Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers eap_tls_sec_prot_lib.h Source File

eap_tls_sec_prot_lib.h

00001 /*
00002  * Copyright (c) 2019, 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 
00018 #ifndef EAP_TLS_SEC_PROT_LIB_H_
00019 #define EAP_TLS_SEC_PROT_LIB_H_
00020 
00021 /*
00022  * EAP-TLS security protocol library
00023  *
00024  */
00025 
00026 typedef enum {
00027     EAP_TLS_EXCHANGE_NONE = 0,
00028     EAP_TLS_EXCHANGE_START,
00029     EAP_TLS_EXCHANGE_ONGOING
00030 } eap_tls_sec_prot_tls_exchange_e;
00031 
00032 typedef enum {
00033     EAP_TLS_MSG_IDENTITY = 0,
00034     EAP_TLS_MSG_START,
00035     EAP_TLS_MSG_CONTINUE,
00036     EAP_TLS_MSG_SEND_DONE,
00037     EAP_TLS_MSG_MORE_FRAG,
00038     EAP_TLS_MSG_RECEIVE_DONE,
00039     EAP_TLS_MSG_DECODE_ERROR,
00040     EAP_TLS_MSG_FAIL,
00041 } eap_tls_sec_prot_msg_e;
00042 
00043 typedef enum {
00044     EAP_TLS_RESULT_NONE = 0,
00045     EAP_TLS_RESULT_ERROR,
00046     EAP_TLS_RESULT_HANDSHAKE_OVER,
00047     EAP_TLS_RESULT_HANDSHAKE_FAILED,
00048     EAP_TLS_RESULT_HANDSHAKE_FATAL_ERROR,
00049 } eap_tls_sec_prot_result_e;
00050 
00051 typedef struct {
00052     uint8_t                       *data;          /**< Data buffer */
00053     uint16_t                      total_len;      /**< Total length of the data buffer */
00054     uint16_t                      handled_len;    /**< Handled length of the data buffer (e.g. acked by other end) */
00055 } tls_data_t;
00056 
00057 #define TLS_FRAGMENT_LEN          1100   //EAP-TLS fragment length
00058 #define TLS_HEAD_LEN              5      //EAP-TLS flags and EAP-TLS length
00059 
00060 extern const uint8_t eap_msg_trace[4][10];
00061 
00062 /**
00063  * eap_tls_sec_prot_lib_message_allocate allocate message buffer
00064  *
00065  * \param data data buffer (length of the allocated data is header length + data length)
00066  * \param head_len header length
00067  * \param len data len
00068  *
00069  * \return < 0 failure
00070  * \return >= 0 success
00071  *
00072  */
00073 int8_t eap_tls_sec_prot_lib_message_allocate(tls_data_t *data, uint8_t head_len, uint16_t len);
00074 
00075 /**
00076  * eap_tls_sec_prot_lib_message_realloc allocates larger message buffer and copies existing data to it
00077  *
00078  * \param data data buffer which length is increased
00079  * \param head_len header length
00080  * \param new_len new length for the buffer
00081  *
00082  * \return < 0 failure
00083  * \return >= 0 success
00084  *
00085  */
00086 int8_t eap_tls_sec_prot_lib_message_realloc(tls_data_t *data, uint8_t head_len, uint16_t new_len);
00087 
00088 /**
00089  * eap_tls_sec_prot_lib_message_free free message buffer
00090  *
00091  * \param data data buffer
00092  *
00093  */
00094 void eap_tls_sec_prot_lib_message_free(tls_data_t *data);
00095 
00096 /**
00097  * eap_tls_sec_prot_lib_message_init init message buffer
00098  *
00099  * \param data data buffer
00100  *
00101  */
00102 void eap_tls_sec_prot_lib_message_init(tls_data_t *data);
00103 
00104 /**
00105  * eap_tls_sec_prot_lib_message_handle decode incoming message EAP-TLS part (from EAP-TLS flags field onward)
00106  *
00107  * \param data message data (points to EAP-TLS flags)
00108  * \param length of the message remaining
00109  * \param new_seq_id EAP sequence identifier is new (message is not re-send by other end)
00110  * \param tls_send EAP-TLS send buffer, when sending data, updates the data (fragments) that has been acknowledged by other end
00111  * \param tls_recv EAP_TLS receive buffer, if receiving data, updates the received data (fragments)
00112  *
00113  * \return < 0 failure
00114  * \return >= 0 success
00115  *
00116  */
00117 int8_t eap_tls_sec_prot_lib_message_handle(uint8_t *data, uint16_t length, bool new_seq_id, tls_data_t *tls_send, tls_data_t *tls_recv);
00118 
00119 /**
00120  * eap_tls_sec_prot_lib_message_build builds EAP-TLS message
00121  *
00122  * \param eap_code EAP code
00123  * \param eap_type EAP type
00124  * \param flags EAP-TLS flags
00125  * \param eap_id_seq EAP sequence identifier
00126  * \param header_size header size
00127  * \param tls_send EAP-TLS send buffer, sends either a fragment or full message
00128  * \param length of the message to be send
00129  *
00130  * \return pointer to message to be sent or NULL in case of failure
00131  *
00132  */
00133 uint8_t *eap_tls_sec_prot_lib_message_build(uint8_t eap_code, uint8_t eap_type, uint8_t *flags, uint8_t eap_id_seq, uint8_t header_size, tls_data_t *tls_send, uint16_t *length);
00134 
00135 #endif /* EAP_TLS_SEC_PROT_H_ */