• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SMS_COMMON_UTILS_H
18 #define SMS_COMMON_UTILS_H
19 
20 #include <ctime>
21 
22 #include "sms_pdu_code_type.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 class SmsCommonUtils {
27 public:
28     static int Pack7bitChar(const unsigned char *userData, int dataLen, int fillBits, unsigned char *packData);
29     static int Unpack7bitChar(const unsigned char *tpdu, unsigned char dataLen, int fillBits,
30         unsigned char *unpackData, unsigned int unpackDataLen);
31     static int DigitToBcd(const char *digit, int digitLen, unsigned char *bcd);
32     static int BcdToDigit(const unsigned char *bcd, int bcdLen, char *digit);
33     static int BcdToDigitCdma(const unsigned char *bcd, int bcdLen, char *digit);
34     static int ConvertDigitToDTMF(const char *digit, int digitLen, int startBit, unsigned char *dtmf);
35     static long ConvertTime(const struct SmsTimeAbs &timeAbs);
36 
37 private:
38     static char BcdToChar(const unsigned char c);
39     static unsigned char DigitToDtmfChar(const unsigned char c);
40     static void DisplayTime(const time_t &rawtime);
41 
42     static constexpr uint8_t SMS_HEX_BYTE_STEP = 2;
43     static constexpr uint8_t SMS_ENCODE_GSM_BIT = 7;
44     static constexpr uint8_t SMS_BYTE_BIT = 8;
45     static constexpr uint16_t SEC_PER_HOUR = 3600;
46 
47     static constexpr uint8_t BASE_GSM_YEAR = 100;
48     static constexpr uint16_t BASE_CDMA_YEAR = 1900;
49     static constexpr uint16_t BASE_CDMA_YEAR_V2 = 2000;
50 };
51 } // namespace Telephony
52 } // namespace OHOS
53 #endif // SMS_COMMON_UTILS_H