Search in sources :

Example 16 with DataCodingScheme

use of org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.

the class MoSbb method createSmsEvent.

private Sms createSmsEvent(SmsSubmitTpdu smsSubmitTpdu, TargetAddress ta, PersistenceRAInterface store, AddressString callingPartyAddress, int networkId, String originatorSccpAddress) throws SmscProcessingException {
    UserData userData = smsSubmitTpdu.getUserData();
    try {
        userData.decode();
    } catch (MAPException e) {
        throw new SmscProcessingException("MO MAPException when decoding user data", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    Sms sms = new Sms();
    sms.setDbId(UUID.randomUUID());
    sms.setOriginationType(OriginationType.SS7_MO);
    // checking parameters first
    if (callingPartyAddress == null || callingPartyAddress.getAddress() == null || callingPartyAddress.getAddress().isEmpty()) {
        throw new SmscProcessingException("MO SourceAddress digits are absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    if (callingPartyAddress.getAddressNature() == null) {
        throw new SmscProcessingException("MO SourceAddress AddressNature is absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    if (callingPartyAddress.getNumberingPlan() == null) {
        throw new SmscProcessingException("MO SourceAddress NumberingPlan is absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    sms.setSourceAddr(callingPartyAddress.getAddress());
    sms.setOriginatorSccpAddress(originatorSccpAddress);
    sms.setSourceAddrTon(callingPartyAddress.getAddressNature().getIndicator());
    sms.setSourceAddrNpi(callingPartyAddress.getNumberingPlan().getIndicator());
    sms.setOrigNetworkId(networkId);
    sms.setSubmitDate(new Timestamp(System.currentTimeMillis()));
    int messageingMode = (smscPropertiesManagement.getMoDefaultMessagingMode() & 0x03);
    sms.setEsmClass(messageingMode | (smsSubmitTpdu.getUserDataHeaderIndicator() ? SmppConstants.ESM_CLASS_UDHI_MASK : 0) | (smsSubmitTpdu.getReplyPathExists() ? SmppConstants.ESM_CLASS_REPLY_PATH_MASK : 0));
    sms.setProtocolId(smsSubmitTpdu.getProtocolIdentifier().getCode());
    sms.setPriority(0);
    // TODO: do we need somehow care with RegisteredDelivery ?
    sms.setReplaceIfPresent(smsSubmitTpdu.getRejectDuplicates() ? 2 : 0);
    sms.setStatusReportRequest(smsSubmitTpdu.getStatusReportRequest());
    DataCodingScheme dataCodingScheme = smsSubmitTpdu.getDataCodingScheme();
    int dcs = dataCodingScheme.getCode();
    String err = MessageUtil.checkDataCodingSchemeSupport(dcs);
    if (err != null) {
        throw new SmscProcessingException("MO DataCoding scheme does not supported: " + dcs + " - " + err, SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    sms.setDataCoding(dcs);
    sms.setShortMessageText(userData.getDecodedMessage());
    UserDataHeader udh = userData.getDecodedUserDataHeader();
    if (udh != null) {
        sms.setShortMessageBin(udh.getEncodedData());
    }
    // ValidityPeriod processing
    ValidityPeriod vp = smsSubmitTpdu.getValidityPeriod();
    ValidityPeriodFormat vpf = smsSubmitTpdu.getValidityPeriodFormat();
    Date validityPeriod = null;
    if (vp != null && vpf != null && vpf != ValidityPeriodFormat.fieldNotPresent) {
        switch(vpf) {
            case fieldPresentAbsoluteFormat:
                AbsoluteTimeStamp ats = vp.getAbsoluteFormatValue();
                Date dt = new Date(ats.getYear(), ats.getMonth(), ats.getDay(), ats.getHour(), ats.getMinute(), ats.getSecond());
                int i1 = ats.getTimeZone() * 15 * 60;
                int i2 = -new Date().getTimezoneOffset() * 60;
                long i3 = (i2 - i1) * 1000;
                validityPeriod = new Date(dt.getTime() + i3);
                break;
            case fieldPresentRelativeFormat:
                validityPeriod = new Date(new Date().getTime() + (long) (vp.getRelativeFormatHours() * 3600 * 1000));
                break;
            case fieldPresentEnhancedFormat:
                this.logger.info("Recieved unsupported ValidityPeriodFormat: PresentEnhancedFormat - we skip it");
                break;
        }
    }
    MessageUtil.applyValidityPeriod(sms, validityPeriod, false, smscPropertiesManagement.getMaxValidityPeriodHours(), smscPropertiesManagement.getDefaultValidityPeriodHours());
    SmsSet smsSet;
    smsSet = new SmsSet();
    smsSet.setDestAddr(ta.getAddr());
    smsSet.setDestAddrNpi(ta.getAddrNpi());
    smsSet.setDestAddrTon(ta.getAddrTon());
    smsSet.setNetworkId(networkId);
    smsSet.addSms(sms);
    long messageId = store.c2_getNextMessageId();
    SmscStatProvider.getInstance().setCurrentMessageId(messageId);
    sms.setMessageId(messageId);
    sms.setMoMessageRef(smsSubmitTpdu.getMessageReference());
    return sms;
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) AbsoluteTimeStamp(org.restcomm.protocols.ss7.map.api.smstpdu.AbsoluteTimeStamp) UserData(org.restcomm.protocols.ss7.map.api.smstpdu.UserData) MAPException(org.restcomm.protocols.ss7.map.api.MAPException) ISDNAddressString(org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.restcomm.protocols.ss7.map.api.primitives.AddressString) Timestamp(java.sql.Timestamp) Date(java.util.Date) ValidityPeriodFormat(org.restcomm.protocols.ss7.map.api.smstpdu.ValidityPeriodFormat) MAPDialogSms(org.restcomm.protocols.ss7.map.api.service.sms.MAPDialogSms) ValidityPeriod(org.restcomm.protocols.ss7.map.api.smstpdu.ValidityPeriod) UserDataHeader(org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader)

Example 17 with DataCodingScheme

use of org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.

the class MoSbb method createSmsEvent.

private Sms createSmsEvent(SmsDeliverTpdu smsDeliverTpdu, TargetAddress ta, PersistenceRAInterface store, CorrelationIdValue civ, int networkId, String originatorSccpAddress) throws SmscProcessingException {
    UserData userData = smsDeliverTpdu.getUserData();
    try {
        userData.decode();
    } catch (MAPException e) {
        throw new SmscProcessingException("MT MAPException when decoding user data", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    Sms sms = new Sms();
    sms.setDbId(UUID.randomUUID());
    sms.setOriginationType(OriginationType.SS7_HR);
    AddressField callingPartyAddress = smsDeliverTpdu.getOriginatingAddress();
    // checking parameters first
    if (callingPartyAddress == null || callingPartyAddress.getAddressValue() == null || callingPartyAddress.getAddressValue().isEmpty()) {
        throw new SmscProcessingException("Home routing: TPDU OriginatingAddress digits are absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    if (callingPartyAddress.getTypeOfNumber() == null) {
        throw new SmscProcessingException("Home routing: TPDU OriginatingAddress TypeOfNumber is absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    if (callingPartyAddress.getNumberingPlanIdentification() == null) {
        throw new SmscProcessingException("Home routing: TPDU OriginatingAddress NumberingPlanIdentification is absent", SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    sms.setSourceAddr(callingPartyAddress.getAddressValue());
    sms.setOriginatorSccpAddress(originatorSccpAddress);
    if (callingPartyAddress.getTypeOfNumber() == TypeOfNumber.Alphanumeric) {
        sms.setSourceAddrTon(TypeOfNumber.Alphanumeric.getCode());
        sms.setSourceAddrNpi(NumberingPlanIdentification.Unknown.getCode());
    } else {
        sms.setSourceAddrTon(callingPartyAddress.getTypeOfNumber().getCode());
        sms.setSourceAddrNpi(callingPartyAddress.getNumberingPlanIdentification().getCode());
    }
    sms.setOrigNetworkId(networkId);
    sms.setSubmitDate(new Timestamp(System.currentTimeMillis()));
    int messageingMode = (smscPropertiesManagement.getHrDefaultMessagingMode() & 0x03);
    sms.setEsmClass(messageingMode | (smsDeliverTpdu.getUserDataHeaderIndicator() ? SmppConstants.ESM_CLASS_UDHI_MASK : 0) | (smsDeliverTpdu.getReplyPathExists() ? SmppConstants.ESM_CLASS_REPLY_PATH_MASK : 0));
    sms.setProtocolId(smsDeliverTpdu.getProtocolIdentifier().getCode());
    sms.setPriority(0);
    // TODO: do we need somehow care with RegisteredDelivery ?
    sms.setReplaceIfPresent(0);
    // TODO: care with smsSubmitTpdu.getStatusReportRequest() parameter
    // sending back SMS_STATUS_REPORT tpdu ?
    DataCodingScheme dataCodingScheme = smsDeliverTpdu.getDataCodingScheme();
    int dcs = dataCodingScheme.getCode();
    String err = MessageUtil.checkDataCodingSchemeSupport(dcs);
    if (err != null) {
        throw new SmscProcessingException("Home routing: DataCoding scheme does not supported: " + dcs + " - " + err, SmppConstants.STATUS_SYSERR, MAPErrorCode.unexpectedDataValue, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null);
    }
    sms.setDataCoding(dcs);
    sms.setShortMessageText(userData.getDecodedMessage());
    UserDataHeader udh = userData.getDecodedUserDataHeader();
    if (udh != null) {
        sms.setShortMessageBin(udh.getEncodedData());
    }
    // ValidityPeriod processing
    MessageUtil.applyValidityPeriod(sms, null, false, smscPropertiesManagement.getMaxValidityPeriodHours(), smscPropertiesManagement.getDefaultValidityPeriodHours());
    SmsSet smsSet;
    smsSet = new SmsSet();
    smsSet.setDestAddr(ta.getAddr());
    smsSet.setDestAddrNpi(ta.getAddrNpi());
    smsSet.setDestAddrTon(ta.getAddrTon());
    smsSet.setNetworkId(networkId);
    smsSet.setCorrelationId(civ.getCorrelationID());
    smsSet.setImsi(civ.getImsi());
    smsSet.setLocationInfoWithLMSI(civ.getLocationInfoWithLMSI());
    smsSet.addSms(sms);
    sms.setSmsSet(smsSet);
    long messageId = store.c2_getNextMessageId();
    SmscStatProvider.getInstance().setCurrentMessageId(messageId);
    sms.setMessageId(messageId);
    return sms;
}
Also used : AddressField(org.restcomm.protocols.ss7.map.api.smstpdu.AddressField) DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) UserData(org.restcomm.protocols.ss7.map.api.smstpdu.UserData) MAPException(org.restcomm.protocols.ss7.map.api.MAPException) MAPDialogSms(org.restcomm.protocols.ss7.map.api.service.sms.MAPDialogSms) ISDNAddressString(org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.restcomm.protocols.ss7.map.api.primitives.AddressString) Timestamp(java.sql.Timestamp) UserDataHeader(org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader)

Example 18 with DataCodingScheme

use of org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.

the class DBOperations method createSms.

protected SmsSet createSms(final Row row, SmsSet smsSet, boolean shortMessageNewStringFormat, boolean addedCorrId, boolean addedNetworkId, boolean addedOrigNetworkId, boolean addedPacket1, boolean getMessageInProcessing) throws PersistenceException {
    if (row == null) {
        return smsSet;
    }
    int inSystem = row.getInt(Schema.COLUMN_IN_SYSTEM);
    UUID smscUuid = row.getUUID(Schema.COLUMN_SMSC_UUID);
    if (!getMessageInProcessing && (inSystem == IN_SYSTEM_SENT || inSystem == IN_SYSTEM_INPROCESS && smscUuid.equals(currentSessionUUID))) {
        // inSystem it is in processing or processed - skip this
        return smsSet;
    }
    Sms sms = new Sms();
    sms.setStored(true);
    sms.setDbId(row.getUUID(Schema.COLUMN_ID));
    sms.setDueSlot(row.getLong(Schema.COLUMN_DUE_SLOT));
    sms.setSourceAddr(row.getString(Schema.COLUMN_ADDR_SRC_DIGITS));
    sms.setSourceAddrTon(row.getInt(Schema.COLUMN_ADDR_SRC_TON));
    sms.setSourceAddrNpi(row.getInt(Schema.COLUMN_ADDR_SRC_NPI));
    if (addedOrigNetworkId) {
        sms.setOrigNetworkId(row.getInt(Schema.COLUMN_ORIG_NETWORK_ID));
    }
    sms.setMessageId(row.getLong(Schema.COLUMN_MESSAGE_ID));
    sms.setMoMessageRef(row.getInt(Schema.COLUMN_MO_MESSAGE_REF));
    sms.setOrigEsmeName(row.getString(Schema.COLUMN_ORIG_ESME_NAME));
    sms.setOrigSystemId(row.getString(Schema.COLUMN_ORIG_SYSTEM_ID));
    sms.setSubmitDate(getRowDate(row, Schema.COLUMN_SUBMIT_DATE));
    sms.setServiceType(row.getString(Schema.COLUMN_SERVICE_TYPE));
    sms.setEsmClass(row.getInt(Schema.COLUMN_ESM_CLASS));
    sms.setProtocolId(row.getInt(Schema.COLUMN_PROTOCOL_ID));
    sms.setPriority(row.getInt(Schema.COLUMN_PRIORITY));
    sms.setRegisteredDelivery(row.getInt(Schema.COLUMN_REGISTERED_DELIVERY));
    sms.setReplaceIfPresent(row.getInt(Schema.COLUMN_REPLACE));
    sms.setDataCodingForDatabase(row.getInt(Schema.COLUMN_DATA_CODING));
    sms.setDefaultMsgId(row.getInt(Schema.COLUMN_DEFAULT_MSG_ID));
    if (shortMessageNewStringFormat) {
        sms.setShortMessageText(row.getString(Schema.COLUMN_MESSAGE_TEXT));
        ByteBuffer bb = row.getBytes(Schema.COLUMN_MESSAGE_BIN);
        if (bb != null) {
            byte[] buf = new byte[bb.limit() - bb.position()];
            bb.get(buf);
            sms.setShortMessageBin(buf);
        }
    } else {
        ByteBuffer bb = row.getBytes(Schema.COLUMN_MESSAGE);
        if (bb != null) {
            byte[] buf = new byte[bb.limit() - bb.position()];
            bb.get(buf);
            sms.setShortMessage(buf);
            // convert to a new format
            byte[] shortMessage = sms.getShortMessage();
            byte[] textPart = shortMessage;
            byte[] udhData = null;
            boolean udhExists = false;
            DataCodingScheme dcs = new DataCodingSchemeImpl(sms.getDataCoding());
            String msg = null;
            if (dcs.getCharacterSet() == CharacterSet.GSM8) {
                udhData = shortMessage;
            } else {
                if ((sms.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0) {
                    udhExists = true;
                }
                if (udhExists && shortMessage != null && shortMessage.length > 2) {
                    // UDH exists
                    int udhLen = (shortMessage[0] & 0xFF) + 1;
                    if (udhLen <= shortMessage.length) {
                        textPart = new byte[shortMessage.length - udhLen];
                        udhData = new byte[udhLen];
                        System.arraycopy(shortMessage, udhLen, textPart, 0, textPart.length);
                        System.arraycopy(shortMessage, 0, udhData, 0, udhLen);
                    }
                }
                switch(dcs.getCharacterSet()) {
                    case GSM7:
                        msg = new String(textPart);
                        break;
                    case UCS2:
                        Charset ucs2Charset = Charset.forName("UTF-16BE");
                        bb = ByteBuffer.wrap(textPart);
                        CharBuffer bf = ucs2Charset.decode(bb);
                        msg = bf.toString();
                        break;
                    default:
                        udhData = sms.getShortMessage();
                        break;
                }
            }
            sms.setShortMessageText(msg);
            sms.setShortMessageBin(udhData);
        }
    }
    sms.setScheduleDeliveryTime(getRowDate(row, Schema.COLUMN_SCHEDULE_DELIVERY_TIME));
    sms.setValidityPeriod(getRowDate(row, Schema.COLUMN_VALIDITY_PERIOD));
    sms.setDeliveryCount(row.getInt(Schema.COLUMN_DELIVERY_COUNT));
    if (addedPacket1) {
        sms.setOriginatorSccpAddress(row.getString(Schema.COLUMN_ORIGINATOR_SCCP_ADDRESS));
        // TODO: extra columns for further usage
        sms.setStatusReportRequest(row.getBool(Schema.COLUMN_STATUS_REPORT_REQUEST));
        sms.setDeliveryAttempt(row.getInt(Schema.COLUMN_DELIVERY_ATTEMPT));
        sms.setUserData(row.getString(Schema.COLUMN_USER_DATA));
        sms.setExtraData(row.getString(Schema.COLUMN_EXTRA_DATA));
        sms.setExtraData_2(row.getString(Schema.COLUMN_EXTRA_DATA_2));
        sms.setExtraData_3(row.getString(Schema.COLUMN_EXTRA_DATA_3));
        sms.setExtraData_4(row.getString(Schema.COLUMN_EXTRA_DATA_4));
    }
    String s = row.getString(Schema.COLUMN_OPTIONAL_PARAMETERS);
    if (s != null) {
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());
            XMLObjectReader reader = XMLObjectReader.newInstance(bais);
            TlvSet copy = reader.read(TLV_SET, TlvSet.class);
            sms.getTlvSet().clearAllOptionalParameter();
            sms.getTlvSet().addAllOptionalParameter(copy.getOptionalParameters());
        } catch (XMLStreamException e) {
            String msg = "XMLStreamException when deserializing optional parameters for '" + sms.getDbId() + "'!";
            throw new PersistenceException(msg, e);
        }
    }
    if (smsSet == null) {
        smsSet = new SmsSet();
        String destAddr = null;
        int destAddrTon = -1;
        int destAddrNpi = -1;
        destAddr = row.getString(Schema.COLUMN_ADDR_DST_DIGITS);
        destAddrTon = row.getInt(Schema.COLUMN_ADDR_DST_TON);
        destAddrNpi = row.getInt(Schema.COLUMN_ADDR_DST_NPI);
        if (destAddr == null || destAddrTon == -1 || destAddrNpi == -1) {
            throw new PersistenceException("destAddr or destAddrTon or destAddrNpi is absent for ID='" + sms.getDbId() + "'");
        }
        smsSet.setDestAddr(destAddr);
        smsSet.setDestAddrTon(destAddrTon);
        smsSet.setDestAddrNpi(destAddrNpi);
        if (getMessageInProcessing) {
            smsSet.setInSystem(inSystem);
            smsSet.setStatus(ErrorCode.fromInt(row.getInt(Schema.COLUMN_SM_STATUS)));
        }
        if (addedNetworkId) {
            smsSet.setNetworkId(row.getInt(Schema.COLUMN_NETWORK_ID));
        } else {
            String tagId = row.getString(Schema.COLUMN_TARGET_ID);
            if (tagId != null) {
                String[] ss = tagId.split("_");
                if (ss.length == 4) {
                    String s1 = ss[3];
                    try {
                        int networkId = Integer.parseInt(s1);
                        smsSet.setNetworkId(networkId);
                    } catch (Exception e) {
                    }
                }
            }
        }
        if (addedCorrId)
            smsSet.setCorrelationId(row.getString(Schema.COLUMN_CORR_ID));
        else
            smsSet.setCorrelationId(row.getString(Schema.COLUMN_IMSI));
    }
    int dueDelay = row.getInt(Schema.COLUMN_DUE_DELAY);
    if (dueDelay > smsSet.getDueDelay())
        smsSet.setDueDelay(dueDelay);
    boolean alertingSupported = row.getBool(Schema.COLUMN_ALERTING_SUPPORTED);
    if (alertingSupported)
        smsSet.setAlertingSupported(true);
    smsSet.addSms(sms);
    return smsSet;
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) CharBuffer(java.nio.CharBuffer) Charset(java.nio.charset.Charset) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ByteBuffer(java.nio.ByteBuffer) XMLStreamException(javolution.xml.stream.XMLStreamException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException) XMLStreamException(javolution.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) Sms(org.mobicents.smsc.library.Sms) XMLObjectReader(javolution.xml.XMLObjectReader) TlvSet(org.restcomm.smpp.parameter.TlvSet) UUID(java.util.UUID) SmsSet(org.mobicents.smsc.library.SmsSet)

Example 19 with DataCodingScheme

use of org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.

the class CdrGenerator method generateCdr.

public static void generateCdr(Sms smsEvent, String status, String reason, boolean generateReceiptCdr, boolean generateCdr, boolean messageIsSplitted, boolean lastSegment, boolean calculateMsgPartsLenCdr, boolean delayParametersInCdr, int seqNumber) {
    if (!generateCdr)
        return;
    if (!generateReceiptCdr && smsEvent.isMcDeliveryReceipt())
        // we do not generate CDR's for receipt if generateReceiptCdr option is off
        return;
    int msgParts = 0, charNumbers = 0;
    if (calculateMsgPartsLenCdr) {
        if (messageIsSplitted) {
            msgParts = 1;
        } else {
            DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(smsEvent.getDataCoding());
            msgParts = MessageUtil.calculateMsgParts(smsEvent.getShortMessageText(), dataCodingScheme, smsEvent.getNationalLanguageLockingShift(), smsEvent.getNationalLanguageSingleShift());
        }
        if (lastSegment) {
            charNumbers = smsEvent.getShortMessageText().length();
        } else {
            charNumbers = 0;
        }
    }
    int dcs = smsEvent.getDataCoding();
    Long receiptLocalMessageId = smsEvent.getReceiptLocalMessageId();
    long msgPartDelTime = -1;
    if (smsEvent.getMsgPartsSeqNumbers().contains(seqNumber - 1)) {
        msgPartDelTime = smsEvent.getMsgPartDelTime(seqNumber) - smsEvent.getMsgPartDelTime(seqNumber - 1);
    } else if (smsEvent.getMsgPartsSeqNumbers().contains(seqNumber)) {
        msgPartDelTime = smsEvent.getMsgPartDelTime(seqNumber) - smsEvent.getSubmitDate().getTime();
    }
    DeliveryReceiptData deliveryReceiptData = MessageUtil.parseDeliveryReceipt(smsEvent.getShortMessageText(), smsEvent.getTlvSet());
    String st = null;
    int tlvMessageState = -1;
    int err = -1;
    if (deliveryReceiptData != null) {
        st = deliveryReceiptData.getStatus();
        tlvMessageState = deliveryReceiptData.getTlvMessageState() == null ? -1 : deliveryReceiptData.getTlvMessageState();
        err = deliveryReceiptData.getError();
    }
    StringBuffer sb = new StringBuffer();
    sb.append(DATE_FORMAT.format(smsEvent.getSubmitDate())).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddr()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddrTon()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddrNpi()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddr()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddrTon()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddrNpi()).append(CdrGenerator.CDR_SEPARATOR).append(status).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOriginationType()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getReceiptLocalMessageId() == null ? "message" : "dlr").append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOrigSystemId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMessageId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getDlvMessageId()).append(CdrGenerator.CDR_SEPARATOR).append((receiptLocalMessageId != null && receiptLocalMessageId == -1) ? "xxxx" : smsEvent.getReceiptLocalMessageId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getLocationInfoWithLMSI() != null ? smsEvent.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber().getAddress() : null).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getImsi()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getCorrelationId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOriginatorSccpAddress()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMtServiceCenterAddress()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOrigNetworkId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getNetworkId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMprocNotes()).append(CdrGenerator.CDR_SEPARATOR).append(msgParts).append(CdrGenerator.CDR_SEPARATOR).append(charNumbers).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? getProcessingTime(smsEvent.getSubmitDate()) : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? getScheduleDeliveryDelayMilis(smsEvent.getSubmitDate(), smsEvent.getScheduleDeliveryTime()) : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? smsEvent.getDeliveryCount() : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(msgPartDelTime != -1 ? msgPartDelTime : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(dcs).append(CdrGenerator.CDR_SEPARATOR).append("\"").append(getEscapedString(getFirst20CharOfSMS(smsEvent.getShortMessageText()))).append("\"").append(CdrGenerator.CDR_SEPARATOR).append("\"").append(getEscapedString(reason)).append("\"").append(CdrGenerator.CDR_SEPARATOR).append(st != null ? st : CdrGenerator.CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(tlvMessageState != -1 ? tlvMessageState : CdrGenerator.CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(err != -1 ? err : CdrGenerator.CDR_EMPTY);
    CdrGenerator.generateCdr(sb.toString());
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) DeliveryReceiptData(org.mobicents.smsc.mproc.DeliveryReceiptData) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)

Example 20 with DataCodingScheme

use of org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme in project smscgateway by RestComm.

the class SmppTestingForm method submitMessage.

private void submitMessage(EncodingType encodingType, int messageClass, String messageText, SplittingType splittingType, ValidityType validityType, String destAddr, SmppSimulatorParameters.MessagingMode messagingMode, int specifiedSegmentLength) {
    if (session0 == null)
        return;
    try {
        int dcs = 0;
        ArrayList<byte[]> msgLst = new ArrayList<byte[]>();
        int msgRef = 0;
        switch(encodingType) {
            case GSM7_DCS_0:
                dcs = 0;
                break;
            case GSM8_DCS_4:
                dcs = 4;
                break;
            case UCS2_DCS_8:
                dcs = 8;
                break;
        }
        // if (messageClass) {
        // dcs += 16;
        // }
        int messageClassVal = 0;
        if (messageClass > 0) {
            messageClassVal = messageClass;
        }
        DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dcs);
        int maxLen = MessageUtil.getMaxSolidMessageCharsLength(dataCodingScheme);
        int maxSplLen = MessageUtil.getMaxSegmentedMessageCharsLength(dataCodingScheme);
        if (splittingType == SplittingType.SplitWithParameters_SpecifiedSegmentLength || splittingType == SplittingType.SplitWithUdh_SpecifiedSegmentLength) {
            maxLen = specifiedSegmentLength;
            maxSplLen = specifiedSegmentLength;
        }
        int segmCnt = 0;
        int esmClass = 0;
        boolean addSegmTlv = false;
        if (messageText.length() > maxLen) {
            // may be message splitting
            SplittingType st = splittingType;
            switch(st) {
                case DoNotSplit:
                    // we do not split
                    byte[] buf1 = encodeSegment(messageText, encodingType);
                    byte[] buf2;
                    if (encodingType == EncodingType.GSM8_DCS_4) {
                        // 4-bytes length
                        byte[] bf3 = new byte[7];
                        // total UDH length
                        bf3[0] = 6;
                        // UDH id
                        bf3[1] = 5;
                        // UDH length
                        bf3[2] = 4;
                        bf3[3] = 0x3E;
                        bf3[4] = (byte) 0x94;
                        bf3[5] = 0;
                        bf3[6] = 0;
                        // 0-bytes length
                        // bf3 = new byte[3];
                        // bf3[0] = 2; // total UDH length
                        // bf3[1] = 112; // UDH id
                        // bf3[2] = 0; // UDH length
                        buf2 = new byte[bf3.length + buf1.length];
                        System.arraycopy(bf3, 0, buf2, 0, bf3.length);
                        System.arraycopy(buf1, 0, buf2, bf3.length, buf1.length);
                        esmClass = 0x40;
                    } else {
                        buf2 = buf1;
                    }
                    msgLst.add(buf2);
                    ArrayList<String> r1 = this.splitStr(messageText, maxSplLen);
                    segmCnt = r1.size();
                    break;
                case SplitWithParameters_DefaultSegmentLength:
                case SplitWithParameters_SpecifiedSegmentLength:
                    msgRef = getNextMsgRef();
                    r1 = this.splitStr(messageText, maxSplLen);
                    for (String bf : r1) {
                        msgLst.add(encodeSegment(bf, encodingType));
                    }
                    segmCnt = msgLst.size();
                    addSegmTlv = true;
                    break;
                case SplitWithUdh_DefaultSegmentLength:
                case SplitWithUdh_SpecifiedSegmentLength:
                    msgRef = getNextMsgRef();
                    r1 = this.splitStr(messageText, maxSplLen);
                    byte[] bf1 = new byte[6];
                    // total UDH length
                    bf1[0] = 5;
                    // UDH id
                    bf1[1] = 0;
                    // UDH length
                    bf1[2] = 3;
                    // refNum
                    bf1[3] = (byte) msgRef;
                    // segmCnt
                    bf1[4] = (byte) r1.size();
                    int i1 = 0;
                    for (String bfStr : r1) {
                        byte[] bf = encodeSegment(bfStr, encodingType);
                        i1++;
                        // segmNum
                        bf1[5] = (byte) i1;
                        byte[] bf2 = new byte[bf1.length + bf.length];
                        System.arraycopy(bf1, 0, bf2, 0, bf1.length);
                        System.arraycopy(bf, 0, bf2, bf1.length, bf.length);
                        msgLst.add(bf2);
                    }
                    segmCnt = msgLst.size();
                    esmClass = 0x40;
                    break;
            }
        } else {
            byte[] buf = encodeSegment(messageText, encodingType);
            if (encodingType == EncodingType.GSM8_DCS_4) {
                byte[] bf1 = new byte[7];
                // total UDH length
                bf1[0] = 6;
                // UDH id
                bf1[1] = 5;
                // UDH length
                bf1[2] = 4;
                bf1[3] = 0x3e;
                bf1[4] = (byte) 0x94;
                bf1[5] = 0;
                bf1[6] = 0;
                // 0-bytes length
                // bf1 = new byte[3];
                // bf1[0] = 2; // total UDH length
                // bf1[1] = 112; // UDH id
                // bf1[2] = 0; // UDH length
                byte[] bf2 = new byte[bf1.length + buf.length];
                System.arraycopy(bf1, 0, bf2, 0, bf1.length);
                System.arraycopy(buf, 0, bf2, bf1.length, buf.length);
                msgLst.add(bf2);
                esmClass = 0x40;
            } else {
                msgLst.add(buf);
            }
            segmCnt = 1;
        }
        esmClass |= messagingMode.getCode();
        this.doSubmitMessage(dcs, msgLst, msgRef, addSegmTlv, esmClass, validityType, segmCnt, destAddr, messageClassVal);
    } catch (Exception e) {
        this.addMessage("Failure to submit message", e.toString());
        return;
    }
}
Also used : DataCodingScheme(org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme) ArrayList(java.util.ArrayList) DataCodingSchemeImpl(org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) SplittingType(org.mobicents.smsc.tools.smppsimulator.SmppSimulatorParameters.SplittingType) SmppChannelException(com.cloudhopper.smpp.type.SmppChannelException) CharacterCodingException(java.nio.charset.CharacterCodingException)

Aggregations

DataCodingScheme (org.restcomm.protocols.ss7.map.api.smstpdu.DataCodingScheme)21 DataCodingSchemeImpl (org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)18 Date (java.util.Date)11 Sms (org.mobicents.smsc.library.Sms)8 UserDataHeader (org.restcomm.protocols.ss7.map.api.smstpdu.UserDataHeader)8 Test (org.testng.annotations.Test)7 ByteBuffer (java.nio.ByteBuffer)6 CharacterCodingException (java.nio.charset.CharacterCodingException)6 AddressString (org.restcomm.protocols.ss7.map.api.primitives.AddressString)6 ISDNAddressString (org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString)6 UserData (org.restcomm.protocols.ss7.map.api.smstpdu.UserData)6 UserDataHeaderImpl (org.restcomm.protocols.ss7.map.smstpdu.UserDataHeaderImpl)6 Tlv (com.cloudhopper.smpp.tlv.Tlv)5 PreparedStatementCollection (org.mobicents.smsc.cassandra.PreparedStatementCollection)5 SmsSet (org.mobicents.smsc.library.SmsSet)5 AddressField (org.restcomm.protocols.ss7.map.api.smstpdu.AddressField)5 Timestamp (java.sql.Timestamp)4 MAPDialogSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy)4 MAPProviderProxy (org.mobicents.smsc.slee.resources.persistence.MAPProviderProxy)4 MAPServiceSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPServiceSmsProxy)4