36 |
|
|
37 |
string EncodePhonenr(string input) |
string EncodePhonenr(string input) |
38 |
{ |
{ |
39 |
|
if ( input.at(0) == '+' ) |
40 |
|
input.erase(0,1); |
41 |
|
|
42 |
if ( (input.length() % 2) == 1) |
if ( (input.length() % 2) == 1) |
43 |
input.append("F"); |
input.append("F"); |
44 |
return SwitchChars(input); |
return SwitchChars(input); |
81 |
return vec; |
return vec; |
82 |
} |
} |
83 |
|
|
84 |
std::string Decode8to7bit(vector<unsigned char> input) |
std::string Decode8to7bit(vector<unsigned char> input, int shift_start) |
85 |
{ |
{ |
86 |
string result; |
string result; |
87 |
|
|
88 |
int shift = 0; |
int shift = shift_start; |
89 |
for (unsigned int i=0; i<input.size(); ++i) |
for (unsigned int i=0; i<input.size(); ++i) |
90 |
{ |
{ |
91 |
unsigned char current = input.at(i); |
unsigned char current = input.at(i); |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
vector<unsigned char> Encode7to8bit(std::string str) |
vector<unsigned char> Encode7to8bit(std::string str, int shift_start) |
117 |
{ |
{ |
118 |
vector<unsigned char> buf; |
vector<unsigned char> buf; |
119 |
|
|
120 |
int shift = 0; |
int shift = shift_start; |
121 |
for (unsigned int i=0; i<str.size(); ++i) |
for (unsigned int i=0; i<str.size(); ++i) |
122 |
{ |
{ |
123 |
unsigned char current = str.at(i) & 0x7F; |
unsigned char current = str.at(i) & 0x7F; |
181 |
pdu.push_back(to.length() ); //length of phone nr |
pdu.push_back(to.length() ); //length of phone nr |
182 |
pdu.push_back(0x81); // type of address (international nr + ISDN/telephone range) - else try 0x81 |
pdu.push_back(0x81); // type of address (international nr + ISDN/telephone range) - else try 0x81 |
183 |
|
|
184 |
|
|
185 |
string phone = EncodePhonenr(to); |
vector<unsigned char> phone = HexDecodeString( EncodePhonenr(to )); |
186 |
pdu.insert( pdu.end(), phone.begin(), phone.end()); |
pdu.insert( pdu.end(), phone.begin(), phone.end()); |
187 |
|
|
188 |
pdu.push_back(0x00); // Protocol identifier |
pdu.push_back(0x00); // Protocol identifier |
189 |
pdu.push_back(0x00); // Data coding scheme |
pdu.push_back(0x00); // Data coding scheme |
190 |
|
|
191 |
|
int shift_start = 0; |
192 |
string message_part; |
string message_part; |
193 |
if (multipart) |
if (multipart) |
194 |
{ |
{ |
203 |
pdu.push_back( part_count ); |
pdu.push_back( part_count ); |
204 |
pdu.push_back( partnr+1 ); |
pdu.push_back( partnr+1 ); |
205 |
pdu.push_back( 0x00); |
pdu.push_back( 0x00); |
206 |
|
//shift_start = 6; |
207 |
} |
} |
208 |
else |
else |
209 |
{ |
{ |
220 |
pdu.push_back( message_part.length() ); //UserDataLength |
pdu.push_back( message_part.length() ); //UserDataLength |
221 |
} |
} |
222 |
|
|
223 |
vector<unsigned char> userData = Encode7to8bit(message_part); |
vector<unsigned char> userData = Encode7to8bit(message_part, shift_start); |
224 |
|
|
225 |
pdu.insert( pdu.end(), userData.begin(), userData.end()); |
pdu.insert( pdu.end(), userData.begin(), userData.end()); |
226 |
|
|
288 |
it += (*it++); // Skip smsc info |
it += (*it++); // Skip smsc info |
289 |
|
|
290 |
unsigned char deliver_first_octet = (*it++); |
unsigned char deliver_first_octet = (*it++); |
291 |
|
|
292 |
|
bool UDHI = (deliver_first_octet & 0x40) > 0; |
293 |
|
|
294 |
unsigned char sender_len = (*it++); |
unsigned char sender_len = (*it++); |
295 |
if ( (sender_len % 2) == 1) |
if ( (sender_len % 2) == 1) |
296 |
sender_len++; |
sender_len++; |
306 |
result.timestamp = DecodeTimestamp(it, it+7); |
result.timestamp = DecodeTimestamp(it, it+7); |
307 |
it += 7; |
it += 7; |
308 |
|
|
309 |
|
|
310 |
unsigned char data_len = (*it++); |
unsigned char data_len = (*it++); |
311 |
|
|
312 |
|
int shift_start = 0; |
313 |
|
if (UDHI) |
314 |
|
{ |
315 |
|
int udh_len = (*it++); |
316 |
|
cout << "UDH_LEN:" << udh_len << endl; |
317 |
|
it += udh_len; //just ignore the User Data Header |
318 |
|
data_len -= udh_len; |
319 |
|
|
320 |
|
shift_start = udh_len+1; //make the 8to7bit decode start with the right shift level |
321 |
|
} |
322 |
|
cout << hex<< (int)(*it) << endl;; |
323 |
|
|
324 |
|
|
325 |
vector<unsigned char> user_data; |
vector<unsigned char> user_data; |
326 |
user_data.insert(user_data.end(), it, it+data_len); |
user_data.insert(user_data.end(), it, it+data_len); |
327 |
|
|
328 |
result.message = Decode8to7bit(user_data); |
result.message = Decode8to7bit(user_data, shift_start); |
329 |
|
|
330 |
|
|
331 |
return result; |
return result; |