mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-05 20:02:19 +03:00
netif: Create netif layer, initially provide datagram read/write
Add in skeleton coap_netif.c coap_netif_internal.h files, populated with coap_netif_dgrm_read(), coap_netif_dgrm_read_ep(), and coap_netif_dgrm_write() functions that are called by the CoAP and (D)TLS code which in turn call the appropriate coap_socket_*() functions. The coap_dtls_send() function parameters are aligned with coap_netif_dgrm_write().
This commit is contained in:
1 parent
62c57e4842
commit
f933c6e604
30 files changed
+362
-95
No files matched your search
@@ -192,9 +192,9 @@ void coap_dtls_session_update_mtu(coap_session_t *coap_session);
|
||||
* @return @c 0 if this would be blocking, @c -1 if there is an error or the
|
||||
* number of cleartext bytes sent.
|
||||
*/
|
||||
int coap_dtls_send(coap_session_t *coap_session,
|
||||
const uint8_t *data,
|
||||
size_t data_len);
|
||||
ssize_t coap_dtls_send(coap_session_t *coap_session,
|
||||
const uint8_t *data,
|
||||
size_t data_len);
|
||||
|
||||
/**
|
||||
* Check if timeout is handled per CoAP session or per CoAP context.
|
||||
|
||||
@@ -46,6 +46,10 @@
|
||||
#endif /* ! PRIu32 */
|
||||
#endif /* ! HAVE_INTTYPES_H */
|
||||
|
||||
#if defined(HAVE_ERRNO_H)
|
||||
# include <errno.h>
|
||||
#endif
|
||||
|
||||
/* By default without either configured, these need to be set */
|
||||
#ifndef COAP_SERVER_SUPPORT
|
||||
#ifndef COAP_CLIENT_SUPPORT
|
||||
@@ -90,6 +94,7 @@ typedef struct oscore_ctx_t oscore_ctx_t;
|
||||
#include "coap_io_internal.h"
|
||||
#include "coap_mutex_internal.h"
|
||||
#include "coap_net_internal.h"
|
||||
#include "coap_netif_internal.h"
|
||||
#if HAVE_OSCORE
|
||||
#include "coap_oscore_internal.h"
|
||||
#endif /* HAVE_OSCORE */
|
||||
|
||||
@@ -91,9 +91,21 @@ coap_socket_bind_udp(coap_socket_t *sock,
|
||||
|
||||
void coap_socket_close(coap_socket_t *sock);
|
||||
|
||||
/**
|
||||
* Function interface for data transmission. This function returns the number of
|
||||
* bytes that have been transmitted, or a value less than zero on error.
|
||||
*
|
||||
* @param sock Socket to send data with
|
||||
* @param session Addressing information for unconnected sockets, or NULL
|
||||
* @param data The data to send.
|
||||
* @param datalen The actual length of @p data.
|
||||
*
|
||||
* @return The number of bytes written on success, or a value
|
||||
* less than zero on error.
|
||||
*/
|
||||
ssize_t
|
||||
coap_socket_send( coap_socket_t *sock, coap_session_t *session,
|
||||
const uint8_t *data, size_t data_len );
|
||||
coap_socket_send(coap_socket_t *sock, coap_session_t *session,
|
||||
const uint8_t *data, size_t datalen);
|
||||
|
||||
ssize_t
|
||||
coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len);
|
||||
@@ -130,7 +142,8 @@ coap_socket_send_pdu( coap_socket_t *sock, coap_session_t *session,
|
||||
* @return The number of bytes written on success, or a value
|
||||
* less than zero on error.
|
||||
*/
|
||||
ssize_t coap_network_send( coap_socket_t *sock, const coap_session_t *session, const uint8_t *data, size_t datalen );
|
||||
ssize_t coap_network_send(coap_socket_t *sock, const coap_session_t *session,
|
||||
const uint8_t *data, size_t datalen);
|
||||
|
||||
/**
|
||||
* Function interface for reading data. This function returns the number of
|
||||
|
||||
@@ -107,11 +107,6 @@ struct coap_context_t {
|
||||
*/
|
||||
coap_event_handler_t handle_event;
|
||||
|
||||
ssize_t (*network_send)(coap_socket_t *sock, const coap_session_t *session,
|
||||
const uint8_t *data, size_t datalen);
|
||||
|
||||
ssize_t (*network_read)(coap_socket_t *sock, coap_packet_t *packet);
|
||||
|
||||
void *dtls_context;
|
||||
|
||||
#if COAP_SERVER_SUPPORT
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* coap_netif_internal.h -- Netif Transport Layer Support for libcoap
|
||||
*
|
||||
* Copyright (C) 2023 Jon Shallow <supjps-libcoap@jpshallow.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file coap_netif_internal.h
|
||||
* @brief Internal CoAP Netif support
|
||||
*/
|
||||
|
||||
#ifndef COAP_NETIF_INTERNAL_H_
|
||||
#define COAP_NETIF_INTERNAL_H_
|
||||
|
||||
#include "coap_internal.h"
|
||||
|
||||
/**
|
||||
* @ingroup internal_api
|
||||
* @defgroup netif_internal Netif Support
|
||||
* Internal API for Netif Support
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function interface to check whether netif for session is still available.
|
||||
*
|
||||
* @param session Session to check against.
|
||||
*
|
||||
* @return 1 If netif is available, else 0.
|
||||
*/
|
||||
int coap_netif_available(coap_session_t *session);
|
||||
|
||||
/**
|
||||
* Function interface for layer data datagram receiving for endpoints. This
|
||||
* function returns the number of bytes that have been read, or -1 on error.
|
||||
*
|
||||
* @param endpoint Endpoint to receive data on.
|
||||
* @param packet Where to put the received information
|
||||
*
|
||||
* @return >=0 Number of bytes read.
|
||||
* -1 Error of some sort (see errno).
|
||||
* -2 ICMP error response
|
||||
*/
|
||||
ssize_t coap_netif_dgrm_read_ep(coap_endpoint_t *endpoint,
|
||||
coap_packet_t *packet);
|
||||
|
||||
/**
|
||||
* Function interface for layer data datagram receiving for sessions. This
|
||||
* function returns the number of bytes that have been read, or -1 on error.
|
||||
*
|
||||
* @param session Session to receive data on.
|
||||
* @param packet Where to put the received information
|
||||
*
|
||||
* @return >=0 Number of bytes read.
|
||||
* -1 Error of some sort (see errno).
|
||||
* -2 ICMP error response
|
||||
*/
|
||||
ssize_t coap_netif_dgrm_read(coap_session_t *session, coap_packet_t *packet);
|
||||
|
||||
/**
|
||||
* Function interface for netif datagram data transmission. This function
|
||||
* returns the number of bytes that have been transmitted, or a value less
|
||||
* than zero on error.
|
||||
*
|
||||
* @param session Session to send data on.
|
||||
* @param data The data to send.
|
||||
* @param datalen The actual length of @p data.
|
||||
*
|
||||
* @return The number of bytes written on success, or a value
|
||||
* less than zero on error.
|
||||
*/
|
||||
ssize_t coap_netif_dgrm_write(coap_session_t *session, const uint8_t *data,
|
||||
size_t datalen);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_NETIF_INTERNAL_H */
|
||||
@@ -274,21 +274,6 @@ coap_session_t *coap_new_server_session(
|
||||
);
|
||||
#endif /* COAP_SERVER_SUPPORT */
|
||||
|
||||
/**
|
||||
* Function interface for datagram data transmission. This function returns
|
||||
* the number of bytes that have been transmitted, or a value less than zero
|
||||
* on error.
|
||||
*
|
||||
* @param session Session to send data on.
|
||||
* @param data The data to send.
|
||||
* @param datalen The actual length of @p data.
|
||||
*
|
||||
* @return The number of bytes written on success, or a value
|
||||
* less than zero on error.
|
||||
*/
|
||||
ssize_t coap_session_send(coap_session_t *session,
|
||||
const uint8_t *data, size_t datalen);
|
||||
|
||||
/**
|
||||
* Function interface for stream data transmission. This function returns
|
||||
* the number of bytes that have been transmitted, or a value less than zero
|
||||
|
||||
Reference in new issue
Block a user