1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SOFTBUS_UTILS_H 17 #define SOFTBUS_UTILS_H 18 19 #include "softbus_def.h" 20 21 #ifdef __cplusplus 22 #if __cplusplus 23 extern "C" { 24 #endif 25 #endif 26 27 #define HEXIFY_UNIT_LEN 2 28 #define UN_HEXIFY_LEN(len) ((len) / HEXIFY_UNIT_LEN) 29 #define HEXIFY_LEN(len) ((len) * HEXIFY_UNIT_LEN + 1) 30 #define HEX_MAX_NUM 16 31 #define DEC_MAX_NUM 10 32 #define HEX_MAX_BIT_NUM 4 33 #define MAX_QUERY_LEN 64 34 35 #define TIMER_TIMEOUT 1000 // 1s 36 37 #define MAC_DELIMITER ':' 38 #define IP_DELIMITER '.' 39 #define ID_DELIMITER ' ' 40 41 typedef void (*TimerFunCallback)(void); 42 43 typedef enum { 44 SOFTBUS_CONN_TIMER_FUN, 45 SOFTBUS_AUTHEN_TIMER_FUN, 46 SOFTBUS_SESSION_TIMER_FUN, 47 SOFTBUS_PROXYCHANNEL_TIMER_FUN, 48 SOFTBUS_PROXYSLICE_TIMER_FUN, 49 SOFTBUS_TCP_DIRECTCHANNEL_TIMER_FUN, 50 SOFTBUS_UDP_CHANNEL_TIMER_FUN, 51 SOFTBUS_TIME_SYNC_TIMER_FUN, 52 SOFTBUS_PROXY_SENDFILE_TIMER_FUN, 53 SOFTBUS_MAX_TIMER_FUN_NUM 54 } SoftBusTimerFunEnum; 55 56 int32_t RegisterTimeoutCallback(int32_t timerFunId, TimerFunCallback callback); 57 58 int32_t SoftBusTimerInit(void); 59 60 void SoftBusTimerDeInit(void); 61 SoftBusList *CreateSoftBusList(void); 62 63 void DestroySoftBusList(SoftBusList *list); 64 65 int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, const unsigned char *inBuf, uint32_t inLen); 66 67 int32_t ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen, const char *inBuf, uint32_t inLen); 68 69 int32_t GenerateRandomStr(char *str, uint32_t size); 70 71 bool IsValidString(const char *input, uint32_t maxLen); 72 73 int32_t ConvertBtMacToBinary(const char *strMac, uint32_t strMacLen, uint8_t *binMac, uint32_t binMacLen); 74 75 int32_t ConvertBtMacToStr(char *strMac, uint32_t strMacLen, const uint8_t *binMac, uint32_t binMacLen); 76 77 int32_t StrCmpIgnoreCase(const char *str1, const char *str2); 78 79 void SetSignalingMsgSwitchOn(void); 80 void SetSignalingMsgSwitchOff(void); 81 bool GetSignalingMsgSwitch(void); 82 83 /** 84 * @brief Intercept signaling messages of specified length and print. 85 * @param[in] distinguish Distinguish the sending and receiving of ble, COAP and P2P signaling messages. 86 * @param[in] data Signaling message. 87 * @param[in] dataLen Length of the signaling message. 88 * @param[in] module softbus log module. 89 */ 90 void SignalingMsgPrint(const char *distinguish, unsigned char *data, unsigned char dataLen, uint32_t module); 91 92 void DataMasking(const char *data, uint32_t length, char delimiter, char *container); 93 int32_t GenerateStrHashAndConvertToHexString(const unsigned char *str, uint32_t len, unsigned char *hashStr, 94 uint32_t hashStrLen); 95 #ifdef __cplusplus 96 #if __cplusplus 97 } 98 #endif /* __cplusplus */ 99 #endif /* __cplusplus */ 100 101 #endif /* SOFTBUS_UTILS_H */