--- smsdaemon/SmsPdu.cpp 2008/06/11 19:42:24 59 +++ smsdaemon/SmsPdu.cpp 2008/06/11 21:18:04 60 @@ -2,10 +2,13 @@ */ +#include "SmsPdu.h" + #include #include - +#include +#include #include "util.h" @@ -85,30 +88,76 @@ return buf; } -string CreateSmsPdu(string to, string message, int& len) +vector CreateSmsPdu(string to, string message, bool allowMultipart) { - message = message.substr(0,160); //truncate to 160 + bool multipart = allowMultipart && message.length() > 160; + + const unsigned char UHDI = multipart ? 0x40 : 0; + + srand(time(0)); + unsigned char csms_ref = rand() % 256; + + int part_count; + if (multipart) + { + part_count = message.length() / 153; + if (message.length() % 153) + part_count++; + } + else + { + part_count = 1; + } - vector pdu; + vector result; + for (int partnr = 0; partnr < part_count; ++partnr) + { + vector pdu; + + pdu.push_back(0x00); // use SMSC from phone + pdu.push_back( 0x01|UHDI ); // first octet -- no timeout + 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 - pdu.push_back(0x00); // use SMSC from phone - pdu.push_back(0x01); // first octet -- no timeout - 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 + vector phone = BcdEncode(to); + pdu.insert( pdu.end(), phone.begin(), phone.end()); - vector phone = BcdEncode(to); - pdu.insert( pdu.end(), phone.begin(), phone.end()); + pdu.push_back(0x00); // Protocol identifier + pdu.push_back(0x00); // Data coding scheme - pdu.push_back(0x00); // Protocol identifier - pdu.push_back(0x00); // Data coding scheme - pdu.push_back( message.length() ); //UserDataLength + string message_part; + if (multipart) + { + message_part = message.substr(0,153); + message.erase(0,153); - vector userData = Encode7to8bit(message); - pdu.insert( pdu.end(), userData.begin(), userData.end()); + pdu.push_back( message_part.length()+5 ); //UserDataLength + pdu.push_back( 0x00 ); // UDH[0] + pdu.push_back( 0x03 ); // UDH[1] = UDH_LEN + pdu.push_back( csms_ref ); //UDH[2] + pdu.push_back( part_count ); + pdu.push_back( partnr ); - len = pdu.size()-1; - return HexformatVector(pdu); + } + else + { + message_part = message.substr(0,160); //truncate to 160 + + pdu.push_back( message_part.length() ); //UserDataLength + } + + vector userData = Encode7to8bit(message_part); + + pdu.insert( pdu.end(), userData.begin(), userData.end()); + + PduInfo info; + info.len = pdu.size()-1; + info.pdu = HexformatVector(pdu); + result.push_back(info); + + } + return result; } }