Example #1
0
    def callback(self, pdumsg, msgcenter, somestring, sendernumber):
        logger.debug("New sms received")

        firstoctet = int(pdumsg[0])
        if firstoctet & 0x03:
            logger.debug("invalid SMS-DELIVER PDU, TP-MTI not cleared.")
            return

        if firstoctet & 0x40:
            logger.debug("message has user data header (multipart sms), not yet supported.")

        # construct pointer to TP-PID (protocol identifier).
        # We've got: first octet + address length (sender) + type of address
        # i.e. 3 bytes + the address itself (length specified in digits)
        ptr = 3 + int(ceil(float(pdumsg[1]) / 2))
        tp_dcs = int(pdumsg[ptr + 1])
        tp_udl = int(pdumsg[ptr + 9])

        msgarray = pdumsg[ptr + 10 : len(pdumsg)]

        # test for international msg
        if tp_dcs == 8:
            logger.debug("International sms received")
            msg = deoctify_int(msgarray)
        else:
            logger.debug("local sms received")
            msg = deoctify(msgarray)

        if msg > 0:
            logger.debug("Sms from: %s" % sendernumber)
            logger.debug("Sms content: %s" % msg)

        recv_sms_q.put({'phone_number': sendernumber,
                        'message': msg})
Example #2
0
    def callback(self, pdumsg, msgcenter, somestring, sendernumber):
        logger.debug("New sms received")

        firstoctet = int(pdumsg[0])
        if firstoctet & 0x03:
            logger.debug("invalid SMS-DELIVER PDU, TP-MTI not cleared.")
            return

        if firstoctet & 0x40:
            logger.debug(
                "message has user data header (multipart sms), not yet supported."
            )

        # construct pointer to TP-PID (protocol identifier).
        # We've got: first octet + address length (sender) + type of address
        # i.e. 3 bytes + the address itself (length specified in digits)
        ptr = 3 + int(ceil(float(pdumsg[1]) / 2))
        tp_dcs = int(pdumsg[ptr + 1])
        tp_udl = int(pdumsg[ptr + 9])

        msgarray = pdumsg[ptr + 10:len(pdumsg)]

        # test for international msg
        if tp_dcs == 8:
            logger.debug("International sms received")
            msg = deoctify_int(msgarray)
        else:
            logger.debug("local sms received")
            msg = deoctify(msgarray)

        if msg > 0:
            logger.debug("Sms from: %s" % sendernumber)
            logger.debug("Sms content: %s" % msg)

        recv_sms_q.put({'phone_number': sendernumber, 'message': msg})
Example #3
0
    def callback(self, pdumsg, msgcenter, somestring, sendernumber):
        logger.debug("New sms received")

        firstoctet = int(pdumsg[0])
        if firstoctet & 0x03:
            logger.debug("invalid SMS-DELIVER PDU, TP-MTI not cleared.")
            return

        # construct pointer to TP-PID (protocol identifier).
        # We've got: first octet + address length (sender) + type of address
        # i.e. 3 bytes + the address itself (length specified in digits)
        ptr = 3 + int(ceil(float(pdumsg[1]) / 2))
        tp_dcs = int(pdumsg[ptr + 1])

        msgarray = pdumsg[ptr + 10 : len(pdumsg)]

        # test for international msg
        if tp_dcs & 0x08:
            logger.debug("Incoming SMS is UCS-2 encoded.")
            msg = deoctify_int(msgarray)
        else:
            logger.debug("Incoming SMS uses GSM-7 alphabet")
            msg = deoctify(msgarray)

        complete = True
        if firstoctet & 0x40 and (msgarray[0] == 5 or msgarray[0] == 6) \
            and msgarray[1] == 0 and (msgarray[2] == msgarray[0] - 2):
            logger.debug("Incoming SMS is a concatenated SMS.")

            # extract CSMS ref
            ref = msgarray[3]
            if msgarray[2] == 4:
                ref = ref << 16 | msgarray[4]
                off = 1
            else:
                off = 0

            total_num = msgarray[4 + off]
            key = (sendernumber, ref, msgarray[5 + off])

            # strip UDH
            if tp_dcs & 0x08:
                msg = msg[3 + off:]
            else:
                msg = msg[7 + off:]

            # store fragment
            logger.debug("Storing fragment %d: %s" % (msgarray[5 + off], msg))
            self.csms_fragments[key] = msg;

            # check for completeness
            msg = ""
            for i in xrange(total_num):
                try:
                    msg += self.csms_fragments[sendernumber, ref, i + 1]
                except KeyError:
                    complete = False
                    logger.debug("Fragement %d still missing" % (i + 1))
                    break

            if complete:
                logger.debug("CSMS reception complete")
                for i in xrange(total_num):
                    del self.csms_fragments[sendernumber, ref, i + 1]

        if msg > 0 and complete:
            logger.debug("Sms from: %s" % sendernumber)
            logger.debug("Sms content: %s" % msg)

            recv_sms_q.put({'phone_number': sendernumber,
                            'message': msg})