/[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 60 by torben, Wed Jun 11 21:18:04 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    
14  #include "util.h"  #include "util.h"
# Line 85  vector<unsigned char> Encode7to8bit(std: Line 88  vector<unsigned char> Encode7to8bit(std:
88          return buf;          return buf;
89  }  }
90    
91  string CreateSmsPdu(string to, string message, int& len)  vector<PduInfo> CreateSmsPdu(string to, string message, bool allowMultipart)
92  {  {
93          message = message.substr(0,160); //truncate to 160          bool multipart = allowMultipart && message.length() > 160;
94    
95            const unsigned char UHDI = multipart ? 0x40 : 0;
96    
97            srand(time(0));
98            unsigned char csms_ref = rand() % 256;
99    
100            int part_count;
101            if (multipart)
102            {
103                    part_count = message.length() / 153;
104                    if (message.length() % 153)
105                            part_count++;
106            }
107            else
108            {
109                    part_count = 1;
110            }
111    
112          vector<unsigned char> pdu;          vector<PduInfo> result;
113            for (int partnr = 0; partnr < part_count; ++partnr)
114            {
115                    vector<unsigned char> pdu;
116    
117                    pdu.push_back(0x00); // use SMSC from phone
118                    pdu.push_back( 0x01|UHDI ); // first octet -- no timeout
119                    pdu.push_back(0x00); // TP-MR message reference
120                    pdu.push_back(to.length() ); //length of phone nr
121                    pdu.push_back(0x91); // type of address (international nr  + ISDN/telephone range) - else try 0x81
122    
123          pdu.push_back(0x00); // use SMSC from phone                  vector<unsigned char> phone = BcdEncode(to);
124          pdu.push_back(0x01); // first octet -- no timeout                  pdu.insert( pdu.end(), phone.begin(), phone.end());
         pdu.push_back(0x00); // TP-MR message reference  
         pdu.push_back(to.length() ); //length of phone nr  
         pdu.push_back(0x91); // type of address (international nr  + ISDN/telephone range) - else try 0x81  
125    
126          vector<unsigned char> phone = BcdEncode(to);                  pdu.push_back(0x00); // Protocol identifier
127          pdu.insert( pdu.end(), phone.begin(), phone.end());                  pdu.push_back(0x00); // Data coding scheme
128    
129          pdu.push_back(0x00); // Protocol identifier                  string message_part;
130          pdu.push_back(0x00); // Data coding scheme                  if (multipart)
131          pdu.push_back( message.length() ); //UserDataLength                  {
132                            message_part = message.substr(0,153);
133                            message.erase(0,153);
134    
135          vector<unsigned char> userData = Encode7to8bit(message);                          pdu.push_back( message_part.length()+5 );  //UserDataLength
136          pdu.insert( pdu.end(), userData.begin(), userData.end());                          pdu.push_back( 0x00 ); // UDH[0]
137                            pdu.push_back( 0x03 ); // UDH[1] = UDH_LEN
138                            pdu.push_back( csms_ref ); //UDH[2]
139                            pdu.push_back( part_count );
140                            pdu.push_back( partnr );
141    
142          len = pdu.size()-1;                  }
143          return HexformatVector(pdu);                  else
144                    {
145                            message_part = message.substr(0,160); //truncate to 160
146    
147                            pdu.push_back( message_part.length() ); //UserDataLength
148                    }
149    
150                    vector<unsigned char> userData = Encode7to8bit(message_part);
151    
152                    pdu.insert( pdu.end(), userData.begin(), userData.end());
153    
154                    PduInfo info;
155                    info.len = pdu.size()-1;
156                    info.pdu = HexformatVector(pdu);
157                    result.push_back(info);
158    
159            }
160            return result;
161  }  }
162    
163  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20