/[projects]/smsdaemon/SmsPdu.cpp
ViewVC logotype

Diff of /smsdaemon/SmsPdu.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 59 by torben, Wed Jun 11 19:42:24 2008 UTC revision 63 by torben, Thu Jun 12 12:43:29 2008 UTC
# Line 2  Line 2 
2   */   */
3    
4    
5    #include "SmsPdu.h"
6    
7  #include <string>  #include <string>
8  #include <sstream>  #include <sstream>
9    
10    #include <time.h>
11    #include <stdlib.h>
12    
13    #include "common.h"
   
14  #include "util.h"  #include "util.h"
15    
16    
# Line 40  vector<unsigned char> BcdEncode(string i Line 43  vector<unsigned char> BcdEncode(string i
43                  }                  }
44          }          }
45    
46            if ((input.length() % 2) == 1)
47            {
48                    current |= 0xF0;
49                    result.push_back(current);
50            }
51    
52          return result;          return result;
53  }  }
54    
# Line 58  string HexformatVector(vector<unsigned c Line 67  string HexformatVector(vector<unsigned c
67          return os.str();          return os.str();
68  }  }
69    
70    std::string Encode8to7bit(vector<unsigned char> vec)
71    {
72            string result;
73    
74            return result;
75    }
76    
77  vector<unsigned char> Encode7to8bit(std::string str)  vector<unsigned char> Encode7to8bit(std::string str)
78  {  {
79          vector<unsigned char> buf;          vector<unsigned char> buf;
# Line 85  vector<unsigned char> Encode7to8bit(std: Line 101  vector<unsigned char> Encode7to8bit(std:
101          return buf;          return buf;
102  }  }
103    
104  string CreateSmsPdu(string to, string message, int& len)  vector<PduInfo> CreateSmsPdu(string to, string message, bool allowMultipart)
105  {  {
106          message = message.substr(0,160); //truncate to 160          bool multipart = allowMultipart && message.length() > 160;
107    
108            const unsigned char UDHI = multipart ? 0x40 : 0;
109    
110            srand(time(0));
111            unsigned char csms_ref = rand() % 128;
112    
113            int part_count;
114    
115            const int PDU_LEN = 153;
116    
117            if (multipart)
118            {
119                    part_count = message.length() / PDU_LEN;
120                    if (message.length() % PDU_LEN)
121                            part_count++;
122            }
123            else
124            {
125                    part_count = 1;
126            }
127    
128          vector<unsigned char> pdu;          vector<PduInfo> result;
129            for (int partnr = 0; partnr < part_count; ++partnr)
130            {
131                    vector<unsigned char> pdu;
132    
133          pdu.push_back(0x00); // use SMSC from phone                  pdu.push_back(0x00); // use SMSC from phone
134          pdu.push_back(0x01); // first octet -- no timeout                  pdu.push_back( 0x01|UDHI ); // first octet -- no timeout
135          pdu.push_back(0x00); // TP-MR message reference                  pdu.push_back(0x00); // TP-MR message reference
136          pdu.push_back(to.length() ); //length of phone nr                  pdu.push_back(to.length() ); //length of phone nr
137          pdu.push_back(0x91); // type of address (international nr  + ISDN/telephone range) - else try 0x81                  pdu.push_back(0x91); // type of address (international nr  + ISDN/telephone range) - else try 0x81
138    
139          vector<unsigned char> phone = BcdEncode(to);                  vector<unsigned char> phone = BcdEncode(to);
140          pdu.insert( pdu.end(), phone.begin(), phone.end());                  pdu.insert( pdu.end(), phone.begin(), phone.end());
141    
142          pdu.push_back(0x00); // Protocol identifier                  pdu.push_back(0x00); // Protocol identifier
143          pdu.push_back(0x00); // Data coding scheme                  pdu.push_back(0x00); // Data coding scheme
         pdu.push_back( message.length() ); //UserDataLength  
144    
145          vector<unsigned char> userData = Encode7to8bit(message);                  string message_part;
146          pdu.insert( pdu.end(), userData.begin(), userData.end());                  if (multipart)
147                    {
148                            message_part = message.substr(0, PDU_LEN);
149                            message.erase(0, PDU_LEN);
150    
151          len = pdu.size()-1;                          pdu.push_back( message_part.length()+ 7 );  //UserDataLength
152          return HexformatVector(pdu);                          pdu.push_back( 0x06 ); // UDH Len
153                            pdu.push_back( 0x00 ); // UDH Element Identifier
154                            pdu.push_back( 0x03 ); // UDH element length
155                            pdu.push_back( csms_ref ); // csms_ref reference
156                            pdu.push_back( part_count );
157                            pdu.push_back( partnr+1 );
158                            pdu.push_back( 0x00);
159    
160                    }
161                    else
162                    {
163                            if (message.length() > 160)
164                            {
165                                    message_part = message.substr(0,160); //truncate to 160
166                                    Common::instance()->logMessage("Truncated message");
167                            }
168                            else
169                            {
170                                    message_part = message;
171                            }
172    
173                            pdu.push_back( message_part.length() ); //UserDataLength
174                    }
175    
176                    vector<unsigned char> userData = Encode7to8bit(message_part);
177    
178                    pdu.insert( pdu.end(), userData.begin(), userData.end());
179    
180                    PduInfo info;
181                    info.len = pdu.size()-1;
182                    info.pdu = HexformatVector(pdu);
183                    result.push_back(info);
184    
185            }
186            return result;
187  }  }
188    
189  }  }

Legend:
Removed from v.59  
changed lines
  Added in v.63

  ViewVC Help
Powered by ViewVC 1.1.20