Import Mbed OS hard-float snapshot

This commit is contained in:
Beslan
2026-06-01 20:15:04 +03:00
commit d3738e2f89
16278 changed files with 10628036 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2015-2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __COAP_CONNECTION_HANDLER_H__
#define __COAP_CONNECTION_HANDLER_H__
#include <inttypes.h>
#include <stddef.h>
#include <stdbool.h>
#include "ns_address.h"
#include "coap_service_api_internal.h"
#include "coap_security_handler.h"
#define MAX_SECURE_SESSION_COUNT 3
#define MAX_ONGOING_HANDSHAKES 2
#define CLOSED_SECURE_SESSION_TIMEOUT 3600 // Seconds
#define ONGOING_HANDSHAKE_TIMEOUT 600 // Seconds
#define OPEN_SECURE_SESSION_TIMEOUT 18000 // Seconds
#define SECURE_SESSION_CLEAN_INTERVAL 60 // Seconds
struct internal_socket_s;
typedef int send_to_socket_cb(int8_t socket_id, const uint8_t address[static 16], uint16_t port, const void *, int);
typedef int receive_from_socket_cb(int8_t socket_id, int8_t recv_if_id, uint8_t src_address[static 16], uint16_t port, const uint8_t dst_address[static 16], unsigned char *, int);
typedef int get_pw_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, coap_security_keys_t *security_ptr);
typedef void security_done_cb(int8_t socket_id, uint8_t address[static 16], uint16_t port, uint8_t keyblock[static 40]);
typedef void cch_func_cb(void);
typedef struct coap_conn_handler_s {
struct internal_socket_s *socket;
coap_security_keys_t *security_keys;
receive_from_socket_cb *_recv_cb;
send_to_socket_cb *_send_cb;
get_pw_cb *_get_password_cb;
security_done_cb *_security_done_cb;
int8_t socket_interface_selection;
bool registered_to_multicast;
} coap_conn_handler_t;
coap_conn_handler_t *connection_handler_create(receive_from_socket_cb *recv_from_cb,
send_to_socket_cb *send_to_cb,
get_pw_cb *pw_cb,
security_done_cb *done_cb);
void connection_handler_destroy(coap_conn_handler_t *handler, bool multicast_group_leave);
void connection_handler_close_secure_connection(coap_conn_handler_t *handler, uint8_t destination_addr_ptr[static 16], uint16_t port);
int coap_connection_handler_open_connection(coap_conn_handler_t *handler, uint16_t listen_port, bool use_ephemeral_port, bool is_secure, bool real_socket, bool bypassSec);
//If returns -2, it means security was started and data was not send
/*
* \return > 0 in OK
* \return 0 Session started, data not send
* \return -1 failure
*/
int coap_connection_handler_send_data(coap_conn_handler_t *handler, const ns_address_t *dest_addr, const uint8_t src_address[static 16], uint8_t *data_ptr, uint16_t data_len, bool bypass_link_sec);
int coap_connection_handler_virtual_recv(coap_conn_handler_t *handler, uint8_t address[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len);
bool coap_connection_handler_socket_belongs_to(coap_conn_handler_t *handler, int8_t socket_id);
int8_t coap_connection_handler_set_timeout(coap_conn_handler_t *handler, uint32_t min, uint32_t max);
int8_t coap_connection_handler_handshake_limits_set(uint8_t handshakes_limit, uint8_t connections_limit);
void coap_connection_handler_exec(uint32_t time);
coap_conn_handler_t *coap_connection_handler_find_by_socket_port(uint16_t listen_port);
int coap_connection_handler_msg_prevalidate_callback_set(coap_conn_handler_t *handler, cch_func_cb *function_callback);
cch_func_cb *coap_connection_handler_msg_prevalidate_callback_get(coap_conn_handler_t *handler, uint16_t *listen_socket_port);
#endif

View File

@@ -0,0 +1,122 @@
/*
* Copyright (c) 2015-2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __COAP_MESSAGE_HANDLER_H__
#define __COAP_MESSAGE_HANDLER_H__
#include <inttypes.h>
#include "mbed-coap/sn_coap_header.h"
#include "ns_list.h"
#define TRANSACTION_LIFETIME 180
/* Default value for CoAP duplicate message buffer (0 = disabled) */
#define DUPLICATE_MESSAGE_BUFFER_SIZE 0
/* Default value for CoAP blockwise data size (0 = disabled) */
#define DEFAULT_BLOCKWISE_DATA_SIZE 0
/* Default values for CoAP resendings */
#define COAP_RESENDING_COUNT 3
#define COAP_RESENDING_INTERVAL 10
/**
* \brief Service message response receive callback.
*
* Function that handles CoAP service message receiving and parsing
*
* \param msg_id Id number of the current message.
* \param response_ptr Pointer to CoAP header structure.
*
* \return 0 for success / -1 for failure
*/
typedef int coap_message_handler_response_recv(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *response_ptr);
typedef struct coap_msg_handler_s {
void *(*sn_coap_service_malloc)(uint16_t);
void (*sn_coap_service_free)(void *);
uint8_t (*sn_coap_tx_callback)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *);
struct coap_s *coap;
} coap_msg_handler_t;
typedef struct coap_transaction {
uint8_t remote_address[16];
uint8_t local_address[16];
uint8_t token[8];
uint32_t valid_until;
uint8_t *data_ptr;
coap_message_handler_response_recv *resp_cb;
uint16_t remote_port;
uint16_t msg_id;
uint16_t data_len;
int8_t service_id;
uint8_t options;
uint8_t token_len;
sn_coap_msg_type_e req_msg_type;
bool client_request: 1;
ns_list_link_t link;
} coap_transaction_t;
/**
* \brief Service message processing callback.
*
* Function that processes CoAP service message
*
* \param socket_id Socket that receives the message.
* \param recv_if_id Interface where message is received.
* \param coap_message Actual CoAP message.
* \param transaction_ptr Message transaction.
* \param local_addr Address where message is received.
*
* \return 0 for success / -1 for failure
*/
typedef int16_t coap_msg_process_cb(int8_t socket_id, int8_t recv_if_id, sn_coap_hdr_s *coap_message, coap_transaction_t *transaction_ptr, const uint8_t *local_addr);
extern coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *),
uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *));
extern int8_t coap_message_handler_destroy(coap_msg_handler_t *handle);
extern coap_transaction_t *coap_message_handler_transaction_valid(coap_transaction_t *tr_ptr);
extern coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port);
extern int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, int8_t recv_if_id, const uint8_t source_addr_ptr[static 16], uint16_t port,
const uint8_t dst_addr_ptr[static 16], uint8_t *data_ptr, uint16_t data_len, coap_msg_process_cb *msg_process_callback);
extern uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16],
uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri, sn_coap_content_format_e cont_type,
const uint8_t *payload_ptr, uint16_t payload_len, coap_message_handler_response_recv *request_response_cb);
extern int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code,
sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len);
extern int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t service_id, uint16_t msg_id);
extern int8_t coap_message_handler_request_delete_by_service_id(coap_msg_handler_t *handle, int8_t service_id);
extern int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time);
extern void transaction_delete(coap_transaction_t *this);
extern void transactions_delete_all(uint8_t *address_ptr, uint16_t port);
extern int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code,
sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len);
#endif

