Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 44be3fc4 authored by Rika Brooks's avatar Rika Brooks Committed by Jake Hamby
Browse files

Telephony: Distinguish GSM vs ETWS bc by message id

Per 3GPP TS 24.012 3.1 GSM CB can be less than 88 byes.
Fix to distinguish GSM vs ETWS broadcast format by checking message id field
rather than length of pdu.

Bug: 7417676
Change-Id: I6aeedcd531a89ded7901db33d89ed45baaabbaa7
parent 708cb897
Loading
Loading
Loading
Loading
+39 −36
Original line number Diff line number Diff line
@@ -95,17 +95,22 @@ class SmsCbHeader {
            throw new IllegalArgumentException("Illegal PDU");
        }

        if (pdu.length <= PDU_LENGTH_ETWS) {
            format = FORMAT_ETWS_PRIMARY;
            geographicalScope = (pdu[0] & 0xc0) >> 6;
        if (pdu.length <= PDU_LENGTH_GSM) {
            // can be ETWS or GSM format.
            // Per TS23.041 9.4.1.2 and 9.4.1.3.2, GSM and ETWS format both
            // contain serial number which contains GS, Message Code, and Update Number
            // per 9.4.1.2.1, and message identifier in same octets
            geographicalScope = (pdu[0] & 0xc0) >>> 6;
            serialNumber = ((pdu[0] & 0xff) << 8) | (pdu[1] & 0xff);
            messageIdentifier = ((pdu[2] & 0xff) << 8) | (pdu[3] & 0xff);
            if (isEtwsMessage() && pdu.length <= PDU_LENGTH_ETWS) {
                format = FORMAT_ETWS_PRIMARY;
                dataCodingScheme = -1;
                pageIndex = -1;
                nrOfPages = -1;
                boolean emergencyUserAlert = (pdu[4] & 0x1) != 0;
                boolean activatePopup = (pdu[5] & 0x80) != 0;
            int warningType = (pdu[4] & 0xfe) >> 1;
                int warningType = (pdu[4] & 0xfe) >>> 1;
                byte[] warningSecurityInfo;
                // copy the Warning-Security-Information, if present
                if (pdu.length > PDU_HEADER_LENGTH) {
@@ -117,16 +122,13 @@ class SmsCbHeader {
                        warningSecurityInfo);
                mCmasInfo = null;
                return;     // skip the ETWS/CMAS initialization code for regular notifications
        } else if (pdu.length <= PDU_LENGTH_GSM) {
            } else {
                // GSM pdus are no more than 88 bytes
                format = FORMAT_GSM;
            geographicalScope = (pdu[0] & 0xc0) >> 6;
            serialNumber = ((pdu[0] & 0xff) << 8) | (pdu[1] & 0xff);
            messageIdentifier = ((pdu[2] & 0xff) << 8) | (pdu[3] & 0xff);
                dataCodingScheme = pdu[4] & 0xff;

                // Check for invalid page parameter
            int pageIndex = (pdu[5] & 0xf0) >> 4;
                int pageIndex = (pdu[5] & 0xf0) >>> 4;
                int nrOfPages = pdu[5] & 0x0f;

                if (pageIndex == 0 || nrOfPages == 0 || pageIndex > nrOfPages) {
@@ -136,6 +138,7 @@ class SmsCbHeader {

                this.pageIndex = pageIndex;
                this.nrOfPages = nrOfPages;
            }
        } else {
            // UMTS pdus are always at least 90 bytes since the payload includes
            // a number-of-pages octet and also one length octet per page
@@ -148,7 +151,7 @@ class SmsCbHeader {
            }

            messageIdentifier = ((pdu[1] & 0xff) << 8) | pdu[2] & 0xff;
            geographicalScope = (pdu[3] & 0xc0) >> 6;
            geographicalScope = (pdu[3] & 0xc0) >>> 6;
            serialNumber = ((pdu[3] & 0xff) << 8) | (pdu[4] & 0xff);
            dataCodingScheme = pdu[5] & 0xff;