• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (C) 2010 The Android Open Source Project
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17/**
18 * Simulated Icc
19 */
20function Icc() {
21
22    var MCC = '310';
23    var MNC = '260';
24    var MSN = '123456789';
25    var IMEI = '123456789012345';
26    var IMEISV = '00';
27
28    function RilAppStatus(type, state, persoState, aidPtr, appLabelPtr, pin1R, curPin1, curPin2) {
29        this.appType = type;
30        this.appState = state;
31        this.persoSubstate = persoState;
32        this.aid = aidPtr;
33        this.appLabel = appLabelPtr;
34        this.pin1Replaced = pin1R;
35        this.pin1 = curPin1;
36        this.pint2 = curPin2;
37    }
38
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.imsSubscriptionAppIndex = CARD_MAX_APPS;
45        this.numApplications = 1;
46        this.applications = new Array(CARD_MAX_APPS);
47
48        // Initialize application status
49        for (i = 0; i < CARD_MAX_APPS; i++) {
50            var app = new RilAppStatus(APPTYPE_UNKNOWN, APPSTATE_UNKNOWN, PERSOSUBSTATE_UNKNOWN,
51                                       null, null, 0, PINSTATE_UNKNOWN, PINSTATE_UNKNOWN);
52            this.applications[i] = app;
53        }
54
55        // set gsm application status.
56        var gsmApp = new RilAppStatus(APPTYPE_SIM, APPSTATE_READY, PERSOSUBSTATE_READY, null, null,
57                                     0, PINSTATE_UNKNOWN, PINSTATE_UNKNOWN);
58        this.applications[this.gsmUmtsSubscriptionAppIndex] = gsmApp;
59    }
60
61    var cardStatus = new RilCardStatus();
62
63    // The result returned by the request handlers
64    var result = new Object();
65
66    this.rilRequestGetSimStatus = function(req) { // 1
67        print('Icc: rilRequestGetSimStatus');
68
69        var rsp = new Object();
70        rsp.cardStatus = cardStatus;
71
72        result.responseProtobuf = rilSchema[packageNameAndSeperator +
73                                 'RspGetSimStatus'].serialize(rsp);
74        return result;
75    }
76
77    this.rilRequestEnterSimPin = function(req) { // 2
78        print('Icc: rilRequestEnterSimPin req.data.pin=' + req.data.pin);
79
80        var rsp = new Object();
81        rsp.retriesRemaining = 3;
82        result.responseProtobuf = rilSchema[packageNameAndSeperator +
83                                 'RspEnterSimPin'].serialize(rsp);
84        return result;
85    }
86
87    this.rilRequestGetImsi = function(req) { // 11
88        print('Icc: rilRequestGetImsi');
89
90        var rsp = new Object();
91        rsp.strings = new Array();
92        rsp.strings[0] = MCC + MNC + MSN;
93        result.responseProtobuf = rilSchema[packageNameAndSeperator +
94                                 'RspStrings'].serialize(rsp);
95        return result;
96    }
97
98    this.rilRequestOperator = function(req) { // 22
99        print('Icc: rilRequestOperator');
100
101        var rsp = new Object();
102        rsp.longAlphaOns = 'Mock-Ril long Alpha Ons';
103        rsp.shortAlphaOns = 'Mock-Ril';
104        rsp.mccMnc = MCC + MNC;
105        result.responseProtobuf = rilSchema[packageNameAndSeperator +
106                                 'RspOperator'].serialize(rsp);
107        return result;
108    }
109
110    this.rilRequestGetImei = function(req) { // 38
111        print('Icc: rilRequestGetImei');
112
113        var rsp = new Object();
114        rsp.strings = new Array();
115        rsp.strings[0] = IMEI;
116        result.responseProtobuf = rilSchema[packageNameAndSeperator +
117                                 'RspStrings'].serialize(rsp);
118        return result;
119    }
120
121    this.rilRequestGetImeisv = function(req) { // 39
122        print('Icc: rilRequestGetImeisv');
123
124        var rsp = new Object();
125        rsp.strings = new Array();
126        rsp.strings[0] = IMEISV;
127        result.responseProtobuf = rilSchema[packageNameAndSeperator +
128                                 'RspStrings'].serialize(rsp);
129        return result;
130    }
131
132    /**
133     * Process the request
134     */
135    this.process = function(req) {
136        try {
137            // print('Icc E: req.reqNum=' + req.reqNum + ' req.token=' + req.token);
138
139            // Assume the result will be true, successful and nothing to return
140            result.sendResponse = true;
141            result.rilErrCode = RIL_E_SUCCESS;
142            result.responseProtobuf = emptyProtobuf;
143
144            try {
145                result = (this.simDispatchTable[req.reqNum]).call(this, req);
146            } catch (err) {
147                print('Icc: Unknown reqNum=' + req.reqNum);
148                result.rilErrCode = RIL_E_REQUEST_NOT_SUPPORTED;
149            }
150
151            if (result.sendResponse) {
152                sendRilRequestComplete(result.rilErrCode, req.reqNum,
153                        req.token, result.responseProtobuf);
154            }
155
156            // print('Icc X: req.reqNum=' + req.reqNum + ' req.token=' + req.token);
157        } catch (err) {
158            print('Icc X: Exception req.reqNum=' +
159                    req.reqNum + ' req.token=' + req.token + ' err=' + err);
160        }
161    }
162
163    print('Icc: constructor E');
164    this.simDispatchTable = new Array();
165    this.simDispatchTable[RIL_REQUEST_GET_SIM_STATUS] = this.rilRequestGetSimStatus; // 1
166    this.simDispatchTable[RIL_REQUEST_ENTER_SIM_PIN] = this.rilRequestEnterSimPin; // 2
167    this.simDispatchTable[RIL_REQUEST_GET_IMSI] = this.rilRequestGetImsi; // 11
168    this.simDispatchTable[RIL_REQUEST_OPERATOR] = this.rilRequestOperator; // 22
169    this.simDispatchTable[RIL_REQUEST_GET_IMEI] = this.rilRequestGetImei; // 38
170    this.simDispatchTable[RIL_REQUEST_GET_IMEISV] = this.rilRequestGetImeisv; // 39
171    print('Icc: constructor X');
172}
173
174// The simulated sim instance and its associated Worker
175var simulatedIcc = new Icc();
176var simulatedIccWorker = new Worker(function (req) {
177    simulatedIcc.process(req);
178});
179simulatedIccWorker.run();
180
181/**
182 * Optional tests
183 */
184if (false) {
185    include("simulated_icc_tests.js");
186}
187