View File

@@ -0,0 +1,139 @@
/*
* Copyright (c) 2015-2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __COAP_SECURITY_HANDLER_H__
#define __COAP_SECURITY_HANDLER_H__
#include "ns_types.h"
#ifdef NS_USE_EXTERNAL_MBED_TLS
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#if defined(MBEDTLS_SSL_TLS_C)
#include "mbedtls/ssl.h"
#define COAP_SECURITY_AVAILABLE
#endif
#endif /* NS_USE_EXTERNAL_MBED_TLS */
#define COOKIE_SIMPLE_LEN 8
typedef struct simple_cookie {
unsigned char value[COOKIE_SIMPLE_LEN];
size_t len;
} simple_cookie_t;
#define KEY_BLOCK_LEN 40
typedef struct key_block {
unsigned char value[KEY_BLOCK_LEN];
} key_block_t;
typedef int send_cb(int8_t socket_id, void *handle, const void *buf, size_t);
typedef int receive_cb(int8_t socket_id, unsigned char *, size_t);
typedef void start_timer_cb(int8_t timer_id, uint32_t min, uint32_t fin);
typedef int timer_status_cb(int8_t timer_id);
#define DTLS_HANDSHAKE_TIMEOUT_MIN 25000
#define DTLS_HANDSHAKE_TIMEOUT_MAX 201000
typedef enum {
DTLS = 0,
TLS = 1
} SecureSocketMode;
typedef enum {
CERTIFICATE,
PSK,
ECJPAKE
} SecureConnectionMode;
typedef struct {
SecureConnectionMode mode;
/* Certificate pointers, not owned */
const unsigned char *_cert;
uint16_t _cert_len;
const unsigned char *_priv_key;
uint8_t _priv_key_len;
/* Secure key pointer, owned */
unsigned char *_key;
uint8_t _key_len;
} coap_security_keys_t;
typedef struct coap_security_s coap_security_t;
#ifdef COAP_SECURITY_AVAILABLE
coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *handle,
SecureConnectionMode mode,
send_cb *send_cb,
receive_cb *receive_cb,
start_timer_cb *start_timer_cb,
timer_status_cb *timer_status_cb);
void coap_security_destroy(coap_security_t *sec);
int coap_security_handler_connect_non_blocking(coap_security_t *sec, bool is_server, SecureSocketMode sock_mode, coap_security_keys_t keys, uint32_t timeout_min, uint32_t timeout_max);
int coap_security_handler_continue_connecting(coap_security_t *sec);
int coap_security_handler_send_message(coap_security_t *sec, unsigned char *message, size_t len);
int coap_security_send_close_alert(coap_security_t *sec);
int coap_security_handler_read(coap_security_t *sec, unsigned char *buffer, size_t len);
bool coap_security_handler_is_started(const coap_security_t *sec);
const void *coap_security_handler_keyblock(const coap_security_t *sec);
#else
NS_DUMMY_DEFINITIONS_OK
/* Dummy definitions, including needed error codes */
#ifndef MBEDTLS_ERR_SSL_TIMEOUT
#define MBEDTLS_ERR_SSL_TIMEOUT (-1)
#endif
#ifndef MBEDTLS_ERR_SSL_WANT_READ
#define MBEDTLS_ERR_SSL_WANT_READ (-2)
#endif
#ifndef MBEDTLS_ERR_SSL_WANT_WRITE
#define MBEDTLS_ERR_SSL_WANT_WRITE (-3)
#endif
#ifndef MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE
#define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE (-4)
#endif
#define coap_security_create(socket_id, timer_id, handle, \
mode, send_cb, receive_cb, start_timer_cb, timer_status_cb) ((coap_security_t *) 0)
#define coap_security_destroy(sec) ((void) 0)
#define coap_security_handler_connect_non_blocking(sec, is_server, sock_mode, keys, timeout_min, timeout_max) (-1)
#define coap_security_handler_continue_connecting(sec) (-1)
#define coap_security_handler_send_message(sec, message, len) (-1)
#define coap_security_send_close_alert(sec) (-1)
#define coap_security_handler_read(sec, buffer, len) (-1)
#define coap_security_handler_is_started(sec) false
#define coap_security_handler_keyblock(sec) ((void *) 0)
#endif /* COAP_SECURITY_AVAILABLE */
#endif

View File

@@ -0,0 +1,30 @@
/*
* Copyright (c) 2016, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __COAP_SERVICE_API_INTERNAL_H__
#define __COAP_SERVICE_API_INTERNAL_H__
#include "coap_message_handler.h"
extern coap_msg_handler_t *coap_service_handle;
uint32_t coap_service_get_internal_timer_ticks(void);
uint16_t coap_service_id_find_by_socket(int8_t socket_id);
#endif