Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more
coap_security_handler.h
00001 /* 00002 * Copyright (c) 2015-2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #ifndef __COAP_SECURITY_HANDLER_H__ 00018 #define __COAP_SECURITY_HANDLER_H__ 00019 00020 #include "ns_types.h" 00021 00022 #ifdef NS_USE_EXTERNAL_MBED_TLS 00023 #include "mbedtls/ssl.h" 00024 #ifdef MBEDTLS_SSL_TLS_C 00025 #define COAP_SECURITY_AVAILABLE 00026 #endif 00027 #endif 00028 00029 #define COOKIE_SIMPLE_LEN 8 00030 typedef struct simple_cookie { 00031 unsigned char value[COOKIE_SIMPLE_LEN]; 00032 size_t len; 00033 } simple_cookie_t; 00034 00035 #define KEY_BLOCK_LEN 40 00036 typedef struct key_block { 00037 unsigned char value[KEY_BLOCK_LEN]; 00038 } key_block_t; 00039 00040 typedef int send_cb(int8_t socket_id, void *handle, const void *buf, size_t); 00041 typedef int receive_cb(int8_t socket_id, unsigned char *, size_t); 00042 typedef void start_timer_cb(int8_t timer_id, uint32_t min, uint32_t fin); 00043 typedef int timer_status_cb(int8_t timer_id); 00044 00045 #define DTLS_HANDSHAKE_TIMEOUT_MIN 25000 00046 #define DTLS_HANDSHAKE_TIMEOUT_MAX 201000 00047 00048 typedef enum { 00049 DTLS = 0, 00050 TLS = 1 00051 }SecureSocketMode; 00052 00053 typedef enum { 00054 CERTIFICATE, 00055 PSK, 00056 ECJPAKE 00057 }SecureConnectionMode; 00058 00059 typedef struct { 00060 SecureConnectionMode mode; 00061 /* Certificate pointers, not owned */ 00062 const unsigned char *_cert; 00063 uint16_t _cert_len; 00064 const unsigned char *_priv_key; 00065 uint8_t _priv_key_len; 00066 /* Secure key pointer, owned */ 00067 unsigned char *_key; 00068 uint8_t _key_len; 00069 } coap_security_keys_t; 00070 00071 typedef struct coap_security_s coap_security_t; 00072 00073 #ifdef COAP_SECURITY_AVAILABLE 00074 00075 coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *handle, 00076 SecureConnectionMode mode, 00077 send_cb *send_cb, 00078 receive_cb *receive_cb, 00079 start_timer_cb *start_timer_cb, 00080 timer_status_cb *timer_status_cb); 00081 00082 void coap_security_destroy(coap_security_t *sec); 00083 00084 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); 00085 00086 int coap_security_handler_continue_connecting(coap_security_t *sec); 00087 00088 int coap_security_handler_send_message(coap_security_t *sec, unsigned char *message, size_t len); 00089 00090 int coap_security_send_close_alert(coap_security_t *sec); 00091 00092 int coap_security_handler_read(coap_security_t *sec, unsigned char* buffer, size_t len); 00093 00094 bool coap_security_handler_is_started(const coap_security_t *sec); 00095 00096 const void *coap_security_handler_keyblock(const coap_security_t *sec); 00097 00098 #else 00099 00100 NS_DUMMY_DEFINITIONS_OK 00101 00102 /* Dummy definitions, including needed error codes */ 00103 #ifndef MBEDTLS_ERR_SSL_TIMEOUT 00104 #define MBEDTLS_ERR_SSL_TIMEOUT (-1) 00105 #endif 00106 00107 #ifndef MBEDTLS_ERR_SSL_WANT_READ 00108 #define MBEDTLS_ERR_SSL_WANT_READ (-2) 00109 #endif 00110 00111 #ifndef MBEDTLS_ERR_SSL_WANT_WRITE 00112 #define MBEDTLS_ERR_SSL_WANT_WRITE (-3) 00113 #endif 00114 00115 #ifndef MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE 00116 #define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE (-4) 00117 #endif 00118 00119 #define coap_security_create(socket_id, timer_id, handle, \ 00120 mode, send_cb, receive_cb, start_timer_cb, timer_status_cb) ((coap_security_t *) 0) 00121 #define coap_security_destroy(sec) ((void) 0) 00122 #define coap_security_handler_connect_non_blocking(sec, is_server, sock_mode, keys, timeout_min, timeout_max) (-1) 00123 #define coap_security_handler_continue_connecting(sec) (-1) 00124 #define coap_security_handler_send_message(sec, message, len) (-1) 00125 #define coap_security_send_close_alert(sec) (-1) 00126 #define coap_security_handler_read(sec, buffer, len) (-1) 00127 #define coap_security_handler_is_started(sec) false 00128 #define coap_security_handler_keyblock(sec) ((void *) 0) 00129 00130 #endif /* COAP_SECURITY_AVAILABLE */ 00131 00132 #endif
Generated on Tue Jul 12 2022 13:02:49 by
