Esempio n. 1
0
void TLUserData::parse(const TLFrame& src, size_t& rp)
{
	// The DCS is defined in GSM 03.38 4.
	assert(mDCS<0x100);	// Someone forgot to initialize the DCS.
	// TP-User-Data-Length
	mLength = src.readField(rp,8);
#if 1
	// This tail() works because UD is always the last field in the PDU.
	mRawData.clone(src.tail(rp));
	// Should we do this here?
	mRawData.LSB8MSB();
#else
	assert(!mUDHI);		// We don't support user headers.
	switch (mDCS) {
		case 0:
		case 244:
		case 245:
		case 246:
		case 247:
		{
			// GSM 7-bit encoding, GSM 03.38 6.
			// Check bounds.
			if (numChar*7 > (src.size()-rp)) {
				LOG(NOTICE) << "badly formatted TL-UD";
				SMS_READ_ERROR;
			}
			BitVector chars(src.tail(rp));
			chars.LSB8MSB();
			size_t crp=0;
			for (unsigned i=0; i<numChar; i++) {
				char gsm = chars.readFieldReversed(crp,7);
				mData[i] = decodeGSMChar(gsm);
			}
			mData[numChar]='\0';
			if (crp%8) crp += 8 - crp%8;
			rp += crp;
			return;
		}
		default:
		{
			rp += numChar;
			sprintf(mData,"unsupported DCS 0x%x", mDCS);
			LOG(NOTICE) << mData;
			SMS_READ_ERROR;
		}
	}
#endif
}
void TLUserData::parse(const TLFrame& src, size_t& rp)
{
	assert(!mUDHI);		// We don't support user headers.
	// The DCS is defined in GSM 03.38 4.
	assert(mDCS<0x100);	// Someone forgot to initialize the DCS.
	unsigned numChar = src.readField(rp,8);
	switch (mDCS) {
		case 0:
		case 244:
		case 245:
		case 246:
		case 247:
		{
			// GSM 7-bit encoding, GSM 03.38 6.
			// Check bounds.
			if (numChar*7 > (src.size()-rp)) {
				LOG(NOTICE) << "badly formatted TL-UD";
				SMS_READ_ERROR;
			}
			BitVector chars(src.tail(rp));
			chars.LSB8MSB();
			size_t crp=0;
			for (unsigned i=0; i<numChar; i++) {
				char gsm = chars.readFieldReversed(crp,7);
				mData[i] = decodeGSMChar(gsm);
			}
			mData[numChar]='\0';
			if (crp%8) crp += 8 - crp%8;
			rp += crp;
			return;
		}
		default:
		{
			rp += numChar;
			sprintf(mData,"unsupported DCS 0x%x", mDCS);
			LOG(NOTICE) << mData;
			SMS_READ_ERROR;
		}
	}
}