• 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 GSM_SMS_UDCODEC_H
18 #define GSM_SMS_UDCODEC_H
19 
20 #include "gsm_sms_param_codec.h"
21 
22 namespace OHOS {
23 namespace Telephony {
24 class GsmSmsUDataCodec {
25 public:
26     GsmSmsUDataCodec() = default;
27     virtual ~GsmSmsUDataCodec() = default;
28     static int EncodeUserData(
29         const struct SmsUserData *(&pUserData), SmsCodingScheme CodingScheme, char *(&pEncodeData));
30     static int DecodeUserData(const unsigned char *pTpdu, const int tpduLen, bool bHeaderInd,
31         SmsCodingScheme CodingScheme, struct SmsUserData *pUserData);
32     static int DecodeUserData(const unsigned char *pTpdu, const int tpduLen, bool bHeaderInd,
33         SmsCodingScheme CodingScheme, struct SmsUserData *pUserData, struct SmsTpud *pTPUD);
34 
35     static int EncodeGSMData(const struct SmsUserData *pUserData, char *pEncodeData);
36     static int Encode8bitData(const struct SmsUserData *pUserData, char *pEncodeData);
37     static int EncodeUCS2Data(const struct SmsUserData *pUserData, char *pEncodeData);
38 
39     static int DecodeGSMData(const unsigned char *pTpdu, const int tpduLen, bool bHeaderInd,
40         struct SmsUserData *pUserData, struct SmsTpud *pTPUD);
41     static int Decode8bitData(
42         const unsigned char *pTpdu, bool bHeaderInd, struct SmsUserData *pUserData, struct SmsTpud *pTPUD);
43     static int DecodeUCS2Data(const unsigned char *pTpdu, const int tpduLen, bool bHeaderInd,
44         struct SmsUserData *pUserData, struct SmsTpud *pTPUD);
45     static int EncodeHeader(const struct SmsUDH header, char *pEncodeHeader);
46     static int DecodeHeader(const unsigned char *pTpdu, struct SmsUDH *pHeader);
47     static void ResetUserData(struct SmsUserData &userData);
48 
49 private:
50     static int EncodeHeaderConcat(const struct SmsUDH header, char *pEncodeHeader);
51     static void DebugDecodeHeader(const struct SmsUDH *pHeader);
52     static bool GetHeaderCnt(const unsigned char *pTpdu, struct SmsUserData *pUserData, int &offset, int &udhl, int i);
53 };
54 } // namespace Telephony
55 } // namespace OHOS
56 #endif