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 typedef void (*TimerFunCallback)(void); 38 39 typedef enum { 40 SOFTBUS_CONN_TIMER_FUN, 41 SOFTBUS_AUTHEN_TIMER_FUN, 42 SOFTBUS_SESSION_TIMER_FUN, 43 SOFTBUS_PROXYCHANNEL_TIMER_FUN, 44 SOFTBUS_PROXYSLICE_TIMER_FUN, 45 SOFTBUS_TCP_DIRECTCHANNEL_TIMER_FUN, 46 SOFTBUS_UDP_CHANNEL_TIMER_FUN, 47 SOFTBUS_TIME_SYNC_TIMER_FUN, 48 SOFTBUS_PROXY_SENDFILE_TIMER_FUN, 49 SOFTBUS_MAX_TIMER_FUN_NUM 50 } SoftBusTimerFunEnum; 51 52 int32_t RegisterTimeoutCallback(int32_t timerFunId, TimerFunCallback callback); 53 54 int32_t SoftBusTimerInit(void); 55 56 void SoftBusTimerDeInit(void); 57 SoftBusList *CreateSoftBusList(void); 58 59 void DestroySoftBusList(SoftBusList *list); 60 61 int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, const unsigned char *inBuf, uint32_t inLen); 62 63 int32_t ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen, const char *inBuf, uint32_t inLen); 64 65 int32_t GenerateRandomStr(char *str, uint32_t size); 66 67 bool IsValidString(const char *input, uint32_t maxLen); 68 69 int32_t ConvertBtMacToBinary(const char *strMac, uint32_t strMacLen, uint8_t *binMac, uint32_t binMacLen); 70 71 int32_t ConvertBtMacToStr(char *strMac, uint32_t strMacLen, const uint8_t *binMac, uint32_t binMacLen); 72 73 int32_t Strnicmp(const char *src1, const char *src2, uint32_t len); 74 75 #ifdef __cplusplus 76 #if __cplusplus 77 } 78 #endif /* __cplusplus */ 79 #endif /* __cplusplus */ 80 81 #endif /* SOFTBUS_UTILS_H */