--- smsdaemon/SmsPdu.cpp 2008/06/11 19:42:24 59 +++ smsdaemon/SmsPdu.cpp 2008/06/12 12:04:32 62 @@ -2,10 +2,13 @@ */ +#include "SmsPdu.h" + #include #include - +#include +#include #include "util.h" @@ -40,6 +43,12 @@ } } + if ((input.length() % 2) == 1) + { + current |= 0xF0; + result.push_back(current); + } + return result; } @@ -58,6 +67,13 @@ return os.str(); } +std::string Encode8to7bit(vector vec) +{ + string result; + + return result; +} + vector Encode7to8bit(std::string str) { vector buf; @@ -85,30 +101,81 @@ 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 UDHI = multipart ? 0x40 : 0; - vector pdu; + srand(time(0)); + unsigned char csms_ref = rand() % 128; - 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 + int part_count; - vector phone = BcdEncode(to); - pdu.insert( pdu.end(), phone.begin(), phone.end()); + const int PDU_LEN = 153; + + if (multipart) + { + part_count = message.length() / PDU_LEN; + if (message.length() % PDU_LEN) + part_count++; + } + else + { + part_count = 1; + } - pdu.push_back(0x00); // Protocol identifier - pdu.push_back(0x00); // Data coding scheme - pdu.push_back( message.length() ); //UserDataLength + vector result; + for (int partnr = 0; partnr < part_count; ++partnr) + { + vector pdu; - vector userData = Encode7to8bit(message); - pdu.insert( pdu.end(), userData.begin(), userData.end()); + pdu.push_back(0x00); // use SMSC from phone + pdu.push_back( 0x01|UDHI ); // 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 - len = pdu.size()-1; - return HexformatVector(pdu); + 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 + + string message_part; + if (multipart) + { + message_part = message.substr(0, PDU_LEN); + message.erase(0, PDU_LEN); + + pdu.push_back( message_part.length()+ 7 ); //UserDataLength + pdu.push_back( 0x06 ); // UDH Len + pdu.push_back( 0x00 ); // UDH Element Identifier + pdu.push_back( 0x03 ); // UDH element length + pdu.push_back( csms_ref ); // csms_ref reference + pdu.push_back( part_count ); + pdu.push_back( partnr+1 ); + pdu.push_back( 0x00); + + } + 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; } }