1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 /** 17 * @defgroup hitls_crypt_reg 18 * @ingroup hitls 19 * @brief hitls maintenance and debugging 20 */ 21 22 #ifndef HITLS_DEBUG_H 23 #define HITLS_DEBUG_H 24 25 #include <stdint.h> 26 #include "hitls_type.h" 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 #define INDICATE_VALUE_SUCCESS 1u 33 34 #define INDICATE_EVENT_LOOP 0x01 // 0000 0000 0000 0001, Handshake state transition 35 #define INDICATE_EVENT_EXIT 0x02 // 0000 0000 0000 0010, Handshake status exit 36 #define INDICATE_EVENT_READ 0x04 // 0000 0000 0000 0100, Read event 37 #define INDICATE_EVENT_WRITE 0x08 // 0000 0000 0000 1000, Write event 38 #define INDICATE_EVENT_HANDSHAKE_START 0x10 // 0000 0000 0001 0000, Handshake Start 39 #define INDICATE_EVENT_HANDSHAKE_DONE 0x20 // 0000 0000 0010 0000, Handshake completed 40 #define INDICATE_EVENT_STATE_CONNECT 0x1000 // 0001 0000 0000 0000, Local client 41 #define INDICATE_EVENT_STATE_ACCEPT 0x2000 // 0010 0000 0000 0000, Local server 42 #define INDICATE_EVENT_ALERT 0x4000 // 0100 0000 0000 0000, Warning Time 43 44 #define INDICATE_EVENT_READ_ALERT (INDICATE_EVENT_ALERT | INDICATE_EVENT_READ) 45 #define INDICATE_EVENT_WRITE_ALERT (INDICATE_EVENT_ALERT | INDICATE_EVENT_WRITE) 46 #define INDICATE_EVENT_STATE_ACCEPT_LOOP (INDICATE_EVENT_STATE_ACCEPT | INDICATE_EVENT_LOOP) 47 #define INDICATE_EVENT_STATE_ACCEPT_EXIT (INDICATE_EVENT_STATE_ACCEPT | INDICATE_EVENT_EXIT) 48 #define INDICATE_EVENT_STATE_CONNECT_LOOP (INDICATE_EVENT_STATE_CONNECT | INDICATE_EVENT_LOOP) 49 #define INDICATE_EVENT_STATE_CONNECT_EXIT (INDICATE_EVENT_STATE_CONNECT | INDICATE_EVENT_EXIT) 50 51 /** 52 * @ingroup hitls_debug 53 * @brief Information prompt callback prototype 54 * 55 * @attention The message prompt callback function does not return a value 56 * @param ctx [IN] Ctx context 57 * @param eventType [IN] EventType Event type 58 * @param value [IN] Value Function return value or Alert type that matches the event type 59 * @retval No value is returned. 60 */ 61 typedef void (*HITLS_InfoCb)(const HITLS_Ctx *ctx, int32_t eventType, int32_t value); 62 63 /** 64 * @ingroup hitls_debug 65 * @brief Set the callback for prompt information. 66 * 67 * @param ctx [OUT] Ctx context 68 * @param callback [IN] Callback function for prompting information 69 * @retval HITLS_SUCCESS, if successful. 70 * For other error codes, see hitls_error.h. 71 */ 72 int32_t HITLS_SetInfoCb(HITLS_Ctx *ctx, HITLS_InfoCb callback); 73 74 /** 75 * @ingroup hitls_debug 76 * @brief Callback for obtaining information 77 * 78 * @param ctx [IN] Ctx context 79 * @retval Callback function of the current information prompt. 80 * If this parameter is not set, NULL is returned. 81 */ 82 HITLS_InfoCb HITLS_GetInfoCb(const HITLS_Ctx *ctx); 83 84 /** 85 * @ingroup hitls_debug 86 * @brief Set the callback function for prompting information. 87 * 88 * @param config [OUT] Config Context 89 * @param callback [IN] Client callback 90 * @retval HITLS_SUCCESS, if successful. 91 * For details about other error codes, see hitls_error.h. 92 */ 93 int32_t HITLS_CFG_SetInfoCb(HITLS_Config *config, HITLS_InfoCb callback); 94 95 /** 96 * @ingroup hitls_debug 97 * @brief Callback function for obtaining information prompts 98 * 99 * @param config [IN] config Context 100 * @retval Callback function of the current information prompt. 101 * If this parameter is not set, NULL is returned. 102 */ 103 HITLS_InfoCb HITLS_CFG_GetInfoCb(const HITLS_Config *config); 104 105 /** 106 * @ingroup hitls_debug 107 * @brief Callback prototype of a protocol message 108 * 109 * @attention: The callback function for messages in the retention protocol does not return any value. 110 * @param writePoint [IN] writePoint Message direction in the callback ">>>" or "<<<" 111 * @param tlsVersion [IN] tlsVersion TLS version, for example, HITLS_VERSION_TLS12. 112 * @param contentType[IN] contentType Type of the processed message body. 113 * @param msg [IN] msg callback internal message processing instruction data 114 * @param msgLen [IN] msgLen Processing instruction data length 115 * @param ctx [IN] ctx HITLS context 116 * @param arg [IN] arg User data, for example, BIO 117 * @retval No value is returned. 118 */ 119 typedef void (*HITLS_MsgCb) (int32_t writePoint, int32_t tlsVersion, int32_t contentType, const void *msg, 120 uint32_t msgLen, HITLS_Ctx *ctx, void *arg); 121 122 /** 123 * @ingroup hitls_debug 124 * @brief Set the protocol message callback function, cb can be NULL. 125 * 126 * @param ctx [OUT] Ctx context 127 * @param callback [IN] Protocol message callback function 128 * @retval HITLS_SUCCESS, if successful. 129 * For details about other error codes, see hitls_error.h. 130 */ 131 int32_t HITLS_SetMsgCb(HITLS_Ctx *ctx, HITLS_MsgCb callback); 132 133 /** 134 * @ingroup hitls_debug 135 * @brief Set the protocol message callback function, cb can be NULL. 136 * 137 * @param config [OUT] Config Context 138 * @param callback [IN] Protocol message callback 139 * @retval HITLS_SUCCESS, if successful. 140 * For details about other error codes, see hitls_error.h. 141 */ 142 int32_t HITLS_CFG_SetMsgCb(HITLS_Config *config, HITLS_MsgCb callback); 143 144 /** 145 * @ingroup hitls_debug 146 * @brief Set the related parameters arg required by the protocol message callback function. 147 * 148 * @param config [OUT] Config Context. 149 * @param arg [IN] Related parameters arg. 150 * @retval HITLS_SUCCESS, if successful. 151 * For details about other error codes, see hitls_error.h. 152 */ 153 int32_t HITLS_CFG_SetMsgCbArg(HITLS_Config *config, void *arg); 154 155 #ifdef __cplusplus 156 } 157 #endif 158 159 #endif // HITLS_DEBUG_H 160 161