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_TPDU_CODEC_H 18 #define GSM_SMS_TPDU_CODEC_H 19 20 #include "gsm_sms_udata_codec.h" 21 22 namespace OHOS { 23 namespace Telephony { 24 enum SmsMTIType { SMS_MTI_DELIVER = 0, SMS_MTI_SUBMIT, SMS_MTI_STATUS_REP }; 25 26 enum DecodeType { 27 DECODE_SUBMIT_TYPE, 28 DECODE_DELIVER_TYPE, 29 DECODE_STATUS_REP_TYPE, 30 }; 31 32 class GsmSmsTpduCodec { 33 public: 34 GsmSmsTpduCodec() = default; 35 virtual ~GsmSmsTpduCodec() = default; 36 static int EncodeTpdu(const struct SmsTpdu *pSmsTpdu, char *pTpdu, int pduLen); 37 static int DecodeTpdu(const unsigned char *pTpdu, int TpduLen, struct SmsTpdu *pSmsTpdu); 38 39 private: 40 static int EncodeSubmit(const struct SmsSubmit *pSubmit, char *pTpdu); 41 static int EncodeDeliver(const struct SmsDeliver *pDeliver, char *pTpdu); 42 static int EncodeDeliverReport(const struct SmsDeliverReport *pDeliverRep, char *pTpdu); 43 static int EncodeStatusReport(const struct SmsStatusReport *pStatusRep, char *pTpdu); 44 static int DecodeSubmit(const unsigned char *pTpdu, int TpduLen, struct SmsSubmit *pSubmit); 45 static int DecodeDeliver(const unsigned char *pTpdu, int TpduLen, struct SmsDeliver *pDeliver); 46 static int DecodeStatusReport(const unsigned char *pTpdu, int TpduLen, struct SmsStatusReport *pStatusRep); 47 static enum SmsPid ParsePid(const unsigned char pid); 48 static int EncodeSubmitTpduType(const struct SmsSubmit &pSubmit, unsigned char *pTpdu); 49 static void DebugTpdu(const unsigned char *pTpdu, int TpduLen, const enum DecodeType type); 50 }; 51 } // namespace Telephony 52 } // namespace OHOS 53 #endif