Bug 738132 - Part 3: parse application port address for incoming messages. r=philikon a=b2g-only
authorVicamo Yang <vyang@mozilla.com>
Mon, 23 Apr 2012 20:43:32 -0300
changeset 95489 2f422d4378a38100c55288b0eb2e3e7639401e31
parent 95488 88b7eafda84ee2e18b9b72aabfab547482e7b6b9
child 95490 ee30e2a91e10b03cfed1da0a772ef8a247459a82
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilikon, b2g-only
bugs738132
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 738132 - Part 3: parse application port address for incoming messages. r=philikon a=b2g-only
dom/system/gonk/RadioInterfaceLayer.js
dom/system/gonk/ril_consts.js
dom/system/gonk/ril_worker.js
--- a/dom/system/gonk/RadioInterfaceLayer.js
+++ b/dom/system/gonk/RadioInterfaceLayer.js
@@ -168,16 +168,17 @@ function RadioInterfaceLayer() {
                      type: null,
                      signalStrength: null,
                      relSignalStrength: null},
   };
   ppmm.addMessageListener("RIL:GetRadioState", this);
   Services.obs.addObserver(this, "xpcom-shutdown", false);
 
   this._sentSmsEnvelopes = {};
+  this.portAddressedSmsApps = {};
 }
 RadioInterfaceLayer.prototype = {
 
   classID:   RADIOINTERFACELAYER_CID,
   classInfo: XPCOMUtils.generateCI({classID: RADIOINTERFACELAYER_CID,
                                     classDescription: "RadioInterfaceLayer",
                                     interfaces: [Ci.nsIWorkerHolder,
                                                  Ci.nsIRadioInterfaceLayer]}),
@@ -455,19 +456,31 @@ RadioInterfaceLayer.prototype = {
         keepGoing = true;
       }
       if (!keepGoing) {
         break;
       }
     }
   },
 
+  portAddressedSmsApps: null,
   handleSmsReceived: function handleSmsReceived(message) {
     debug("handleSmsReceived: " + JSON.stringify(message));
 
+    // Dispatch to registered handler if application port addressing is
+    // available. Note that the destination port can possibly be zero when
+    // representing a UDP/TCP port.
+    if (message.header.destinationPort != null) {
+      let handler = this.portAddressedSmsApps[message.header.destinationPort];
+      if (handler) {
+        handler(message);
+      }
+      return;
+    }
+
     if (message.encoding == RIL.PDU_DCS_MSG_CODING_8BITS_ALPHABET) {
       // Don't know how to handle binary data yet.
       return;
     }
 
     let id = gSmsDatabaseService.saveReceivedMessage(message.sender || null,
                                                      message.fullBody || null,
                                                      message.timestamp);
--- a/dom/system/gonk/ril_consts.js
+++ b/dom/system/gonk/ril_consts.js
@@ -653,16 +653,20 @@ const PDU_IEI_CHARACTER_SIZE_WVG_OBJECT 
 const PDU_IEI_EXTENDED_OBJECT_DATA_REQUEST_COMMAND     = 0x1A;
 const PDU_IEI_RFC822_EMAIL_HEADER                      = 0x20;
 const PDU_IEI_HYPERLINK_FORMAT_ELEMENT                 = 0x21;
 const PDU_IEI_REPLY_ADDRESS_ELEMENT                    = 0x22;
 const PDU_IEI_ENHANCED_VOICE_MAIL_INFORMATION          = 0x23;
 const PDU_IEI_NATIONAL_LANGUAGE_SINGLE_SHIFT           = 0x24;
 const PDU_IEI_NATIONAL_LANGUAGE_LOCKING_SHIFT          = 0x25;
 
+// Application Port Addressing, see 3GPP TS 23.040 9.2.3.24.3
+const PDU_APA_RESERVED_8BIT_PORTS = 240;
+const PDU_APA_VALID_16BIT_PORTS   = 49152;
+
 // 7bit alphabet escape character. The encoded value of this code point is left
 // undefined in official spec. Its code value is internally assigned to \uffff,
 // <noncharacter-FFFF> in Unicode basic multilingual plane.
 const PDU_NL_EXTENDED_ESCAPE = 0x1B;
 
 // <SP>, <LF>, <CR> are only defined in locking shift tables.
 const PDU_NL_SPACE = 0x20;
 const PDU_NL_LINE_FEED = 0x0A;
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -3190,16 +3190,45 @@ let GsmPDUHelper = {
           dataAvailable -= 3;
           if (max && seq && (seq <= max)) {
             header.segmentRef = ref;
             header.segmentMaxSeq = max;
             header.segmentSeq = seq;
           }
           break;
         }
+        case PDU_IEI_APPLICATION_PORT_ADDREESING_SCHEME_8BIT: {
+          let dstp = this.readHexOctet();
+          let orip = this.readHexOctet();
+          dataAvailable -= 2;
+          if ((dstp < PDU_APA_RESERVED_8BIT_PORTS)
+              || (orip < PDU_APA_RESERVED_8BIT_PORTS)) {
+            // 3GPP TS 23.040 clause 9.2.3.24.3: "A receiving entity shall
+            // ignore any information element where the value of the
+            // Information-Element-Data is Reserved or not supported"
+            break;
+          }
+          header.destinationPort = dstp;
+          header.originatorPort = orip;
+          break;
+        }
+        case PDU_IEI_APPLICATION_PORT_ADDREESING_SCHEME_16BIT: {
+          let dstp = (this.readHexOctet() << 8) | this.readHexOctet();
+          let orip = (this.readHexOctet() << 8) | this.readHexOctet();
+          dataAvailable -= 4;
+          // 3GPP TS 23.040 clause 9.2.3.24.4: "A receiving entity shall
+          // ignore any information element where the value of the
+          // Information-Element-Data is Reserved or not supported"
+          if ((dstp < PDU_APA_VALID_16BIT_PORTS)
+              && (orip < PDU_APA_VALID_16BIT_PORTS)) {
+            header.destinationPort = dstp;
+            header.originatorPort = orip;
+          }
+          break;
+        }
         case PDU_IEI_CONCATENATED_SHORT_MESSAGES_16BIT: {
           let ref = (this.readHexOctet() << 8) | this.readHexOctet();
           let max = this.readHexOctet();
           let seq = this.readHexOctet();
           dataAvailable -= 4;
           if (max && seq && (seq <= max)) {
             header.segmentRef = ref;
             header.segmentMaxSeq = max;