2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 var MSN = '123456789';
25 var IMEI = '123456789012345';
28 function RilAppStatus(type, state, persoState, aidPtr, appLabelPtr, pin1R, curPin1, curPin2) {
30 this.appState = state;
31 this.persoSubstate = persoState;
33 this.appLabel = appLabelPtr;
34 this.pin1Replaced = pin1R;
39 function RilCardStatus() {
40 this.cardState = CARDSTATE_PRESENT;
41 this.universalPinState = PINSTATE_UNKNOWN;
42 this.gsmUmtsSubscriptionAppIndex = 0;
43 this.cdmaSubscriptionAppIndex = CARD_MAX_APPS;
44 this.numApplications = 1;
45 this.applications = new Array(CARD_MAX_APPS);
47 // Initialize application status
48 for (i = 0; i < CARD_MAX_APPS; i++) {
49 var app = new RilAppStatus(APPTYPE_UNKNOWN, APPSTATE_UNKNOWN, PERSOSUBSTATE_UNKNOWN,
50 null, null, 0, PINSTATE_UNKNOWN, PINSTATE_UNKNOWN);
51 this.applications[i] = app;
54 // set gsm application status.
55 var gsmApp = new RilAppStatus(APPTYPE_SIM, APPSTATE_READY, PERSOSUBSTATE_READY, null, null,
56 0, PINSTATE_UNKNOWN, PINSTATE_UNKNOWN);
57 this.applications[this.gsmUmtsSubscriptionAppIndex] = gsmApp;
60 var cardStatus = new RilCardStatus();
62 // The result returned by the request handlers
63 var result = new Object();
65 this.rilRequestGetSimStatus = function(req) { // 1
66 print('Icc: rilRequestGetSimStatus');
68 var rsp = new Object();
69 rsp.cardStatus = cardStatus;
71 result.responseProtobuf = rilSchema[packageNameAndSeperator +
72 'RspGetSimStatus'].serialize(rsp);
76 this.rilRequestEnterSimPin = function(req) { // 2
77 print('Icc: rilRequestEnterSimPin req.data.pin=' + req.data.pin);
79 var rsp = new Object();
80 rsp.retriesRemaining = 3;
81 result.responseProtobuf = rilSchema[packageNameAndSeperator +
82 'RspEnterSimPin'].serialize(rsp);
86 this.rilRequestGetImsi = function(req) { // 11
87 print('Icc: rilRequestGetImsi');
89 var rsp = new Object();
90 rsp.strings = new Array();
91 rsp.strings[0] = MCC + MNC + MSN;
92 result.responseProtobuf = rilSchema[packageNameAndSeperator +
93 'RspStrings'].serialize(rsp);
97 this.rilRequestOperator = function(req) { // 22
98 print('Icc: rilRequestOperator');
100 var rsp = new Object();
101 rsp.longAlphaOns = 'Mock-Ril long Alpha Ons';
102 rsp.shortAlphaOns = 'Mock-Ril';
103 rsp.mccMnc = MCC + MNC;
104 result.responseProtobuf = rilSchema[packageNameAndSeperator +
105 'RspOperator'].serialize(rsp);
109 this.rilRequestGetImei = function(req) { // 38
110 print('Icc: rilRequestGetImei');
112 var rsp = new Object();
113 rsp.strings = new Array();
114 rsp.strings[0] = IMEI;
115 result.responseProtobuf = rilSchema[packageNameAndSeperator +
116 'RspStrings'].serialize(rsp);
120 this.rilRequestGetImeisv = function(req) { // 39
121 print('Icc: rilRequestGetImeisv');
123 var rsp = new Object();
124 rsp.strings = new Array();
125 rsp.strings[0] = IMEISV;
126 result.responseProtobuf = rilSchema[packageNameAndSeperator +
127 'RspStrings'].serialize(rsp);
132 * Process the request
134 this.process = function(req) {
136 // print('Icc E: req.reqNum=' + req.reqNum + ' req.token=' + req.token);
138 // Assume the result will be true, successful and nothing to return
139 result.sendResponse = true;
140 result.rilErrCode = RIL_E_SUCCESS;
141 result.responseProtobuf = emptyProtobuf;
144 result = (this.simDispatchTable[req.reqNum]).call(this, req);
146 print('Icc: Unknown reqNum=' + req.reqNum);
147 result.rilErrCode = RIL_E_REQUEST_NOT_SUPPORTED;
150 if (result.sendResponse) {
151 sendRilRequestComplete(result.rilErrCode, req.reqNum,
152 req.token, result.responseProtobuf);
155 // print('Icc X: req.reqNum=' + req.reqNum + ' req.token=' + req.token);
157 print('Icc X: Exception req.reqNum=' +
158 req.reqNum + ' req.token=' + req.token + ' err=' + err);
162 print('Icc: constructor E');
163 this.simDispatchTable = new Array();
164 this.simDispatchTable[RIL_REQUEST_GET_SIM_STATUS] = this.rilRequestGetSimStatus; // 1
165 this.simDispatchTable[RIL_REQUEST_ENTER_SIM_PIN] = this.rilRequestEnterSimPin; // 2
166 this.simDispatchTable[RIL_REQUEST_GET_IMSI] = this.rilRequestGetImsi; // 11
167 this.simDispatchTable[RIL_REQUEST_OPERATOR] = this.rilRequestOperator; // 22
168 this.simDispatchTable[RIL_REQUEST_GET_IMEI] = this.rilRequestGetImei; // 38
169 this.simDispatchTable[RIL_REQUEST_GET_IMEISV] = this.rilRequestGetImeisv; // 39
170 print('Icc: constructor X');
173 // The simulated sim instance and its associated Worker
174 var simulatedIcc = new Icc();
175 var simulatedIccWorker = new Worker(function (req) {
176 simulatedIcc.process(req);
178 simulatedIccWorker.run();
184 include("simulated_icc_tests.js");