• 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_MAX_TIMER_FUN_NUM
56 } SoftBusTimerFunEnum;
57 
58 int32_t RegisterTimeoutCallback(int32_t timerFunId, TimerFunCallback callback);
59 
60 int32_t SoftBusTimerInit(void);
61 
62 void SoftBusTimerDeInit(void);
63 SoftBusList *CreateSoftBusList(void);
64 
65 void DestroySoftBusList(SoftBusList *list);
66 
67 int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, const unsigned char *inBuf, uint32_t inLen);
68 
69 int32_t ConvertBtMacToStrNoColon(char *strMac, uint32_t strMacLen, const uint8_t *binMac,
70     uint32_t binMacLen);
71 
72 int32_t ConvertHexStringToBytes(unsigned char *outBuf, uint32_t outBufLen, const char *inBuf, uint32_t inLen);
73 
74 int32_t ConvertBytesToUpperCaseHexString(char *outBuf, uint32_t outBufLen,
75     const unsigned char *inBuf, uint32_t inLen);
76 
77 int32_t GenerateRandomStr(char *str, uint32_t size);
78 
79 bool IsValidString(const char *input, uint32_t maxLen);
80 
81 int32_t ConvertBtMacToBinary(const char *strMac, uint32_t strMacLen, uint8_t *binMac, uint32_t binMacLen);
82 
83 int32_t ConvertBtMacToStr(char *strMac, uint32_t strMacLen, const uint8_t *binMac, uint32_t binMacLen);
84 
85 int32_t StrCmpIgnoreCase(const char *str1, const char *str2);
86 
87 int32_t StringToUpperCase(const char *str, char *buf, int32_t size);
88 
89 int32_t StringToLowerCase(const char *str, char *buf, int32_t size);
90 
91 void SetSignalingMsgSwitchOn(void);
92 void SetSignalingMsgSwitchOff(void);
93 bool GetSignalingMsgSwitch(void);
94 
95 /**
96  * @brief Intercept signaling messages of specified length and print.
97  * @param[in] distinguish Distinguish the sending and receiving of ble, COAP and P2P signaling messages.
98  * @param[in] data Signaling message.
99  * @param[in] dataLen Length of the signaling message.
100  * @param[in] module softbus log module.
101  */
102 void SignalingMsgPrint(const char *distinguish, unsigned char *data, unsigned char dataLen, uint32_t module);
103 
104 void DataMasking(const char *data, uint32_t length, char delimiter, char *container);
105 int32_t GenerateStrHashAndConvertToHexString(const unsigned char *str, uint32_t len, unsigned char *hashStr,
106     uint32_t hashStrLen);
107 #ifdef __cplusplus
108 #if __cplusplus
109 }
110 #endif /* __cplusplus */
111 #endif /* __cplusplus */
112 
113 #endif /* SOFTBUS_UTILS_H */