Bug 793137 - Part 2: Support PLAY_TONE, POLL_INTERVAL and REFRESH in RIL. r=philikon
authorYoshi Huang <allstars.chh@mozilla.com>
Fri, 21 Sep 2012 15:01:58 +0800
changeset 108711 e60e324d1fa3a8ebcf90d59d558add9516e5326b
parent 108710 b4d33b66bfba37f5d1bfd79b9bef15c314df2eeb
child 108712 bf8b676ae8d242cdf3feb83130f57c6dfdc5fa01
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersphilikon
bugs793137
milestone18.0a1
Bug 793137 - Part 2: Support PLAY_TONE, POLL_INTERVAL and REFRESH in RIL. r=philikon
dom/system/gonk/ril_consts.js
dom/system/gonk/ril_worker.js
--- a/dom/system/gonk/ril_consts.js
+++ b/dom/system/gonk/ril_consts.js
@@ -532,19 +532,21 @@ const COMPREHENSIONTLV_FLAG_CR = 0x80;  
 const COMPREHENSIONTLV_TAG_COMMAND_DETAILS = 0x01;
 const COMPREHENSIONTLV_TAG_DEVICE_ID = 0x02;
 const COMPREHENSIONTLV_TAG_RESULT = 0x03;
 const COMPREHENSIONTLV_TAG_DURATION = 0x04;
 const COMPREHENSIONTLV_TAG_ALPHA_ID = 0x05;
 const COMPREHENSIONTLV_TAG_ADDRESS = 0x06;
 const COMPREHENSIONTLV_TAG_SMS_TPDU = 0x0b;
 const COMPREHENSIONTLV_TAG_TEXT_STRING = 0x0d;
+const COMPREHENSIONTLV_TAG_TONE = 0x0e;
 const COMPREHENSIONTLV_TAG_ITEM = 0x0f;
 const COMPREHENSIONTLV_TAG_ITEM_ID = 0x10;
 const COMPREHENSIONTLV_TAG_RESPONSE_LENGTH = 0x11;
+const COMPREHENSIONTLV_TAG_FILE_LIST = 0x12;
 const COMPREHENSIONTLV_TAG_LOCATION_INFO = 0x13;
 const COMPREHENSIONTLV_TAG_HELP_REQUEST = 0x15;
 const COMPREHENSIONTLV_TAG_DEFAULT_TEXT = 0x17;
 const COMPREHENSIONTLV_TAG_LOCATION_STATUS = 0x1b;
 const COMPREHENSIONTLV_TAG_EVENT_LIST = 0x19;
 const COMPREHENSIONTLV_TAG_ICON_ID = 0x1e;
 const COMPREHENSIONTLV_TAG_ICON_ID_LIST = 0x1f;
 const COMPREHENSIONTLV_TAG_IMMEDIATE_RESPONSE = 0x2b;
@@ -555,23 +557,26 @@ const STK_DEVICE_ID_KEYPAD = 0x01;
 const STK_DEVICE_ID_DISPLAY = 0x02;
 const STK_DEVICE_ID_EARPIECE = 0x03;
 const STK_DEVICE_ID_SIM = 0x81;
 const STK_DEVICE_ID_ME = 0x82;
 const STK_DEVICE_ID_NETWORK = 0x83;
 
 // STK Proactive commands.
 const STK_CMD_REFRESH = 0x01;
+const STK_CMD_POLL_INTERVAL = 0x03;
+const STK_CMD_POLL_OFF = 0x04;
 const STK_CMD_SET_UP_EVENT_LIST = 0x05;
 const STK_CMD_SET_UP_CALL = 0x10;
 const STK_CMD_SEND_SS = 0x11;
 const STK_CMD_SEND_USSD = 0x12;
 const STK_CMD_SEND_SMS = 0x13;
 const STK_CMD_SEND_DTMF = 0x14;
 const STK_CMD_LAUNCH_BROWSER = 0x15;
+const STK_CMD_PLAY_TONE = 0x20;
 const STK_CMD_DISPLAY_TEXT = 0x21;
 const STK_CMD_GET_INKEY = 0x22;
 const STK_CMD_GET_INPUT = 0x23;
 const STK_CMD_SELECT_ITEM = 0x24;
 const STK_CMD_SET_UP_MENU = 0x25;
 const STK_CMD_SET_UP_IDLE_MODE_TEXT = 0x28;
 
 // STK Result code.
