1 //
2 // Copyright (C) 2020 The Android Open Source Project
3 //
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 #pragma once
17 
18 #include <string>
19 
20 namespace cuttlefish {
21 
22 class PDUParser {
23  public:
24   explicit PDUParser(std::string &pdu);
25   ~PDUParser() = default;
26 
27   bool IsValidPDU();
28   bool IsNeededStatuReport();
29   std::string CreatePDU();
30   std::string CreateRemotePDU(std::string& host_port);
31   std::string CreateStatuReport(int message_reference);
32   std::string GetPhoneNumberFromAddress();
33 
34   static std::string BCDToString(std::string& data);
35 
36  private:
37   bool DecodePDU(std::string& pdu);
38   int Hex2ToByte(const std::string& hex);
39   int HexCharToInt(char c);
40   std::string IntToHexString(int value);
41   std::string GetCurrentTimeStamp();
42 
43   bool is_valid_pdu_;
44 
45   // Ignore SMSC address, default to be "00" when create PDU
46   std::string pdu_type_;
47   std::string message_reference_;
48   std::string originator_address_;
49   std::string protocol_id_;
50   std::string data_code_scheme_;
51   std::string user_data_;
52 };
53 
54 } // namespace cuttlefish
55