Bug 785095 - B2G RIL - Error fetching records for ICC cards with RIL_APPTYPE_SIM = 1. r=philikon
authorJose Antonio Olivera Ortega <josea.olivera@gmail.com>
Tue, 28 Aug 2012 20:05:34 +0200
changeset 105741 020c834a8991eb38904817fd64e3089f03d236a4
parent 105740 1f93692fea1ebc066e7df9119da5d8f5d16d3565
child 105742 30c7ffa7bd97ca5709edeb0567ba9868714233dd
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersphilikon
bugs785095
milestone18.0a1
Bug 785095 - B2G RIL - Error fetching records for ICC cards with RIL_APPTYPE_SIM = 1. r=philikon
dom/system/gonk/ril_worker.js
--- a/dom/system/gonk/ril_worker.js
+++ b/dom/system/gonk/ril_worker.js
@@ -1095,17 +1095,17 @@ let RIL = {
       if (this.iccInfo.msisdn) {
         this._handleICCInfoChange();
       }
     }
 
     this.iccIO({
       command:   ICC_COMMAND_GET_RESPONSE,
       fileId:    ICC_EF_MSISDN,
-      pathId:    EF_PATH_MF_SIM + EF_PATH_ADF_USIM,
+      pathId:    this._getPathIdForICCRecord(ICC_EF_MSISDN),
       p1:        0, // For GET_RESPONSE, p1 = 0
       p2:        0, // For GET_RESPONSE, p2 = 0
       p3:        GET_RESPONSE_EF_SIZE_BYTES,
       data:      null,
       pin2:      null,
       type:      EF_TYPE_LINEAR_FIXED,
       callback:  callback,
     });
@@ -1138,17 +1138,17 @@ let RIL = {
         if (DEBUG) debug("MCC: " + this.iccInfo.mcc + " MNC: " + this.iccInfo.mnc);
         this._handleICCInfoChange();
       }
     }
 
     this.iccIO({
       command:   ICC_COMMAND_GET_RESPONSE,
       fileId:    ICC_EF_AD,
-      pathId:    EF_PATH_MF_SIM + EF_PATH_ADF_USIM,
+      pathId:    this._getPathIdForICCRecord(ICC_EF_AD),
       p1:        0, // For GET_RESPONSE, p1 = 0
       p2:        0, // For GET_RESPONSE, p2 = 0
       p3:        GET_RESPONSE_EF_SIZE_BYTES,
       data:      null,
       pin2:      null,
       type:      EF_TYPE_TRANSPARENT,
       callback:  callback,
     });
@@ -1190,17 +1190,17 @@ let RIL = {
         }
         debug("UST: " + str);
       }
     }
 
     this.iccIO({
       command:   ICC_COMMAND_GET_RESPONSE,
       fileId:    ICC_EF_UST,
-      pathId:    EF_PATH_MF_SIM + EF_PATH_ADF_USIM,
+      pathId:    this._getPathIdForICCRecord(ICC_EF_UST),
       p1:        0, // For GET_RESPONSE, p1 = 0
       p2:        0, // For GET_RESPONSE, p2 = 0
       p3:        GET_RESPONSE_EF_SIZE_BYTES,
       data:      null,
       pin2:      null,
       type:      EF_TYPE_TRANSPARENT,
       callback:  callback,
     });