@@ -727,16 +732,41 @@ const STK_EVENT_TYPE_LOCAL_CONNECTION = 
 const STK_EVENT_TYPE_NETWORK_SEARCH_MODE_CHANGED = 0x0e;
 const STK_EVENT_TYPE_BROWSING_STATUS = 0x0f;
 
 // STK Service state of Location Status.
 const STK_SERVICE_STATE_NORMAL      = 0x00;
 const STK_SERVICE_STATE_LIMITED     = 0x01;
 const STK_SERVICE_STATE_UNAVAILABLE = 0x02;
 
+// Refresh mode.
+const STK_REFRESH_NAA_INIT_AND_FULL_FILE_CHANGE = 0x00;
+const STK_REFRESH_FILE_CHANGE = 0x01;
+const STK_REFRESH_NAA_INIT_AND_FILE_CHANGE = 0x02;
+const STK_REFRESH_NAA_INIT = 0x03;
+const STK_REFRESH_UICC_RESET = 0x04;
+
+// Tone type.
+const STK_TONE_TYPE_DIAL_TONE                = 0x01;
+const STK_TONE_TYPE_CALLED_SUBSCRIBER_BUSY   = 0x02;
+const STK_TONE_TYPE_CONGESTION               = 0x03;
+const STK_TONE_TYPE_RADIO_PATH_ACK           = 0x04;
+const STK_TONE_TYPE_RADIO_PATH_NOT_AVAILABLE = 0x05;
+const STK_TONE_TYPE_ERROR                    = 0x06;
+const STK_TONE_TYPE_CALL_WAITING_TONE        = 0x07;
+const STK_TONE_TYPE_RINGING_TONE             = 0x08;
+const STK_TONE_TYPE_GENERAL_BEEP             = 0x10;
+const STK_TONE_TYPE_POSITIVE_ACK_TONE        = 0x11;
+const STK_TONE_TYPE_NEGATIVE_ACK_TONE        = 0x12;
+
+// Time unit.
+const STK_TIME_UNIT_MINUTE       = 0x00;
+const STK_TIME_UNIT_SECOND       = 0x01;
+const STK_TIME_UNIT_TENTH_SECOND = 0x02;
+
 /**
  * (U)SIM Services.
  *
  * @see 3GPP TS 51.011 10.3.7 (SIM) and 3GPP TS 31.102 4.2.8 (USIM).
  */
 const GECKO_ICC_SERVICES = {
   sim: {
     ADN: 2,
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -6069,16 +6069,25 @@ let GsmPDUHelper = {
     Buf.writeUint16(0);
   },
 };
 
 let StkCommandParamsFactory = {
   createParam: function createParam(cmdDetails, ctlvs) {
     let param;
     switch (cmdDetails.typeOfCommand) {
+      case STK_CMD_REFRESH:
+        param = this.processRefresh(cmdDetails, ctlvs);
+        break;
+      case STK_CMD_POLL_INTERVAL:
+        param = this.processPollInterval(cmdDetails, ctlvs);
+        break;
+      case STK_CMD_POLL_OFF:
+        param = this.processPollOff(cmdDetails, ctlvs);
+        break;
       case STK_CMD_SET_UP_EVENT_LIST:
         param = this.processSetUpEventList(cmdDetails, ctlvs);
         break;
       case STK_CMD_SET_UP_MENU:
       case STK_CMD_SELECT_ITEM:
         param = this.processSelectItem(cmdDetails, ctlvs);
         break;
       case STK_CMD_DISPLAY_TEXT:
@@ -6097,27 +6106,90 @@ let StkCommandParamsFactory = {
       case STK_CMD_SEND_USSD:
       case STK_CMD_SEND_SMS:
       case STK_CMD_SEND_DTMF:
         param = this.processEventNotify(cmdDetails, ctlvs);
         break;
       case STK_CMD_SET_UP_CALL:
         param = this.processSetupCall(cmdDetails, ctlvs);
         break;
-      case STK_LAUNCH_BROWSER:
+      case STK_CMD_LAUNCH_BROWSER:
         param = this.processLaunchBrowser(cmdDetails, ctlvs);
         break;
+      case STK_CMD_PLAY_TONE:
+        param = this.processPlayTone(cmdDetails, ctlvs);
+        break;
       default:
         debug("unknown proactive command");
         break;
     }
     return param;
   },
 
   /**
+   * Construct a param for Refresh.
+   *
+   * @param cmdDetails
+   *        The value object of CommandDetails TLV.
+   * @param ctlvs
+   *        The all TLVs in this proactive command.
+   */
+  processRefresh: function processRefresh(cmdDetails, ctlvs) {
+    let refreshType = cmdDetails.commandQualifier;
+    switch (refreshType) {
+      case STK_REFRESH_FILE_CHANGE:
+      case STK_REFRESH_NAA_INIT_AND_FILE_CHANGE:
+        let ctlv = StkProactiveCmdHelper.searchForTag(
+          COMPREHENSIONTLV_FILE_LIST, ctlvs);
+        if (ctlv) {
+          let list = ctlv.value.fileList;
+          if (DEBUG) {
+            debug("Refresh, list = " + list);
+          }
+          RIL.fetchICCRecords();
+        }
+        break;
+    }
+    return {};
+  },
+
+  /**
+   * Construct a param for Poll Interval.
+   *
+   * @param cmdDetails
+   *        The value object of CommandDetails TLV.
+   * @param ctlvs
+   *        The all TLVs in this proactive command.
+   */
+  processPollInterval: function processPollInterval(cmdDetails, ctlvs) {
+    let ctlv = StkProactiveCmdHelper.searchForTag(
+        COMPREHENSIONTLV_TAG_DURATION, ctlvs);
+    if (!ctlv) {
+      RIL.sendStkTerminalResponse({
+        command: cmdDetails,
+        resultCode: STK_RESULT_REQUIRED_VALUES_MISSING});
+      throw new Error("Stk Poll Interval: Required value missing : Duration");
+    }
+
+    return ctlv.value;
+  },
+
+  /**
+   * Construct a param for Poll Off.
+   *
+   * @param cmdDetails
+   *        The value object of CommandDetails TLV.
+   * @param ctlvs
+   *        The all TLVs in this proactive command.
+   */
+  processPollOff: function processPollOff(cmdDetails, ctlvs) {
+    return {};
+  },
+
+  /**
    * Construct a param for Set Up Event list.
    *
    * @param cmdDetails
    *        The value object of CommandDetails TLV.
    * @param ctlvs
    *        The all TLVs in this proactive command.
    */
   processSetUpEventList: function processSetUpEventList(cmdDetails, ctlvs) {
@@ -6372,38 +6444,70 @@ let StkCommandParamsFactory = {
     ctlv = StkProactiveCmdHelper.searchForTag(COMPREHENSIONTLV_TAG_ALPHA_ID, ctlvs)
     if (ctlv) {
       browser.confirmMessage = ctlv.value.identifier;
     }
 
     browser.mode = cmdDetails.commandQualifier & 0x03;
 
     return browser;
+  },
+
+  processPlayTone: function processPlayTone(cmdDetails, ctlvs) {
+    let playTone = {};
+
+    let ctlv = StkProactiveCmdHelper.searchForTag(
+        COMPREHENSIONTLV_TAG_ALPHA_ID, ctlvs);
+    if (ctlv) {
+      playTone.text = ctlv.value.identifier;
+    }
+
+    ctlv = StkProactiveCmdHelper.searchForTag(COMPREHENSIONTLV_TAG_TONE, ctlvs);
+    if (ctlv) {
+      playTone.tone = ctlv.value.tone;
+    }
+
+    ctlv = StkProactiveCmdHelper.searchForTag(
+        COMPREHENSIONTLV_TAG_DURATION, ctlvs);
+    if (ctlv) {
+      playTone.duration = ctlv.value;
+    }
+
+    // vibrate is only defined in TS 102.223
+    playTone.isVibrate = (cmdDetails.commandQualifier & 0x01) != 0x00;
+
+    return playTone;
   }
 };
 
 let StkProactiveCmdHelper = {
   retrieve: function retrieve(tag, length) {
     switch (tag) {
       case COMPREHENSIONTLV_TAG_COMMAND_DETAILS:
         return this.retrieveCommandDetails(length);
       case COMPREHENSIONTLV_TAG_DEVICE_ID:
         return this.retrieveDeviceId(length);
       case COMPREHENSIONTLV_TAG_ALPHA_ID:
         return this.retrieveAlphaId(length);
+      case COMPREHENSIONTLV_TAG_DURATION:
+        return this.retrieveDuration(length);
       case COMPREHENSIONTLV_TAG_ADDRESS:
         return this.retrieveAddress(length);
       case COMPREHENSIONTLV_TAG_TEXT_STRING:
         return this.retrieveTextString(length);
+      case COMPREHENSIONTLV_TAG_TONE:
+        return this.retrieveTone(length);
       case COMPREHENSIONTLV_TAG_ITEM:
         return this.retrieveItem(length);
       case COMPREHENSIONTLV_TAG_ITEM_ID:
         return this.retrieveItemId(length);
       case COMPREHENSIONTLV_TAG_RESPONSE_LENGTH:
         return this.retrieveResponseLength(length);
+      case COMPREHENSIONTLV_TAG_FILE_LIST:
+        return this.retrieveFileList(length);
       case COMPREHENSIONTLV_TAG_DEFAULT_TEXT:
         return this.retrieveDefaultText(length);
       case COMPREHENSIONTLV_TAG_EVENT_LIST:
         return this.retrieveEventList(length);
       case COMPREHENSIONTLV_TAG_IMMEDIATE_RESPONSE:
         return this.retrieveImmediaResponse(length);
       case COMPREHENSIONTLV_TAG_URL:
         return this.retrieveUrl(length);
@@ -6462,16 +6566,33 @@ let StkProactiveCmdHelper = {
   retrieveAlphaId: function retrieveAlphaId(length) {
     let alphaId = {
       identifier: GsmPDUHelper.readAlphaIdentifier(length)
     };
     return alphaId;
   },
 
   /**
+   * Duration.
+   *
+   * | Byte | Description           | Length |
+   * |  1   | Response Length Tag   |   1    |
+   * |  2   | Lenth = 02            |   1    |
+   * |  3   | Time unit             |   1    |
+   * |  4   | Time interval         |   1    |
+   */
+  retrieveDuration: function retrieveDuration(length) {
+    let duration = {
+      timeUnit: GsmPDUHelper.readHexOctet(),
+      timeInterval: GsmPDUHelper.readHexOctet(),
+    };
+    return duration;
+  },
+
+  /**
    * Address.
    *
    * | Byte         | Description            | Length |
    * |  1           | Alpha Identifier Tag   |   1    |
    * | 2 ~ (Y-1)+2  | Length (X)             |   Y    |
    * | (Y-1)+3      | TON and NPI            |   1    |
    * | (Y-1)+4 ~    | Dialling number        |   X    |
    * | (Y-1)+X+2    |                        |        |
@@ -6514,16 +6635,31 @@ let StkProactiveCmdHelper = {
       case STK_TEXT_CODING_UCS2:
         text.textString = GsmPDUHelper.readUCS2String(length);
         break;
     }
     return text;
   },
 
   /**
+   * Tone.
+   *
+   * | Byte | Description     | Length |
+   * |  1   | Tone Tag        |   1    |
+   * |  2   | Lenth = 01      |   1    |
+   * |  3   | Tone            |   1    |
+   */
+  retrieveTone: function retrieveTone(length) {
+    let tone = {
+      tone: GsmPDUHelper.readHexOctet(),
+    };
+    return tone;
+  },
+
+  /**
    * Item.
    *
    * | Byte         | Description            | Length |
    * |  1           | Item Tag               |   1    |
    * | 2 ~ (Y-1)+2  | Length (X)             |   Y    |
    * | (Y-1)+3      | Identifier of item     |   1    |
    * | (Y-1)+4 ~    | Text string of item    |   X    |
    * | (Y-1)+X+2    |                        |        |
@@ -6564,16 +6700,40 @@ let StkProactiveCmdHelper = {
     let rspLength = {
       minLength : GsmPDUHelper.readHexOctet(),
       maxLength : GsmPDUHelper.readHexOctet()
     };
     return rspLength;
   },
 
   /**
+   * File List.
+   *
+   * | Byte         | Description            | Length |
+   * |  1           | File List Tag          |   1    |
+   * | 2 ~ (Y-1)+2  | Length (X)             |   Y    |
+   * | (Y-1)+3      | Number of files        |   1    |
+   * | (Y-1)+4 ~    | Files                  |   X    |
+   * | (Y-1)+X+2    |                        |        |
+   */
+  retrieveFileList: function retrieveFileList(length) {
+    let num = GsmPDUHelper.readHexOctet();
+    let fileList = "";
+    length--; // -1 for the num octet.
+    for (let i = 0; i < 2 * length; i++) {
+      // Didn't use readHexOctet here,
+      // otherwise 0x00 will be "0", not "00"
+      fileList += String.fromCharCode(Buf.readUint16());
+    }
+    return {
+      fileList: fileList
+    };
+  },
+
+  /**
    * Default Text.
    *
    * Same as Text String.
    */
   retrieveDefaultText: function retrieveDefaultText(length) {
     return this.retrieveTextString(length);
   },