• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define BT_MAC_NO_COLON_LEN 13
37 
38 #define MAC_DELIMITER ':'
39 #define IP_DELIMITER '.'
40 #define ID_DELIMITER ' '
41 
42 typedef void (*TimerFunCallback)(void);
43 
44 typedef enum {
45     SOFTBUS_CONN_TIMER_FUN,
46     SOFTBUS_AUTHEN_TIMER_FUN,
47     SOFTBUS_SESSION_TIMER_FUN,
48     SOFTBUS_PROXYCHANNEL_TIMER_FUN,
49     SOFTBUS_PROXYSLICE_TIMER_FUN,
50     SOFTBUS_TCP_DIRECTCHANNEL_TIMER_FUN,
51     SOFTBUS_UDP_CHANNEL_TIMER_FUN,
52     SOFTBUS_TIME_SYNC_TIMER_FUN,
53     SOFTBUS_PROXY_SENDFILE_TIMER_FUN,
54     SOFTBUS_NIP_NODE_AGING_TIMER_FUN,
55     SOFTBUS_TRNAS_IDLE_TIMEOUT_TIMER_FUN,
56     SOFTBUS_MAX_TIMER_FUN_NUM
57 } SoftBusTimerFunEnum;
58 
59 int32_t RegisterTimeoutCallback(int32_t timerFunId, TimerFunCallback callback);
60 
61 int32_t SoftBusTimerInit(void);
62 
63 void SoftBusTimerDeInit(void);
64 SoftBusList *CreateSoftBusList(void);
65 
66 void DestroySoftBusList(SoftBusList *list);
67 
68 int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, const unsigned char *inBuf, uint32_t inLen);
69 
70 int32_t ConvertBtMacToStrNoColon(char *strMac, uint32_t strMacLen, const uint8_t *binMac,
71     uint32_t binMacLen);
72 
73 int32_t ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen, const char *inBuf, uint32_t inLen);
74 
75 int32_t ConvertBytesToUpperCaseHexString(char *outBuf, uint32_t outBufLen,
76     const unsigned char *inBuf, uint32_t inLen);
77 
78 int32_t GenerateRandomStr(char *str, uint32_t size);
79 
80 bool IsValidString(const char *input, uint32_t maxLen);
81 
82 int32_t ConvertBtMacToBinary(const char *strMac, uint32_t strMacLen, uint8_t *binMac, uint32_t binMacLen);
83 
84 int32_t ConvertBtMacToStr(char *strMac, uint32_t strMacLen, const uint8_t *binMac, uint32_t binMacLen);
85 
86 int32_t ConvertReverseBtMacToStr(char *strMac, uint32_t strMacLen, const uint8_t *binMac, uint32_t binMacLen);
87 
88 int32_t ConvertBtMacToU64(const char *strMac, uint32_t strMacLen, uint64_t *u64Mac);
89 
90 int32_t ConvertU64MacToStr(uint64_t u64Mac, char *strMac, uint32_t strMacLen);
91 
92 int32_t StrCmpIgnoreCase(const char *str1, const char *str2);
93 
94 int32_t StringToUpperCase(const char *str, char *buf, int32_t size);
95 
96 int32_t StringToLowerCase(const char *str, char *buf, int32_t size);
97 
98 void SetSignalingMsgSwitchOn(void);
99 void SetSignalingMsgSwitchOff(void);
100 bool GetSignalingMsgSwitch(void);
101 
102 /**
103  * @brief Intercept signaling messages of specified length and print.
104  * @param[in] distinguish Distinguish the sending and receiving of ble, COAP and P2P signaling messages.
105  * @param[in] data Signaling message.
106  * @param[in] dataLen Length of the signaling message.
107  * @param[in] module softbus log module.
108  */
109 void SignalingMsgPrint(const char *distinguish, unsigned char *data, unsigned char dataLen, uint32_t module);
110 
111 void DataMasking(const char *data, uint32_t length, char delimiter, char *container);
112 int32_t GenerateStrHashAndConvertToHexString(const unsigned char *str, uint32_t len, unsigned char *hashStr,
113     uint32_t hashStrLen);
114 #ifdef __cplusplus
115 #if __cplusplus
116 }
117 #endif /* __cplusplus */
118 #endif /* __cplusplus */
119 
120 #endif /* SOFTBUS_UTILS_H */