1 /*
2 * Copyright (C) 2023 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 #include "gsm_sms_param_codec.h"
17
18 #include "gsm_pdu_hex_value.h"
19 #include "gsm_sms_param_decode.h"
20 #include "gsm_sms_param_encode.h"
21 #include "telephony_log_wrapper.h"
22 #include "text_coder.h"
23
24 namespace OHOS {
25 namespace Telephony {
EncodeAddressPdu(const struct AddressNumber * num,std::string & resultNum)26 bool GsmSmsParamCodec::EncodeAddressPdu(const struct AddressNumber *num, std::string &resultNum)
27 {
28 GsmSmsParamEncode codec;
29 return codec.EncodeAddressPdu(num, resultNum);
30 }
31
EncodeSmscPdu(const char * num,uint8_t * resultNum)32 uint8_t GsmSmsParamCodec::EncodeSmscPdu(const char *num, uint8_t *resultNum)
33 {
34 GsmSmsParamEncode codec;
35 return codec.EncodeSmscPdu(num, resultNum);
36 }
37
EncodeSmscPdu(const struct AddressNumber * num,uint8_t * smscNum,uint8_t smscLen)38 uint8_t GsmSmsParamCodec::EncodeSmscPdu(const struct AddressNumber *num, uint8_t *smscNum, uint8_t smscLen)
39 {
40 GsmSmsParamEncode codec;
41 return codec.EncodeSmscPdu(num, smscNum, smscLen);
42 }
43
EncodeTimePdu(const struct SmsTimeStamp * timeStamp,std::string & resultValue)44 void GsmSmsParamCodec::EncodeTimePdu(const struct SmsTimeStamp *timeStamp, std::string &resultValue)
45 {
46 GsmSmsParamEncode codec;
47 codec.EncodeTimePdu(timeStamp, resultValue);
48 }
49
EncodeDCS(const struct SmsDcs * dcsData,std::string & returnValue)50 void GsmSmsParamCodec::EncodeDCS(const struct SmsDcs *dcsData, std::string &returnValue)
51 {
52 GsmSmsParamEncode codec;
53 codec.EncodeDCS(dcsData, returnValue);
54 }
55
DecodeAddressPdu(SmsReadBuffer & buffer,struct AddressNumber * resultNum)56 bool GsmSmsParamCodec::DecodeAddressPdu(SmsReadBuffer &buffer, struct AddressNumber *resultNum)
57 {
58 GsmSmsParamDecode codec;
59 return codec.DecodeAddressPdu(buffer, resultNum);
60 }
61
DecodeTimePdu(SmsReadBuffer & buffer,struct SmsTimeStamp * timeStamp)62 bool GsmSmsParamCodec::DecodeTimePdu(SmsReadBuffer &buffer, struct SmsTimeStamp *timeStamp)
63 {
64 GsmSmsParamDecode codec;
65 return codec.DecodeTimePdu(buffer, timeStamp);
66 }
67
DecodeDcsPdu(SmsReadBuffer & buffer,struct SmsDcs * smsDcs)68 bool GsmSmsParamCodec::DecodeDcsPdu(SmsReadBuffer &buffer, struct SmsDcs *smsDcs)
69 {
70 GsmSmsParamDecode codec;
71 return codec.DecodeDcsPdu(buffer, smsDcs);
72 }
73
DecodeSmscPdu(uint8_t * pAddress,uint8_t addrLen,enum TypeOfNum ton,std::string & decodeAddr)74 void GsmSmsParamCodec::DecodeSmscPdu(uint8_t *pAddress, uint8_t addrLen, enum TypeOfNum ton, std::string &decodeAddr)
75 {
76 GsmSmsParamDecode codec;
77 codec.DecodeSmscPdu(pAddress, addrLen, ton, decodeAddr);
78 }
79
DecodeSmscPdu(const uint8_t * pTpdu,uint8_t pduLen,struct AddressNumber & address)80 uint8_t GsmSmsParamCodec::DecodeSmscPdu(const uint8_t *pTpdu, uint8_t pduLen, struct AddressNumber &address)
81 {
82 GsmSmsParamDecode codec;
83 return codec.DecodeSmscPdu(pTpdu, pduLen, address);
84 }
85
CheckVoicemail(SmsReadBuffer & buffer,int32_t * setType,int32_t * indType)86 bool GsmSmsParamCodec::CheckVoicemail(SmsReadBuffer &buffer, int32_t *setType, int32_t *indType)
87 {
88 uint8_t oneByte = 0;
89 if (!buffer.ReadByte(oneByte)) {
90 TELEPHONY_LOGE("get data error.");
91 return false;
92 }
93
94 if (oneByte != HEX_VALUE_04) {
95 TELEPHONY_LOGE("data error.");
96 return false;
97 }
98
99 if (!buffer.ReadByte(oneByte)) {
100 TELEPHONY_LOGE("get data error.");
101 return false;
102 }
103 if (oneByte != HEX_VALUE_D0) {
104 TELEPHONY_LOGE("data error.");
105 return false;
106 }
107
108 if (!buffer.PickOneByte(oneByte)) {
109 TELEPHONY_LOGE("get data error.");
110 return false;
111 }
112 uint8_t nextByte = 0;
113 if (!buffer.PickOneByte(nextByte)) {
114 TELEPHONY_LOGE("get data error.");
115 return false;
116 }
117
118 if (oneByte == HEX_VALUE_11 || nextByte == HEX_VALUE_10) {
119 TELEPHONY_LOGI("####### VMI msg ######");
120 if (!buffer.ReadByte(oneByte)) {
121 TELEPHONY_LOGE("get data error.");
122 return false;
123 }
124 *setType = static_cast<int32_t>(oneByte & HEX_VALUE_01); /* 0 : clear, 1 : set */
125 if (!buffer.PickOneByte(oneByte)) {
126 TELEPHONY_LOGE("get data error.");
127 return false;
128 }
129 *indType = static_cast<int32_t>(oneByte & HEX_VALUE_01); /* 0 : indicator 1, 1 : indicator 2 */
130 return true;
131 }
132 return false;
133 }
134 } // namespace Telephony
135 } // namespace OHOS
136