@@ -1288,17 +1288,17 @@ let RIL = {
       };
       this.parseDiallingNumber(options, add, finish);
     }
     
     this.iccInfo.fdn = [];
     this.iccIO({
       command:   ICC_COMMAND_GET_RESPONSE,
       fileId:    ICC_EF_FDN,
-      pathId:    EF_PATH_MF_SIM + EF_PATH_DF_TELECOM,
+      pathId:    this._getPathIdForICCRecord(ICC_EF_FDN),
       p1:        0, // For GET_RESPONSE, p1 = 0
       p2:        0, // For GET_RESPONSE, p2 = 0
       p3:        GET_RESPONSE_EF_SIZE_BYTES,
       data:      null,
       pin2:      null,
       type:      EF_TYPE_LINEAR_FIXED,
       callback:  callback,
       loadAll:   true,
@@ -1333,17 +1333,17 @@ let RIL = {
       };
       this.parseDiallingNumber(options, add, finish);
     }
 
     this.iccInfo.adn = [];
     this.iccIO({
       command:   ICC_COMMAND_GET_RESPONSE,
       fileId:    options.fileId,
-      pathId:    EF_PATH_MF_SIM + EF_PATH_DF_TELECOM + EF_PATH_DF_PHONEBOOK,
+      pathId:    this._getPathIdForICCRecord(options.fileId),
       p1:        0, // For GET_RESPONSE, p1 = 0
       p2:        0, // For GET_RESPONSE, p2 = 0
       p3:        GET_RESPONSE_EF_SIZE_BYTES,
       data:      null,
       pin2:      null,
       type:      EF_TYPE_LINEAR_FIXED,
       callback:  callback,
       loadAll:   true,
@@ -1370,17 +1370,17 @@ let RIL = {
       };
 
       this.parseDiallingNumber(options, parseCallback);
     }
 
     this.iccIO({
       command:   ICC_COMMAND_GET_RESPONSE,
       fileId:    ICC_EF_MBDN,
-      pathId:    EF_PATH_MF_SIM + EF_PATH_ADF_USIM,
+      pathId:    this._getPathIdForICCRecord(ICC_EF_MBDN),
       p1:        0, // For GET_RESPONSE, p1 = 0
       p2:        0, // For GET_RESPONSE, p2 = 0
       p3:        GET_RESPONSE_EF_SIZE_BYTES,
       data:      null,
       pin2:      null,
       type:      EF_TYPE_LINEAR_FIXED,
       callback:  callback,
     });
@@ -1430,17 +1430,17 @@ let RIL = {
                    requestId: options.requestId});
 
       Buf.readStringDelimiter(bufLen);
     }
 
     this.iccIO({
       command:   ICC_COMMAND_GET_RESPONSE,
       fileId:    ICC_EF_PBR,
-      pathId:    EF_PATH_MF_SIM + EF_PATH_DF_TELECOM + EF_PATH_DF_PHONEBOOK,
+      pathId:    this._getPathIdForICCRecord(ICC_EF_PBR),
       p1:        0, // For GET_RESPONSE, p1 = 0
       p2:        0, // For GET_RESPONSE, p2 = 0
       p3:        GET_RESPONSE_EF_SIZE_BYTES,
       data:      null,
       pin2:      null,
       type:      EF_TYPE_LINEAR_FIXED,
       callback:  callback,
       requestId: options.requestId,
@@ -2025,16 +2025,71 @@ let RIL = {
       this.fetchICCRecords();
     }
 
     this.cardState = newCardState;
     this.sendDOMMessage({rilMessageType: "cardstatechange",
                          cardState: this.cardState});
   },
 
+  /** 
+   * Helper function for getting the pathId for the specific ICC record
+   * depeding on which type of ICC card we are using.
+   * 
+   * @param fileId
+   *        File id.
+   * @return The pathId or null in case of an error or invalid input.
+   */
+  _getPathIdForICCRecord: function _getPathIdForICCRecord(fileId) {
+    let index = this.iccStatus.gsmUmtsSubscriptionAppIndex;
+    if (index == -1) {
+      return null;
+    }
+    let app = this.iccStatus.apps[index];
+    if (!app) {
+      return null;
+    }
+
+    switch (app.app_type) {
+      case CARD_APPTYPE_SIM:
+        switch (fileId) {
+          case ICC_EF_ADN:
+          case ICC_EF_FDN:
+          case ICC_EF_MSISDN:
+            return EF_PATH_MF_SIM + EF_PATH_DF_TELECOM;
+
+          case ICC_EF_AD:
+          case ICC_EF_MBDN:
+          case ICC_EF_UST:
+            return EF_PATH_MF_SIM + EF_PATH_DF_GSM;
+          case ICC_EF_PBR:
+            return EF_PATH_MF_SIM + EF_PATH_DF_TELECOM + EF_PATH_DF_PHONEBOOK;
+        }
+      case CARD_APPTYPE_USIM:
+        switch (fileId) {
+          case ICC_EF_AD:
+          case ICC_EF_MBDN:
+          case ICC_EF_UST:
+          case ICC_EF_MSISDN:
+            return EF_PATH_MF_SIM + EF_PATH_ADF_USIM;
+          case ICC_EF_ADN:
+          case ICC_EF_FDN:
+            return EF_PATH_MF_SIM + EF_PATH_DF_TELECOM;
+          case ICC_EF_PBR:
+            return EF_PATH_MF_SIM + EF_PATH_DF_TELECOM + EF_PATH_DF_PHONEBOOK;
+          default:
+            // The file ids in USIM phone book entries are decided by the
+	    // card manufacturer. So if we don't match any of the cases
+	    // above and if its a USIM return the phone book path.
+            return EF_PATH_MF_SIM + EF_PATH_DF_TELECOM + EF_PATH_DF_PHONEBOOK;
+        }
+    }
+    return null;
+  },
+
    /**
    * Helper for processing responses of functions such as enterICC* and changeICC*.
    */
   _processEnterAndChangeICCResponses: function _processEnterAndChangeICCResponses(length, options) {
     options.success = options.rilRequestError == 0;
     if (!options.success) {
       options.errorMsg = RIL_ERROR_TO_GECKO_ERROR[options.rilRequestError];
     }