1*062a843bSAndroid Build Coastguard Worker /*
2*062a843bSAndroid Build Coastguard Worker * Copyright (c) 2016 The Android Open Source Project
3*062a843bSAndroid Build Coastguard Worker *
4*062a843bSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*062a843bSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*062a843bSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*062a843bSAndroid Build Coastguard Worker *
8*062a843bSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*062a843bSAndroid Build Coastguard Worker *
10*062a843bSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*062a843bSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*062a843bSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*062a843bSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*062a843bSAndroid Build Coastguard Worker * limitations under the License.
15*062a843bSAndroid Build Coastguard Worker */
16*062a843bSAndroid Build Coastguard Worker
17*062a843bSAndroid Build Coastguard Worker #define LOG_TAG "RIL_SAP"
18*062a843bSAndroid Build Coastguard Worker
19*062a843bSAndroid Build Coastguard Worker #include <android/hardware/radio/1.1/ISap.h>
20*062a843bSAndroid Build Coastguard Worker
21*062a843bSAndroid Build Coastguard Worker #include <hwbinder/IPCThreadState.h>
22*062a843bSAndroid Build Coastguard Worker #include <hwbinder/ProcessState.h>
23*062a843bSAndroid Build Coastguard Worker #include <sap_service.h>
24*062a843bSAndroid Build Coastguard Worker #include "pb_decode.h"
25*062a843bSAndroid Build Coastguard Worker #include "pb_encode.h"
26*062a843bSAndroid Build Coastguard Worker
27*062a843bSAndroid Build Coastguard Worker using namespace android::hardware::radio::V1_0;
28*062a843bSAndroid Build Coastguard Worker using ::android::hardware::Return;
29*062a843bSAndroid Build Coastguard Worker using ::android::hardware::hidl_vec;
30*062a843bSAndroid Build Coastguard Worker using ::android::hardware::hidl_array;
31*062a843bSAndroid Build Coastguard Worker using ::android::hardware::Void;
32*062a843bSAndroid Build Coastguard Worker using android::CommandInfo;
33*062a843bSAndroid Build Coastguard Worker using android::RequestInfo;
34*062a843bSAndroid Build Coastguard Worker using android::requestToString;
35*062a843bSAndroid Build Coastguard Worker using android::sp;
36*062a843bSAndroid Build Coastguard Worker
37*062a843bSAndroid Build Coastguard Worker struct SapImpl;
38*062a843bSAndroid Build Coastguard Worker
39*062a843bSAndroid Build Coastguard Worker #if (SIM_COUNT >= 2)
40*062a843bSAndroid Build Coastguard Worker sp<SapImpl> sapService[SIM_COUNT];
41*062a843bSAndroid Build Coastguard Worker #else
42*062a843bSAndroid Build Coastguard Worker sp<SapImpl> sapService[1];
43*062a843bSAndroid Build Coastguard Worker #endif
44*062a843bSAndroid Build Coastguard Worker
45*062a843bSAndroid Build Coastguard Worker struct SapImpl : public android::hardware::radio::V1_1::ISap {
46*062a843bSAndroid Build Coastguard Worker int32_t slotId;
47*062a843bSAndroid Build Coastguard Worker sp<ISapCallback> sapCallback;
48*062a843bSAndroid Build Coastguard Worker RIL_SOCKET_ID rilSocketId;
49*062a843bSAndroid Build Coastguard Worker
50*062a843bSAndroid Build Coastguard Worker Return<void> setCallback(const ::android::sp<ISapCallback>& sapCallbackParam);
51*062a843bSAndroid Build Coastguard Worker
52*062a843bSAndroid Build Coastguard Worker Return<void> connectReq(int32_t token, int32_t maxMsgSize);
53*062a843bSAndroid Build Coastguard Worker
54*062a843bSAndroid Build Coastguard Worker Return<void> disconnectReq(int32_t token);
55*062a843bSAndroid Build Coastguard Worker
56*062a843bSAndroid Build Coastguard Worker Return<void> apduReq(int32_t token, SapApduType type, const hidl_vec<uint8_t>& command);
57*062a843bSAndroid Build Coastguard Worker
58*062a843bSAndroid Build Coastguard Worker Return<void> transferAtrReq(int32_t token);
59*062a843bSAndroid Build Coastguard Worker
60*062a843bSAndroid Build Coastguard Worker Return<void> powerReq(int32_t token, bool state);
61*062a843bSAndroid Build Coastguard Worker
62*062a843bSAndroid Build Coastguard Worker Return<void> resetSimReq(int32_t token);
63*062a843bSAndroid Build Coastguard Worker
64*062a843bSAndroid Build Coastguard Worker Return<void> transferCardReaderStatusReq(int32_t token);
65*062a843bSAndroid Build Coastguard Worker
66*062a843bSAndroid Build Coastguard Worker Return<void> setTransferProtocolReq(int32_t token, SapTransferProtocol transferProtocol);
67*062a843bSAndroid Build Coastguard Worker
68*062a843bSAndroid Build Coastguard Worker MsgHeader* createMsgHeader(MsgId msgId, int32_t token);
69*062a843bSAndroid Build Coastguard Worker
70*062a843bSAndroid Build Coastguard Worker Return<void> addPayloadAndDispatchRequest(MsgHeader *msg, uint16_t reqLen, uint8_t *reqPtr);
71*062a843bSAndroid Build Coastguard Worker
72*062a843bSAndroid Build Coastguard Worker void sendFailedResponse(MsgId msgId, int32_t token, int numPointers, ...);
73*062a843bSAndroid Build Coastguard Worker
74*062a843bSAndroid Build Coastguard Worker void checkReturnStatus(Return<void>& ret);
75*062a843bSAndroid Build Coastguard Worker };
76*062a843bSAndroid Build Coastguard Worker
checkReturnStatus(Return<void> & ret)77*062a843bSAndroid Build Coastguard Worker void SapImpl::checkReturnStatus(Return<void>& ret) {
78*062a843bSAndroid Build Coastguard Worker if (ret.isOk() == false) {
79*062a843bSAndroid Build Coastguard Worker RLOGE("checkReturnStatus: unable to call response/indication callback: %s",
80*062a843bSAndroid Build Coastguard Worker ret.description().c_str());
81*062a843bSAndroid Build Coastguard Worker // Remote process (SapRilReceiver.java) hosting the callback must be dead. Reset the
82*062a843bSAndroid Build Coastguard Worker // callback object; there's no other recovery to be done here. When the client process is
83*062a843bSAndroid Build Coastguard Worker // back up, it will call setCallback()
84*062a843bSAndroid Build Coastguard Worker sapCallback = NULL;
85*062a843bSAndroid Build Coastguard Worker }
86*062a843bSAndroid Build Coastguard Worker }
87*062a843bSAndroid Build Coastguard Worker
setCallback(const::android::sp<ISapCallback> & sapCallbackParam)88*062a843bSAndroid Build Coastguard Worker Return<void> SapImpl::setCallback(const ::android::sp<ISapCallback>& sapCallbackParam) {
89*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::setCallback for slotId %d", slotId);
90*062a843bSAndroid Build Coastguard Worker sapCallback = sapCallbackParam;
91*062a843bSAndroid Build Coastguard Worker return Void();
92*062a843bSAndroid Build Coastguard Worker }
93*062a843bSAndroid Build Coastguard Worker
createMsgHeader(MsgId msgId,int32_t token)94*062a843bSAndroid Build Coastguard Worker MsgHeader* SapImpl::createMsgHeader(MsgId msgId, int32_t token) {
95*062a843bSAndroid Build Coastguard Worker // Memory for msg will be freed by RilSapSocket::onRequestComplete()
96*062a843bSAndroid Build Coastguard Worker MsgHeader *msg = (MsgHeader *)calloc(1, sizeof(MsgHeader));
97*062a843bSAndroid Build Coastguard Worker if (msg == NULL) {
98*062a843bSAndroid Build Coastguard Worker return NULL;
99*062a843bSAndroid Build Coastguard Worker }
100*062a843bSAndroid Build Coastguard Worker msg->token = token;
101*062a843bSAndroid Build Coastguard Worker msg->type = MsgType_REQUEST;
102*062a843bSAndroid Build Coastguard Worker msg->id = msgId;
103*062a843bSAndroid Build Coastguard Worker msg->error = Error_RIL_E_SUCCESS;
104*062a843bSAndroid Build Coastguard Worker return msg;
105*062a843bSAndroid Build Coastguard Worker }
106*062a843bSAndroid Build Coastguard Worker
addPayloadAndDispatchRequest(MsgHeader * msg,uint16_t reqLen,uint8_t * reqPtr)107*062a843bSAndroid Build Coastguard Worker Return<void> SapImpl::addPayloadAndDispatchRequest(MsgHeader *msg, uint16_t reqLen,
108*062a843bSAndroid Build Coastguard Worker uint8_t *reqPtr) {
109*062a843bSAndroid Build Coastguard Worker pb_bytes_array_t *payload = (pb_bytes_array_t *) malloc(sizeof(pb_bytes_array_t) - 1 + reqLen);
110*062a843bSAndroid Build Coastguard Worker if (payload == NULL) {
111*062a843bSAndroid Build Coastguard Worker sendFailedResponse(msg->id, msg->token, 2, reqPtr, msg);
112*062a843bSAndroid Build Coastguard Worker return Void();
113*062a843bSAndroid Build Coastguard Worker }
114*062a843bSAndroid Build Coastguard Worker
115*062a843bSAndroid Build Coastguard Worker msg->payload = payload;
116*062a843bSAndroid Build Coastguard Worker msg->payload->size = reqLen;
117*062a843bSAndroid Build Coastguard Worker memcpy(msg->payload->bytes, reqPtr, reqLen);
118*062a843bSAndroid Build Coastguard Worker
119*062a843bSAndroid Build Coastguard Worker RilSapSocket *sapSocket = RilSapSocket::getSocketById(rilSocketId);
120*062a843bSAndroid Build Coastguard Worker if (sapSocket) {
121*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::addPayloadAndDispatchRequest: calling dispatchRequest");
122*062a843bSAndroid Build Coastguard Worker sapSocket->dispatchRequest(msg);
123*062a843bSAndroid Build Coastguard Worker } else {
124*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::addPayloadAndDispatchRequest: sapSocket is null");
125*062a843bSAndroid Build Coastguard Worker sendFailedResponse(msg->id, msg->token, 3, payload, reqPtr, msg);
126*062a843bSAndroid Build Coastguard Worker return Void();
127*062a843bSAndroid Build Coastguard Worker }
128*062a843bSAndroid Build Coastguard Worker free(msg->payload);
129*062a843bSAndroid Build Coastguard Worker free(reqPtr);
130*062a843bSAndroid Build Coastguard Worker return Void();
131*062a843bSAndroid Build Coastguard Worker }
132*062a843bSAndroid Build Coastguard Worker
sendFailedResponse(MsgId msgId,int32_t token,int numPointers,...)133*062a843bSAndroid Build Coastguard Worker void SapImpl::sendFailedResponse(MsgId msgId, int32_t token, int numPointers, ...) {
134*062a843bSAndroid Build Coastguard Worker va_list ap;
135*062a843bSAndroid Build Coastguard Worker va_start(ap, numPointers);
136*062a843bSAndroid Build Coastguard Worker for (int i = 0; i < numPointers; i++) {
137*062a843bSAndroid Build Coastguard Worker void *ptr = va_arg(ap, void *);
138*062a843bSAndroid Build Coastguard Worker if (ptr) free(ptr);
139*062a843bSAndroid Build Coastguard Worker }
140*062a843bSAndroid Build Coastguard Worker va_end(ap);
141*062a843bSAndroid Build Coastguard Worker Return<void> retStatus;
142*062a843bSAndroid Build Coastguard Worker switch(msgId) {
143*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_CONNECT:
144*062a843bSAndroid Build Coastguard Worker retStatus = sapCallback->connectResponse(token, SapConnectRsp::CONNECT_FAILURE, 0);
145*062a843bSAndroid Build Coastguard Worker break;
146*062a843bSAndroid Build Coastguard Worker
147*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_DISCONNECT:
148*062a843bSAndroid Build Coastguard Worker retStatus = sapCallback->disconnectResponse(token);
149*062a843bSAndroid Build Coastguard Worker break;
150*062a843bSAndroid Build Coastguard Worker
151*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_APDU: {
152*062a843bSAndroid Build Coastguard Worker hidl_vec<uint8_t> apduRsp;
153*062a843bSAndroid Build Coastguard Worker retStatus = sapCallback->apduResponse(token, SapResultCode::GENERIC_FAILURE, apduRsp);
154*062a843bSAndroid Build Coastguard Worker break;
155*062a843bSAndroid Build Coastguard Worker }
156*062a843bSAndroid Build Coastguard Worker
157*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_TRANSFER_ATR: {
158*062a843bSAndroid Build Coastguard Worker hidl_vec<uint8_t> atr;
159*062a843bSAndroid Build Coastguard Worker retStatus = sapCallback->transferAtrResponse(token, SapResultCode::GENERIC_FAILURE,
160*062a843bSAndroid Build Coastguard Worker atr);
161*062a843bSAndroid Build Coastguard Worker break;
162*062a843bSAndroid Build Coastguard Worker }
163*062a843bSAndroid Build Coastguard Worker
164*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_POWER:
165*062a843bSAndroid Build Coastguard Worker retStatus = sapCallback->powerResponse(token, SapResultCode::GENERIC_FAILURE);
166*062a843bSAndroid Build Coastguard Worker break;
167*062a843bSAndroid Build Coastguard Worker
168*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_RESET_SIM:
169*062a843bSAndroid Build Coastguard Worker retStatus = sapCallback->resetSimResponse(token, SapResultCode::GENERIC_FAILURE);
170*062a843bSAndroid Build Coastguard Worker break;
171*062a843bSAndroid Build Coastguard Worker
172*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS:
173*062a843bSAndroid Build Coastguard Worker retStatus = sapCallback->transferCardReaderStatusResponse(token,
174*062a843bSAndroid Build Coastguard Worker SapResultCode::GENERIC_FAILURE, 0);
175*062a843bSAndroid Build Coastguard Worker break;
176*062a843bSAndroid Build Coastguard Worker
177*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL:
178*062a843bSAndroid Build Coastguard Worker retStatus = sapCallback->transferProtocolResponse(token, SapResultCode::NOT_SUPPORTED);
179*062a843bSAndroid Build Coastguard Worker break;
180*062a843bSAndroid Build Coastguard Worker
181*062a843bSAndroid Build Coastguard Worker default:
182*062a843bSAndroid Build Coastguard Worker return;
183*062a843bSAndroid Build Coastguard Worker }
184*062a843bSAndroid Build Coastguard Worker sapService[slotId]->checkReturnStatus(retStatus);
185*062a843bSAndroid Build Coastguard Worker }
186*062a843bSAndroid Build Coastguard Worker
connectReq(int32_t token,int32_t maxMsgSize)187*062a843bSAndroid Build Coastguard Worker Return<void> SapImpl::connectReq(int32_t token, int32_t maxMsgSize) {
188*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::connectReq");
189*062a843bSAndroid Build Coastguard Worker MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_CONNECT, token);
190*062a843bSAndroid Build Coastguard Worker if (msg == NULL) {
191*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::connectReq: Error allocating memory for msg");
192*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 0);
193*062a843bSAndroid Build Coastguard Worker return Void();
194*062a843bSAndroid Build Coastguard Worker }
195*062a843bSAndroid Build Coastguard Worker
196*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_CONNECT_REQ *****/
197*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_CONNECT_REQ req;
198*062a843bSAndroid Build Coastguard Worker memset(&req, 0, sizeof(RIL_SIM_SAP_CONNECT_REQ));
199*062a843bSAndroid Build Coastguard Worker req.max_message_size = maxMsgSize;
200*062a843bSAndroid Build Coastguard Worker
201*062a843bSAndroid Build Coastguard Worker size_t encodedSize = 0;
202*062a843bSAndroid Build Coastguard Worker if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_CONNECT_REQ_fields, &req)) {
203*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::connectReq: Error getting encoded size for RIL_SIM_SAP_CONNECT_REQ");
204*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 1, msg);
205*062a843bSAndroid Build Coastguard Worker return Void();
206*062a843bSAndroid Build Coastguard Worker }
207*062a843bSAndroid Build Coastguard Worker
208*062a843bSAndroid Build Coastguard Worker uint8_t *buffer = (uint8_t *)calloc(1, encodedSize);
209*062a843bSAndroid Build Coastguard Worker if (buffer == NULL) {
210*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::connectReq: Error allocating memory for buffer");
211*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 1, msg);
212*062a843bSAndroid Build Coastguard Worker return Void();
213*062a843bSAndroid Build Coastguard Worker }
214*062a843bSAndroid Build Coastguard Worker pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize);
215*062a843bSAndroid Build Coastguard Worker
216*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::connectReq calling pb_encode");
217*062a843bSAndroid Build Coastguard Worker if (!pb_encode(&stream, RIL_SIM_SAP_CONNECT_REQ_fields, &req)) {
218*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::connectReq: Error encoding RIL_SIM_SAP_CONNECT_REQ");
219*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_CONNECT, token, 2, buffer, msg);
220*062a843bSAndroid Build Coastguard Worker return Void();
221*062a843bSAndroid Build Coastguard Worker }
222*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_CONNECT_REQ done *****/
223*062a843bSAndroid Build Coastguard Worker
224*062a843bSAndroid Build Coastguard Worker /* encoded req is payload */
225*062a843bSAndroid Build Coastguard Worker return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer);
226*062a843bSAndroid Build Coastguard Worker }
227*062a843bSAndroid Build Coastguard Worker
disconnectReq(int32_t token)228*062a843bSAndroid Build Coastguard Worker Return<void> SapImpl::disconnectReq(int32_t token) {
229*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::disconnectReq");
230*062a843bSAndroid Build Coastguard Worker MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_DISCONNECT, token);
231*062a843bSAndroid Build Coastguard Worker if (msg == NULL) {
232*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::disconnectReq: Error allocating memory for msg");
233*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 0);
234*062a843bSAndroid Build Coastguard Worker return Void();
235*062a843bSAndroid Build Coastguard Worker }
236*062a843bSAndroid Build Coastguard Worker
237*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_DISCONNECT_REQ *****/
238*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_DISCONNECT_REQ req;
239*062a843bSAndroid Build Coastguard Worker memset(&req, 0, sizeof(RIL_SIM_SAP_DISCONNECT_REQ));
240*062a843bSAndroid Build Coastguard Worker
241*062a843bSAndroid Build Coastguard Worker size_t encodedSize = 0;
242*062a843bSAndroid Build Coastguard Worker if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_DISCONNECT_REQ_fields, &req)) {
243*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::disconnectReq: Error getting encoded size for RIL_SIM_SAP_DISCONNECT_REQ");
244*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 1, msg);
245*062a843bSAndroid Build Coastguard Worker return Void();
246*062a843bSAndroid Build Coastguard Worker }
247*062a843bSAndroid Build Coastguard Worker
248*062a843bSAndroid Build Coastguard Worker uint8_t *buffer = (uint8_t *)calloc(1, encodedSize);
249*062a843bSAndroid Build Coastguard Worker if (buffer == NULL) {
250*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::disconnectReq: Error allocating memory for buffer");
251*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 1, msg);
252*062a843bSAndroid Build Coastguard Worker return Void();
253*062a843bSAndroid Build Coastguard Worker }
254*062a843bSAndroid Build Coastguard Worker
255*062a843bSAndroid Build Coastguard Worker pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize);
256*062a843bSAndroid Build Coastguard Worker
257*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::disconnectReq calling pb_encode");
258*062a843bSAndroid Build Coastguard Worker if (!pb_encode(&stream, RIL_SIM_SAP_DISCONNECT_REQ_fields, &req)) {
259*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::disconnectReq: Error encoding RIL_SIM_SAP_DISCONNECT_REQ");
260*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_DISCONNECT, token, 2, buffer, msg);
261*062a843bSAndroid Build Coastguard Worker return Void();
262*062a843bSAndroid Build Coastguard Worker }
263*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_DISCONNECT_REQ done *****/
264*062a843bSAndroid Build Coastguard Worker
265*062a843bSAndroid Build Coastguard Worker /* encoded req is payload */
266*062a843bSAndroid Build Coastguard Worker return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer);
267*062a843bSAndroid Build Coastguard Worker }
268*062a843bSAndroid Build Coastguard Worker
apduReq(int32_t token,SapApduType type,const hidl_vec<uint8_t> & command)269*062a843bSAndroid Build Coastguard Worker Return<void> SapImpl::apduReq(int32_t token, SapApduType type, const hidl_vec<uint8_t>& command) {
270*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::apduReq");
271*062a843bSAndroid Build Coastguard Worker MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_APDU, token);
272*062a843bSAndroid Build Coastguard Worker if (msg == NULL) {
273*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::apduReq: Error allocating memory for msg");
274*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 0);
275*062a843bSAndroid Build Coastguard Worker return Void();
276*062a843bSAndroid Build Coastguard Worker }
277*062a843bSAndroid Build Coastguard Worker
278*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_APDU_REQ *****/
279*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_APDU_REQ req;
280*062a843bSAndroid Build Coastguard Worker memset(&req, 0, sizeof(RIL_SIM_SAP_APDU_REQ));
281*062a843bSAndroid Build Coastguard Worker req.type = (RIL_SIM_SAP_APDU_REQ_Type)type;
282*062a843bSAndroid Build Coastguard Worker
283*062a843bSAndroid Build Coastguard Worker if (command.size() > 0) {
284*062a843bSAndroid Build Coastguard Worker req.command = (pb_bytes_array_t *)malloc(sizeof(pb_bytes_array_t) - 1 + command.size());
285*062a843bSAndroid Build Coastguard Worker if (req.command == NULL) {
286*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::apduReq: Error allocating memory for req.command");
287*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 1, msg);
288*062a843bSAndroid Build Coastguard Worker return Void();
289*062a843bSAndroid Build Coastguard Worker }
290*062a843bSAndroid Build Coastguard Worker req.command->size = command.size();
291*062a843bSAndroid Build Coastguard Worker memcpy(req.command->bytes, command.data(), command.size());
292*062a843bSAndroid Build Coastguard Worker }
293*062a843bSAndroid Build Coastguard Worker
294*062a843bSAndroid Build Coastguard Worker size_t encodedSize = 0;
295*062a843bSAndroid Build Coastguard Worker if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_APDU_REQ_fields, &req)) {
296*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::apduReq: Error getting encoded size for RIL_SIM_SAP_APDU_REQ");
297*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 2, req.command, msg);
298*062a843bSAndroid Build Coastguard Worker return Void();
299*062a843bSAndroid Build Coastguard Worker }
300*062a843bSAndroid Build Coastguard Worker
301*062a843bSAndroid Build Coastguard Worker uint8_t *buffer = (uint8_t *)calloc(1, encodedSize);
302*062a843bSAndroid Build Coastguard Worker if (buffer == NULL) {
303*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::apduReq: Error allocating memory for buffer");
304*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 2, req.command, msg);
305*062a843bSAndroid Build Coastguard Worker return Void();
306*062a843bSAndroid Build Coastguard Worker }
307*062a843bSAndroid Build Coastguard Worker
308*062a843bSAndroid Build Coastguard Worker pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize);
309*062a843bSAndroid Build Coastguard Worker
310*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::apduReq calling pb_encode");
311*062a843bSAndroid Build Coastguard Worker if (!pb_encode(&stream, RIL_SIM_SAP_APDU_REQ_fields, &req)) {
312*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::apduReq: Error encoding RIL_SIM_SAP_APDU_REQ");
313*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_APDU, token, 3, req.command, buffer, msg);
314*062a843bSAndroid Build Coastguard Worker return Void();
315*062a843bSAndroid Build Coastguard Worker }
316*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_APDU_REQ done *****/
317*062a843bSAndroid Build Coastguard Worker
318*062a843bSAndroid Build Coastguard Worker /* encoded req is payload */
319*062a843bSAndroid Build Coastguard Worker return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer);
320*062a843bSAndroid Build Coastguard Worker }
321*062a843bSAndroid Build Coastguard Worker
transferAtrReq(int32_t token)322*062a843bSAndroid Build Coastguard Worker Return<void> SapImpl::transferAtrReq(int32_t token) {
323*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::transferAtrReq");
324*062a843bSAndroid Build Coastguard Worker MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token);
325*062a843bSAndroid Build Coastguard Worker if (msg == NULL) {
326*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::transferAtrReq: Error allocating memory for msg");
327*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 0);
328*062a843bSAndroid Build Coastguard Worker return Void();
329*062a843bSAndroid Build Coastguard Worker }
330*062a843bSAndroid Build Coastguard Worker
331*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_TRANSFER_ATR_REQ *****/
332*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_TRANSFER_ATR_REQ req;
333*062a843bSAndroid Build Coastguard Worker memset(&req, 0, sizeof(RIL_SIM_SAP_TRANSFER_ATR_REQ));
334*062a843bSAndroid Build Coastguard Worker
335*062a843bSAndroid Build Coastguard Worker size_t encodedSize = 0;
336*062a843bSAndroid Build Coastguard Worker if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_TRANSFER_ATR_REQ_fields, &req)) {
337*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::transferAtrReq: Error getting encoded size for "
338*062a843bSAndroid Build Coastguard Worker "RIL_SIM_SAP_TRANSFER_ATR_REQ");
339*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 1, msg);
340*062a843bSAndroid Build Coastguard Worker return Void();
341*062a843bSAndroid Build Coastguard Worker }
342*062a843bSAndroid Build Coastguard Worker
343*062a843bSAndroid Build Coastguard Worker uint8_t *buffer = (uint8_t *)calloc(1, encodedSize);
344*062a843bSAndroid Build Coastguard Worker if (buffer == NULL) {
345*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::transferAtrReq: Error allocating memory for buffer");
346*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 1, msg);
347*062a843bSAndroid Build Coastguard Worker return Void();
348*062a843bSAndroid Build Coastguard Worker }
349*062a843bSAndroid Build Coastguard Worker
350*062a843bSAndroid Build Coastguard Worker pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize);
351*062a843bSAndroid Build Coastguard Worker
352*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::transferAtrReq calling pb_encode");
353*062a843bSAndroid Build Coastguard Worker if (!pb_encode(&stream, RIL_SIM_SAP_TRANSFER_ATR_REQ_fields, &req)) {
354*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::transferAtrReq: Error encoding RIL_SIM_SAP_TRANSFER_ATR_REQ");
355*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_ATR, token, 2, buffer, msg);
356*062a843bSAndroid Build Coastguard Worker return Void();
357*062a843bSAndroid Build Coastguard Worker }
358*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_TRANSFER_ATR_REQ done *****/
359*062a843bSAndroid Build Coastguard Worker
360*062a843bSAndroid Build Coastguard Worker /* encoded req is payload */
361*062a843bSAndroid Build Coastguard Worker return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer);
362*062a843bSAndroid Build Coastguard Worker }
363*062a843bSAndroid Build Coastguard Worker
powerReq(int32_t token,bool state)364*062a843bSAndroid Build Coastguard Worker Return<void> SapImpl::powerReq(int32_t token, bool state) {
365*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::powerReq");
366*062a843bSAndroid Build Coastguard Worker MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_POWER, token);
367*062a843bSAndroid Build Coastguard Worker if (msg == NULL) {
368*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::powerReq: Error allocating memory for msg");
369*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 0);
370*062a843bSAndroid Build Coastguard Worker return Void();
371*062a843bSAndroid Build Coastguard Worker }
372*062a843bSAndroid Build Coastguard Worker
373*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_POWER_REQ *****/
374*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_POWER_REQ req;
375*062a843bSAndroid Build Coastguard Worker memset(&req, 0, sizeof(RIL_SIM_SAP_POWER_REQ));
376*062a843bSAndroid Build Coastguard Worker req.state = state;
377*062a843bSAndroid Build Coastguard Worker
378*062a843bSAndroid Build Coastguard Worker size_t encodedSize = 0;
379*062a843bSAndroid Build Coastguard Worker if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_POWER_REQ_fields, &req)) {
380*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::powerReq: Error getting encoded size for RIL_SIM_SAP_POWER_REQ");
381*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 1, msg);
382*062a843bSAndroid Build Coastguard Worker return Void();
383*062a843bSAndroid Build Coastguard Worker }
384*062a843bSAndroid Build Coastguard Worker
385*062a843bSAndroid Build Coastguard Worker uint8_t *buffer = (uint8_t *)calloc(1, encodedSize);
386*062a843bSAndroid Build Coastguard Worker if (buffer == NULL) {
387*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::powerReq: Error allocating memory for buffer");
388*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 1, msg);
389*062a843bSAndroid Build Coastguard Worker return Void();
390*062a843bSAndroid Build Coastguard Worker }
391*062a843bSAndroid Build Coastguard Worker
392*062a843bSAndroid Build Coastguard Worker pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize);
393*062a843bSAndroid Build Coastguard Worker
394*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::powerReq calling pb_encode");
395*062a843bSAndroid Build Coastguard Worker if (!pb_encode(&stream, RIL_SIM_SAP_POWER_REQ_fields, &req)) {
396*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::powerReq: Error encoding RIL_SIM_SAP_POWER_REQ");
397*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_POWER, token, 2, buffer, msg);
398*062a843bSAndroid Build Coastguard Worker return Void();
399*062a843bSAndroid Build Coastguard Worker }
400*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_POWER_REQ done *****/
401*062a843bSAndroid Build Coastguard Worker
402*062a843bSAndroid Build Coastguard Worker /* encoded req is payload */
403*062a843bSAndroid Build Coastguard Worker return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer);
404*062a843bSAndroid Build Coastguard Worker }
405*062a843bSAndroid Build Coastguard Worker
resetSimReq(int32_t token)406*062a843bSAndroid Build Coastguard Worker Return<void> SapImpl::resetSimReq(int32_t token) {
407*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::resetSimReq");
408*062a843bSAndroid Build Coastguard Worker MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_RESET_SIM, token);
409*062a843bSAndroid Build Coastguard Worker if (msg == NULL) {
410*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::resetSimReq: Error allocating memory for msg");
411*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 0);
412*062a843bSAndroid Build Coastguard Worker return Void();
413*062a843bSAndroid Build Coastguard Worker }
414*062a843bSAndroid Build Coastguard Worker
415*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_RESET_SIM_REQ *****/
416*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_RESET_SIM_REQ req;
417*062a843bSAndroid Build Coastguard Worker memset(&req, 0, sizeof(RIL_SIM_SAP_RESET_SIM_REQ));
418*062a843bSAndroid Build Coastguard Worker
419*062a843bSAndroid Build Coastguard Worker size_t encodedSize = 0;
420*062a843bSAndroid Build Coastguard Worker if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_RESET_SIM_REQ_fields, &req)) {
421*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::resetSimReq: Error getting encoded size for RIL_SIM_SAP_RESET_SIM_REQ");
422*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 1, msg);
423*062a843bSAndroid Build Coastguard Worker return Void();
424*062a843bSAndroid Build Coastguard Worker }
425*062a843bSAndroid Build Coastguard Worker
426*062a843bSAndroid Build Coastguard Worker uint8_t *buffer = (uint8_t *)calloc(1, encodedSize);
427*062a843bSAndroid Build Coastguard Worker if (buffer == NULL) {
428*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::resetSimReq: Error allocating memory for buffer");
429*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 1, msg);
430*062a843bSAndroid Build Coastguard Worker return Void();
431*062a843bSAndroid Build Coastguard Worker }
432*062a843bSAndroid Build Coastguard Worker
433*062a843bSAndroid Build Coastguard Worker pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize);
434*062a843bSAndroid Build Coastguard Worker
435*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::resetSimReq calling pb_encode");
436*062a843bSAndroid Build Coastguard Worker if (!pb_encode(&stream, RIL_SIM_SAP_RESET_SIM_REQ_fields, &req)) {
437*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::resetSimReq: Error encoding RIL_SIM_SAP_RESET_SIM_REQ");
438*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_RESET_SIM, token, 2, buffer, msg);
439*062a843bSAndroid Build Coastguard Worker return Void();
440*062a843bSAndroid Build Coastguard Worker }
441*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_RESET_SIM_REQ done *****/
442*062a843bSAndroid Build Coastguard Worker
443*062a843bSAndroid Build Coastguard Worker /* encoded req is payload */
444*062a843bSAndroid Build Coastguard Worker return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer);
445*062a843bSAndroid Build Coastguard Worker }
446*062a843bSAndroid Build Coastguard Worker
transferCardReaderStatusReq(int32_t token)447*062a843bSAndroid Build Coastguard Worker Return<void> SapImpl::transferCardReaderStatusReq(int32_t token) {
448*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::transferCardReaderStatusReq");
449*062a843bSAndroid Build Coastguard Worker MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token);
450*062a843bSAndroid Build Coastguard Worker if (msg == NULL) {
451*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::transferCardReaderStatusReq: Error allocating memory for msg");
452*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 0);
453*062a843bSAndroid Build Coastguard Worker return Void();
454*062a843bSAndroid Build Coastguard Worker }
455*062a843bSAndroid Build Coastguard Worker
456*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ *****/
457*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ req;
458*062a843bSAndroid Build Coastguard Worker memset(&req, 0, sizeof(RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ));
459*062a843bSAndroid Build Coastguard Worker
460*062a843bSAndroid Build Coastguard Worker size_t encodedSize = 0;
461*062a843bSAndroid Build Coastguard Worker if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ_fields,
462*062a843bSAndroid Build Coastguard Worker &req)) {
463*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::transferCardReaderStatusReq: Error getting encoded size for "
464*062a843bSAndroid Build Coastguard Worker "RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ");
465*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 1, msg);
466*062a843bSAndroid Build Coastguard Worker return Void();
467*062a843bSAndroid Build Coastguard Worker }
468*062a843bSAndroid Build Coastguard Worker
469*062a843bSAndroid Build Coastguard Worker uint8_t *buffer = (uint8_t *)calloc(1, encodedSize);
470*062a843bSAndroid Build Coastguard Worker if (buffer == NULL) {
471*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::transferCardReaderStatusReq: Error allocating memory for buffer");
472*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 1, msg);
473*062a843bSAndroid Build Coastguard Worker return Void();
474*062a843bSAndroid Build Coastguard Worker }
475*062a843bSAndroid Build Coastguard Worker
476*062a843bSAndroid Build Coastguard Worker pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize);
477*062a843bSAndroid Build Coastguard Worker
478*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::transferCardReaderStatusReq calling pb_encode");
479*062a843bSAndroid Build Coastguard Worker if (!pb_encode(&stream, RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ_fields, &req)) {
480*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::transferCardReaderStatusReq: Error encoding "
481*062a843bSAndroid Build Coastguard Worker "RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ");
482*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS, token, 2, buffer, msg);
483*062a843bSAndroid Build Coastguard Worker return Void();
484*062a843bSAndroid Build Coastguard Worker }
485*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_REQ done *****/
486*062a843bSAndroid Build Coastguard Worker
487*062a843bSAndroid Build Coastguard Worker /* encoded req is payload */
488*062a843bSAndroid Build Coastguard Worker return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer);
489*062a843bSAndroid Build Coastguard Worker }
490*062a843bSAndroid Build Coastguard Worker
setTransferProtocolReq(int32_t token,SapTransferProtocol transferProtocol)491*062a843bSAndroid Build Coastguard Worker Return<void> SapImpl::setTransferProtocolReq(int32_t token, SapTransferProtocol transferProtocol) {
492*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::setTransferProtocolReq");
493*062a843bSAndroid Build Coastguard Worker MsgHeader *msg = createMsgHeader(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token);
494*062a843bSAndroid Build Coastguard Worker if (msg == NULL) {
495*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::setTransferProtocolReq: Error allocating memory for msg");
496*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 0);
497*062a843bSAndroid Build Coastguard Worker return Void();
498*062a843bSAndroid Build Coastguard Worker }
499*062a843bSAndroid Build Coastguard Worker
500*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ *****/
501*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ req;
502*062a843bSAndroid Build Coastguard Worker memset(&req, 0, sizeof(RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ));
503*062a843bSAndroid Build Coastguard Worker req.protocol = (RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ_Protocol)transferProtocol;
504*062a843bSAndroid Build Coastguard Worker
505*062a843bSAndroid Build Coastguard Worker size_t encodedSize = 0;
506*062a843bSAndroid Build Coastguard Worker if (!pb_get_encoded_size(&encodedSize, RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ_fields, &req)) {
507*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::setTransferProtocolReq: Error getting encoded size for "
508*062a843bSAndroid Build Coastguard Worker "RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ");
509*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 1, msg);
510*062a843bSAndroid Build Coastguard Worker return Void();
511*062a843bSAndroid Build Coastguard Worker }
512*062a843bSAndroid Build Coastguard Worker
513*062a843bSAndroid Build Coastguard Worker uint8_t *buffer = (uint8_t *)calloc(1, encodedSize);
514*062a843bSAndroid Build Coastguard Worker if (buffer == NULL) {
515*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::setTransferProtocolReq: Error allocating memory for buffer");
516*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 1, msg);
517*062a843bSAndroid Build Coastguard Worker return Void();
518*062a843bSAndroid Build Coastguard Worker }
519*062a843bSAndroid Build Coastguard Worker
520*062a843bSAndroid Build Coastguard Worker pb_ostream_t stream = pb_ostream_from_buffer(buffer, encodedSize);
521*062a843bSAndroid Build Coastguard Worker
522*062a843bSAndroid Build Coastguard Worker RLOGD("SapImpl::setTransferProtocolReq calling pb_encode");
523*062a843bSAndroid Build Coastguard Worker if (!pb_encode(&stream, RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ_fields, &req)) {
524*062a843bSAndroid Build Coastguard Worker RLOGE("SapImpl::setTransferProtocolReq: Error encoding "
525*062a843bSAndroid Build Coastguard Worker "RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ");
526*062a843bSAndroid Build Coastguard Worker sendFailedResponse(MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL, token, 2, buffer, msg);
527*062a843bSAndroid Build Coastguard Worker return Void();
528*062a843bSAndroid Build Coastguard Worker }
529*062a843bSAndroid Build Coastguard Worker /***** Encode RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_REQ done *****/
530*062a843bSAndroid Build Coastguard Worker
531*062a843bSAndroid Build Coastguard Worker /* encoded req is payload */
532*062a843bSAndroid Build Coastguard Worker return addPayloadAndDispatchRequest(msg, stream.bytes_written, buffer);
533*062a843bSAndroid Build Coastguard Worker }
534*062a843bSAndroid Build Coastguard Worker
sapDecodeMessage(MsgId msgId,MsgType msgType,uint8_t * payloadPtr,size_t payloadLen)535*062a843bSAndroid Build Coastguard Worker void *sapDecodeMessage(MsgId msgId, MsgType msgType, uint8_t *payloadPtr, size_t payloadLen) {
536*062a843bSAndroid Build Coastguard Worker void *responsePtr = NULL;
537*062a843bSAndroid Build Coastguard Worker pb_istream_t stream;
538*062a843bSAndroid Build Coastguard Worker
539*062a843bSAndroid Build Coastguard Worker /* Create the stream */
540*062a843bSAndroid Build Coastguard Worker stream = pb_istream_from_buffer((uint8_t *)payloadPtr, payloadLen);
541*062a843bSAndroid Build Coastguard Worker
542*062a843bSAndroid Build Coastguard Worker /* Decode based on the message id */
543*062a843bSAndroid Build Coastguard Worker switch (msgId)
544*062a843bSAndroid Build Coastguard Worker {
545*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_CONNECT:
546*062a843bSAndroid Build Coastguard Worker responsePtr = malloc(sizeof(RIL_SIM_SAP_CONNECT_RSP));
547*062a843bSAndroid Build Coastguard Worker if (responsePtr) {
548*062a843bSAndroid Build Coastguard Worker if (!pb_decode(&stream, RIL_SIM_SAP_CONNECT_RSP_fields, responsePtr)) {
549*062a843bSAndroid Build Coastguard Worker RLOGE("Error decoding RIL_SIM_SAP_CONNECT_RSP");
550*062a843bSAndroid Build Coastguard Worker return NULL;
551*062a843bSAndroid Build Coastguard Worker }
552*062a843bSAndroid Build Coastguard Worker }
553*062a843bSAndroid Build Coastguard Worker break;
554*062a843bSAndroid Build Coastguard Worker
555*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_DISCONNECT:
556*062a843bSAndroid Build Coastguard Worker if (msgType == MsgType_RESPONSE) {
557*062a843bSAndroid Build Coastguard Worker responsePtr = malloc(sizeof(RIL_SIM_SAP_DISCONNECT_RSP));
558*062a843bSAndroid Build Coastguard Worker if (responsePtr) {
559*062a843bSAndroid Build Coastguard Worker if (!pb_decode(&stream, RIL_SIM_SAP_DISCONNECT_RSP_fields, responsePtr)) {
560*062a843bSAndroid Build Coastguard Worker RLOGE("Error decoding RIL_SIM_SAP_DISCONNECT_RSP");
561*062a843bSAndroid Build Coastguard Worker return NULL;
562*062a843bSAndroid Build Coastguard Worker }
563*062a843bSAndroid Build Coastguard Worker }
564*062a843bSAndroid Build Coastguard Worker } else {
565*062a843bSAndroid Build Coastguard Worker responsePtr = malloc(sizeof(RIL_SIM_SAP_DISCONNECT_IND));
566*062a843bSAndroid Build Coastguard Worker if (responsePtr) {
567*062a843bSAndroid Build Coastguard Worker if (!pb_decode(&stream, RIL_SIM_SAP_DISCONNECT_IND_fields, responsePtr)) {
568*062a843bSAndroid Build Coastguard Worker RLOGE("Error decoding RIL_SIM_SAP_DISCONNECT_IND");
569*062a843bSAndroid Build Coastguard Worker return NULL;
570*062a843bSAndroid Build Coastguard Worker }
571*062a843bSAndroid Build Coastguard Worker }
572*062a843bSAndroid Build Coastguard Worker }
573*062a843bSAndroid Build Coastguard Worker break;
574*062a843bSAndroid Build Coastguard Worker
575*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_APDU:
576*062a843bSAndroid Build Coastguard Worker responsePtr = malloc(sizeof(RIL_SIM_SAP_APDU_RSP));
577*062a843bSAndroid Build Coastguard Worker if (responsePtr) {
578*062a843bSAndroid Build Coastguard Worker if (!pb_decode(&stream, RIL_SIM_SAP_APDU_RSP_fields, responsePtr)) {
579*062a843bSAndroid Build Coastguard Worker RLOGE("Error decoding RIL_SIM_SAP_APDU_RSP");
580*062a843bSAndroid Build Coastguard Worker return NULL;
581*062a843bSAndroid Build Coastguard Worker }
582*062a843bSAndroid Build Coastguard Worker }
583*062a843bSAndroid Build Coastguard Worker break;
584*062a843bSAndroid Build Coastguard Worker
585*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_TRANSFER_ATR:
586*062a843bSAndroid Build Coastguard Worker responsePtr = malloc(sizeof(RIL_SIM_SAP_TRANSFER_ATR_RSP));
587*062a843bSAndroid Build Coastguard Worker if (responsePtr) {
588*062a843bSAndroid Build Coastguard Worker if (!pb_decode(&stream, RIL_SIM_SAP_TRANSFER_ATR_RSP_fields, responsePtr)) {
589*062a843bSAndroid Build Coastguard Worker RLOGE("Error decoding RIL_SIM_SAP_TRANSFER_ATR_RSP");
590*062a843bSAndroid Build Coastguard Worker return NULL;
591*062a843bSAndroid Build Coastguard Worker }
592*062a843bSAndroid Build Coastguard Worker }
593*062a843bSAndroid Build Coastguard Worker break;
594*062a843bSAndroid Build Coastguard Worker
595*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_POWER:
596*062a843bSAndroid Build Coastguard Worker responsePtr = malloc(sizeof(RIL_SIM_SAP_POWER_RSP));
597*062a843bSAndroid Build Coastguard Worker if (responsePtr) {
598*062a843bSAndroid Build Coastguard Worker if (!pb_decode(&stream, RIL_SIM_SAP_POWER_RSP_fields, responsePtr)) {
599*062a843bSAndroid Build Coastguard Worker RLOGE("Error decoding RIL_SIM_SAP_POWER_RSP");
600*062a843bSAndroid Build Coastguard Worker return NULL;
601*062a843bSAndroid Build Coastguard Worker }
602*062a843bSAndroid Build Coastguard Worker }
603*062a843bSAndroid Build Coastguard Worker break;
604*062a843bSAndroid Build Coastguard Worker
605*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_RESET_SIM:
606*062a843bSAndroid Build Coastguard Worker responsePtr = malloc(sizeof(RIL_SIM_SAP_RESET_SIM_RSP));
607*062a843bSAndroid Build Coastguard Worker if (responsePtr) {
608*062a843bSAndroid Build Coastguard Worker if (!pb_decode(&stream, RIL_SIM_SAP_RESET_SIM_RSP_fields, responsePtr)) {
609*062a843bSAndroid Build Coastguard Worker RLOGE("Error decoding RIL_SIM_SAP_RESET_SIM_RSP");
610*062a843bSAndroid Build Coastguard Worker return NULL;
611*062a843bSAndroid Build Coastguard Worker }
612*062a843bSAndroid Build Coastguard Worker }
613*062a843bSAndroid Build Coastguard Worker break;
614*062a843bSAndroid Build Coastguard Worker
615*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_STATUS:
616*062a843bSAndroid Build Coastguard Worker responsePtr = malloc(sizeof(RIL_SIM_SAP_STATUS_IND));
617*062a843bSAndroid Build Coastguard Worker if (responsePtr) {
618*062a843bSAndroid Build Coastguard Worker if (!pb_decode(&stream, RIL_SIM_SAP_STATUS_IND_fields, responsePtr)) {
619*062a843bSAndroid Build Coastguard Worker RLOGE("Error decoding RIL_SIM_SAP_STATUS_IND");
620*062a843bSAndroid Build Coastguard Worker return NULL;
621*062a843bSAndroid Build Coastguard Worker }
622*062a843bSAndroid Build Coastguard Worker }
623*062a843bSAndroid Build Coastguard Worker break;
624*062a843bSAndroid Build Coastguard Worker
625*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS:
626*062a843bSAndroid Build Coastguard Worker responsePtr = malloc(sizeof(RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP));
627*062a843bSAndroid Build Coastguard Worker if (responsePtr) {
628*062a843bSAndroid Build Coastguard Worker if (!pb_decode(&stream, RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_fields,
629*062a843bSAndroid Build Coastguard Worker responsePtr)) {
630*062a843bSAndroid Build Coastguard Worker RLOGE("Error decoding RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP");
631*062a843bSAndroid Build Coastguard Worker return NULL;
632*062a843bSAndroid Build Coastguard Worker }
633*062a843bSAndroid Build Coastguard Worker }
634*062a843bSAndroid Build Coastguard Worker break;
635*062a843bSAndroid Build Coastguard Worker
636*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_ERROR_RESP:
637*062a843bSAndroid Build Coastguard Worker responsePtr = malloc(sizeof(RIL_SIM_SAP_ERROR_RSP));
638*062a843bSAndroid Build Coastguard Worker if (responsePtr) {
639*062a843bSAndroid Build Coastguard Worker if (!pb_decode(&stream, RIL_SIM_SAP_ERROR_RSP_fields, responsePtr)) {
640*062a843bSAndroid Build Coastguard Worker RLOGE("Error decoding RIL_SIM_SAP_ERROR_RSP");
641*062a843bSAndroid Build Coastguard Worker return NULL;
642*062a843bSAndroid Build Coastguard Worker }
643*062a843bSAndroid Build Coastguard Worker }
644*062a843bSAndroid Build Coastguard Worker break;
645*062a843bSAndroid Build Coastguard Worker
646*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL:
647*062a843bSAndroid Build Coastguard Worker responsePtr = malloc(sizeof(RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP));
648*062a843bSAndroid Build Coastguard Worker if (responsePtr) {
649*062a843bSAndroid Build Coastguard Worker if (!pb_decode(&stream, RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP_fields,
650*062a843bSAndroid Build Coastguard Worker responsePtr)) {
651*062a843bSAndroid Build Coastguard Worker RLOGE("Error decoding RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP");
652*062a843bSAndroid Build Coastguard Worker return NULL;
653*062a843bSAndroid Build Coastguard Worker }
654*062a843bSAndroid Build Coastguard Worker }
655*062a843bSAndroid Build Coastguard Worker break;
656*062a843bSAndroid Build Coastguard Worker
657*062a843bSAndroid Build Coastguard Worker default:
658*062a843bSAndroid Build Coastguard Worker break;
659*062a843bSAndroid Build Coastguard Worker }
660*062a843bSAndroid Build Coastguard Worker return responsePtr;
661*062a843bSAndroid Build Coastguard Worker } /* sapDecodeMessage */
662*062a843bSAndroid Build Coastguard Worker
getSapImpl(RilSapSocket * sapSocket)663*062a843bSAndroid Build Coastguard Worker sp<SapImpl> getSapImpl(RilSapSocket *sapSocket) {
664*062a843bSAndroid Build Coastguard Worker switch (sapSocket->getSocketId()) {
665*062a843bSAndroid Build Coastguard Worker case RIL_SOCKET_1:
666*062a843bSAndroid Build Coastguard Worker RLOGD("getSapImpl: returning sapService[0]");
667*062a843bSAndroid Build Coastguard Worker return sapService[0];
668*062a843bSAndroid Build Coastguard Worker #if (SIM_COUNT >= 2)
669*062a843bSAndroid Build Coastguard Worker case RIL_SOCKET_2:
670*062a843bSAndroid Build Coastguard Worker return sapService[1];
671*062a843bSAndroid Build Coastguard Worker #if (SIM_COUNT >= 3)
672*062a843bSAndroid Build Coastguard Worker case RIL_SOCKET_3:
673*062a843bSAndroid Build Coastguard Worker return sapService[2];
674*062a843bSAndroid Build Coastguard Worker #if (SIM_COUNT >= 4)
675*062a843bSAndroid Build Coastguard Worker case RIL_SOCKET_4:
676*062a843bSAndroid Build Coastguard Worker return sapService[3];
677*062a843bSAndroid Build Coastguard Worker #endif
678*062a843bSAndroid Build Coastguard Worker #endif
679*062a843bSAndroid Build Coastguard Worker #endif
680*062a843bSAndroid Build Coastguard Worker default:
681*062a843bSAndroid Build Coastguard Worker return NULL;
682*062a843bSAndroid Build Coastguard Worker }
683*062a843bSAndroid Build Coastguard Worker }
684*062a843bSAndroid Build Coastguard Worker
convertApduResponseProtoToHal(RIL_SIM_SAP_APDU_RSP_Response responseProto)685*062a843bSAndroid Build Coastguard Worker SapResultCode convertApduResponseProtoToHal(RIL_SIM_SAP_APDU_RSP_Response responseProto) {
686*062a843bSAndroid Build Coastguard Worker switch(responseProto) {
687*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SUCCESS:
688*062a843bSAndroid Build Coastguard Worker return SapResultCode::SUCCESS;
689*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_GENERIC_FAILURE:
690*062a843bSAndroid Build Coastguard Worker return SapResultCode::GENERIC_FAILURE;
691*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SIM_NOT_READY:
692*062a843bSAndroid Build Coastguard Worker return SapResultCode::CARD_NOT_ACCESSSIBLE;
693*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF:
694*062a843bSAndroid Build Coastguard Worker return SapResultCode::CARD_ALREADY_POWERED_OFF;
695*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_APDU_RSP_Response_RIL_E_SIM_ABSENT:
696*062a843bSAndroid Build Coastguard Worker return SapResultCode::CARD_REMOVED;
697*062a843bSAndroid Build Coastguard Worker default:
698*062a843bSAndroid Build Coastguard Worker return SapResultCode::GENERIC_FAILURE;
699*062a843bSAndroid Build Coastguard Worker }
700*062a843bSAndroid Build Coastguard Worker }
701*062a843bSAndroid Build Coastguard Worker
convertTransferAtrResponseProtoToHal(RIL_SIM_SAP_TRANSFER_ATR_RSP_Response responseProto)702*062a843bSAndroid Build Coastguard Worker SapResultCode convertTransferAtrResponseProtoToHal(
703*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_TRANSFER_ATR_RSP_Response responseProto) {
704*062a843bSAndroid Build Coastguard Worker switch(responseProto) {
705*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SUCCESS:
706*062a843bSAndroid Build Coastguard Worker return SapResultCode::SUCCESS;
707*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_GENERIC_FAILURE:
708*062a843bSAndroid Build Coastguard Worker return SapResultCode::GENERIC_FAILURE;
709*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF:
710*062a843bSAndroid Build Coastguard Worker return SapResultCode::CARD_ALREADY_POWERED_OFF;
711*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SIM_ABSENT:
712*062a843bSAndroid Build Coastguard Worker return SapResultCode::CARD_REMOVED;
713*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_TRANSFER_ATR_RSP_Response_RIL_E_SIM_DATA_NOT_AVAILABLE:
714*062a843bSAndroid Build Coastguard Worker return SapResultCode::DATA_NOT_AVAILABLE;
715*062a843bSAndroid Build Coastguard Worker default:
716*062a843bSAndroid Build Coastguard Worker return SapResultCode::GENERIC_FAILURE;
717*062a843bSAndroid Build Coastguard Worker }
718*062a843bSAndroid Build Coastguard Worker }
719*062a843bSAndroid Build Coastguard Worker
convertPowerResponseProtoToHal(RIL_SIM_SAP_POWER_RSP_Response responseProto)720*062a843bSAndroid Build Coastguard Worker SapResultCode convertPowerResponseProtoToHal(RIL_SIM_SAP_POWER_RSP_Response responseProto) {
721*062a843bSAndroid Build Coastguard Worker switch(responseProto) {
722*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SUCCESS:
723*062a843bSAndroid Build Coastguard Worker return SapResultCode::SUCCESS;
724*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_GENERIC_FAILURE:
725*062a843bSAndroid Build Coastguard Worker return SapResultCode::GENERIC_FAILURE;
726*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SIM_ABSENT:
727*062a843bSAndroid Build Coastguard Worker return SapResultCode::CARD_REMOVED;
728*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF:
729*062a843bSAndroid Build Coastguard Worker return SapResultCode::CARD_ALREADY_POWERED_OFF;
730*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_POWER_RSP_Response_RIL_E_SIM_ALREADY_POWERED_ON:
731*062a843bSAndroid Build Coastguard Worker return SapResultCode::CARD_ALREADY_POWERED_ON;
732*062a843bSAndroid Build Coastguard Worker default:
733*062a843bSAndroid Build Coastguard Worker return SapResultCode::GENERIC_FAILURE;
734*062a843bSAndroid Build Coastguard Worker }
735*062a843bSAndroid Build Coastguard Worker }
736*062a843bSAndroid Build Coastguard Worker
convertResetSimResponseProtoToHal(RIL_SIM_SAP_RESET_SIM_RSP_Response responseProto)737*062a843bSAndroid Build Coastguard Worker SapResultCode convertResetSimResponseProtoToHal(RIL_SIM_SAP_RESET_SIM_RSP_Response responseProto) {
738*062a843bSAndroid Build Coastguard Worker switch(responseProto) {
739*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SUCCESS:
740*062a843bSAndroid Build Coastguard Worker return SapResultCode::SUCCESS;
741*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_GENERIC_FAILURE:
742*062a843bSAndroid Build Coastguard Worker return SapResultCode::GENERIC_FAILURE;
743*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SIM_ABSENT:
744*062a843bSAndroid Build Coastguard Worker return SapResultCode::CARD_REMOVED;
745*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SIM_NOT_READY:
746*062a843bSAndroid Build Coastguard Worker return SapResultCode::CARD_NOT_ACCESSSIBLE;
747*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_RESET_SIM_RSP_Response_RIL_E_SIM_ALREADY_POWERED_OFF:
748*062a843bSAndroid Build Coastguard Worker return SapResultCode::CARD_ALREADY_POWERED_OFF;
749*062a843bSAndroid Build Coastguard Worker }
750*062a843bSAndroid Build Coastguard Worker return SapResultCode::GENERIC_FAILURE;
751*062a843bSAndroid Build Coastguard Worker }
752*062a843bSAndroid Build Coastguard Worker
convertTransferCardReaderStatusResponseProtoToHal(RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response responseProto)753*062a843bSAndroid Build Coastguard Worker SapResultCode convertTransferCardReaderStatusResponseProtoToHal(
754*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response responseProto) {
755*062a843bSAndroid Build Coastguard Worker switch(responseProto) {
756*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response_RIL_E_SUCCESS:
757*062a843bSAndroid Build Coastguard Worker return SapResultCode::SUCCESS;
758*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response_RIL_E_GENERIC_FAILURE:
759*062a843bSAndroid Build Coastguard Worker return SapResultCode::GENERIC_FAILURE;
760*062a843bSAndroid Build Coastguard Worker case RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP_Response_RIL_E_SIM_DATA_NOT_AVAILABLE:
761*062a843bSAndroid Build Coastguard Worker return SapResultCode::DATA_NOT_AVAILABLE;
762*062a843bSAndroid Build Coastguard Worker }
763*062a843bSAndroid Build Coastguard Worker return SapResultCode::GENERIC_FAILURE;
764*062a843bSAndroid Build Coastguard Worker }
765*062a843bSAndroid Build Coastguard Worker
processResponse(MsgHeader * rsp,RilSapSocket * sapSocket,MsgType msgType)766*062a843bSAndroid Build Coastguard Worker void processResponse(MsgHeader *rsp, RilSapSocket *sapSocket, MsgType msgType) {
767*062a843bSAndroid Build Coastguard Worker MsgId msgId = rsp->id;
768*062a843bSAndroid Build Coastguard Worker uint8_t *data = rsp->payload->bytes;
769*062a843bSAndroid Build Coastguard Worker size_t dataLen = rsp->payload->size;
770*062a843bSAndroid Build Coastguard Worker
771*062a843bSAndroid Build Coastguard Worker void *messagePtr = sapDecodeMessage(msgId, msgType, data, dataLen);
772*062a843bSAndroid Build Coastguard Worker
773*062a843bSAndroid Build Coastguard Worker sp<SapImpl> sapImpl = getSapImpl(sapSocket);
774*062a843bSAndroid Build Coastguard Worker if (sapImpl->sapCallback == NULL) {
775*062a843bSAndroid Build Coastguard Worker RLOGE("processResponse: sapCallback == NULL; msgId = %d; msgType = %d",
776*062a843bSAndroid Build Coastguard Worker msgId, msgType);
777*062a843bSAndroid Build Coastguard Worker return;
778*062a843bSAndroid Build Coastguard Worker }
779*062a843bSAndroid Build Coastguard Worker
780*062a843bSAndroid Build Coastguard Worker if (messagePtr == NULL) {
781*062a843bSAndroid Build Coastguard Worker RLOGE("processResponse: *messagePtr == NULL; msgId = %d; msgType = %d",
782*062a843bSAndroid Build Coastguard Worker msgId, msgType);
783*062a843bSAndroid Build Coastguard Worker sapImpl->sendFailedResponse(msgId, rsp->token, 0);
784*062a843bSAndroid Build Coastguard Worker return;
785*062a843bSAndroid Build Coastguard Worker }
786*062a843bSAndroid Build Coastguard Worker
787*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: sapCallback != NULL; msgId = %d; msgType = %d",
788*062a843bSAndroid Build Coastguard Worker msgId, msgType);
789*062a843bSAndroid Build Coastguard Worker
790*062a843bSAndroid Build Coastguard Worker Return<void> retStatus;
791*062a843bSAndroid Build Coastguard Worker switch (msgId) {
792*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_CONNECT: {
793*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_CONNECT_RSP *connectRsp = (RIL_SIM_SAP_CONNECT_RSP *)messagePtr;
794*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: calling sapCallback->connectResponse %d %d %d",
795*062a843bSAndroid Build Coastguard Worker rsp->token,
796*062a843bSAndroid Build Coastguard Worker connectRsp->response,
797*062a843bSAndroid Build Coastguard Worker connectRsp->max_message_size);
798*062a843bSAndroid Build Coastguard Worker retStatus = sapImpl->sapCallback->connectResponse(rsp->token,
799*062a843bSAndroid Build Coastguard Worker (SapConnectRsp)connectRsp->response,
800*062a843bSAndroid Build Coastguard Worker connectRsp->max_message_size);
801*062a843bSAndroid Build Coastguard Worker break;
802*062a843bSAndroid Build Coastguard Worker }
803*062a843bSAndroid Build Coastguard Worker
804*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_DISCONNECT:
805*062a843bSAndroid Build Coastguard Worker if (msgType == MsgType_RESPONSE) {
806*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: calling sapCallback->disconnectResponse %d", rsp->token);
807*062a843bSAndroid Build Coastguard Worker retStatus = sapImpl->sapCallback->disconnectResponse(rsp->token);
808*062a843bSAndroid Build Coastguard Worker } else {
809*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_DISCONNECT_IND *disconnectInd =
810*062a843bSAndroid Build Coastguard Worker (RIL_SIM_SAP_DISCONNECT_IND *)messagePtr;
811*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: calling sapCallback->disconnectIndication %d %d",
812*062a843bSAndroid Build Coastguard Worker rsp->token, disconnectInd->disconnectType);
813*062a843bSAndroid Build Coastguard Worker retStatus = sapImpl->sapCallback->disconnectIndication(rsp->token,
814*062a843bSAndroid Build Coastguard Worker (SapDisconnectType)disconnectInd->disconnectType);
815*062a843bSAndroid Build Coastguard Worker }
816*062a843bSAndroid Build Coastguard Worker break;
817*062a843bSAndroid Build Coastguard Worker
818*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_APDU: {
819*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_APDU_RSP *apduRsp = (RIL_SIM_SAP_APDU_RSP *)messagePtr;
820*062a843bSAndroid Build Coastguard Worker SapResultCode apduResponse = convertApduResponseProtoToHal(apduRsp->response);
821*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: calling sapCallback->apduResponse %d %d",
822*062a843bSAndroid Build Coastguard Worker rsp->token, apduResponse);
823*062a843bSAndroid Build Coastguard Worker hidl_vec<uint8_t> apduRspVec;
824*062a843bSAndroid Build Coastguard Worker if (apduRsp->apduResponse != NULL && apduRsp->apduResponse->size > 0) {
825*062a843bSAndroid Build Coastguard Worker apduRspVec.setToExternal(apduRsp->apduResponse->bytes, apduRsp->apduResponse->size);
826*062a843bSAndroid Build Coastguard Worker }
827*062a843bSAndroid Build Coastguard Worker retStatus = sapImpl->sapCallback->apduResponse(rsp->token, apduResponse, apduRspVec);
828*062a843bSAndroid Build Coastguard Worker break;
829*062a843bSAndroid Build Coastguard Worker }
830*062a843bSAndroid Build Coastguard Worker
831*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_TRANSFER_ATR: {
832*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_TRANSFER_ATR_RSP *transferAtrRsp =
833*062a843bSAndroid Build Coastguard Worker (RIL_SIM_SAP_TRANSFER_ATR_RSP *)messagePtr;
834*062a843bSAndroid Build Coastguard Worker SapResultCode transferAtrResponse =
835*062a843bSAndroid Build Coastguard Worker convertTransferAtrResponseProtoToHal(transferAtrRsp->response);
836*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: calling sapCallback->transferAtrResponse %d %d",
837*062a843bSAndroid Build Coastguard Worker rsp->token, transferAtrResponse);
838*062a843bSAndroid Build Coastguard Worker hidl_vec<uint8_t> transferAtrRspVec;
839*062a843bSAndroid Build Coastguard Worker if (transferAtrRsp->atr != NULL && transferAtrRsp->atr->size > 0) {
840*062a843bSAndroid Build Coastguard Worker transferAtrRspVec.setToExternal(transferAtrRsp->atr->bytes,
841*062a843bSAndroid Build Coastguard Worker transferAtrRsp->atr->size);
842*062a843bSAndroid Build Coastguard Worker }
843*062a843bSAndroid Build Coastguard Worker retStatus = sapImpl->sapCallback->transferAtrResponse(rsp->token, transferAtrResponse,
844*062a843bSAndroid Build Coastguard Worker transferAtrRspVec);
845*062a843bSAndroid Build Coastguard Worker break;
846*062a843bSAndroid Build Coastguard Worker }
847*062a843bSAndroid Build Coastguard Worker
848*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_POWER: {
849*062a843bSAndroid Build Coastguard Worker SapResultCode powerResponse = convertPowerResponseProtoToHal(
850*062a843bSAndroid Build Coastguard Worker ((RIL_SIM_SAP_POWER_RSP *)messagePtr)->response);
851*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: calling sapCallback->powerResponse %d %d",
852*062a843bSAndroid Build Coastguard Worker rsp->token, powerResponse);
853*062a843bSAndroid Build Coastguard Worker retStatus = sapImpl->sapCallback->powerResponse(rsp->token, powerResponse);
854*062a843bSAndroid Build Coastguard Worker break;
855*062a843bSAndroid Build Coastguard Worker }
856*062a843bSAndroid Build Coastguard Worker
857*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_RESET_SIM: {
858*062a843bSAndroid Build Coastguard Worker SapResultCode resetSimResponse = convertResetSimResponseProtoToHal(
859*062a843bSAndroid Build Coastguard Worker ((RIL_SIM_SAP_RESET_SIM_RSP *)messagePtr)->response);
860*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: calling sapCallback->resetSimResponse %d %d",
861*062a843bSAndroid Build Coastguard Worker rsp->token, resetSimResponse);
862*062a843bSAndroid Build Coastguard Worker retStatus = sapImpl->sapCallback->resetSimResponse(rsp->token, resetSimResponse);
863*062a843bSAndroid Build Coastguard Worker break;
864*062a843bSAndroid Build Coastguard Worker }
865*062a843bSAndroid Build Coastguard Worker
866*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_STATUS: {
867*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_STATUS_IND *statusInd = (RIL_SIM_SAP_STATUS_IND *)messagePtr;
868*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: calling sapCallback->statusIndication %d %d",
869*062a843bSAndroid Build Coastguard Worker rsp->token, statusInd->statusChange);
870*062a843bSAndroid Build Coastguard Worker retStatus = sapImpl->sapCallback->statusIndication(rsp->token,
871*062a843bSAndroid Build Coastguard Worker (SapStatus)statusInd->statusChange);
872*062a843bSAndroid Build Coastguard Worker break;
873*062a843bSAndroid Build Coastguard Worker }
874*062a843bSAndroid Build Coastguard Worker
875*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS: {
876*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP *transferStatusRsp =
877*062a843bSAndroid Build Coastguard Worker (RIL_SIM_SAP_TRANSFER_CARD_READER_STATUS_RSP *)messagePtr;
878*062a843bSAndroid Build Coastguard Worker SapResultCode transferCardReaderStatusResponse =
879*062a843bSAndroid Build Coastguard Worker convertTransferCardReaderStatusResponseProtoToHal(
880*062a843bSAndroid Build Coastguard Worker transferStatusRsp->response);
881*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: calling sapCallback->transferCardReaderStatusResponse %d %d %d",
882*062a843bSAndroid Build Coastguard Worker rsp->token,
883*062a843bSAndroid Build Coastguard Worker transferCardReaderStatusResponse,
884*062a843bSAndroid Build Coastguard Worker transferStatusRsp->CardReaderStatus);
885*062a843bSAndroid Build Coastguard Worker retStatus = sapImpl->sapCallback->transferCardReaderStatusResponse(rsp->token,
886*062a843bSAndroid Build Coastguard Worker transferCardReaderStatusResponse,
887*062a843bSAndroid Build Coastguard Worker transferStatusRsp->CardReaderStatus);
888*062a843bSAndroid Build Coastguard Worker break;
889*062a843bSAndroid Build Coastguard Worker }
890*062a843bSAndroid Build Coastguard Worker
891*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_ERROR_RESP: {
892*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: calling sapCallback->errorResponse %d", rsp->token);
893*062a843bSAndroid Build Coastguard Worker retStatus = sapImpl->sapCallback->errorResponse(rsp->token);
894*062a843bSAndroid Build Coastguard Worker break;
895*062a843bSAndroid Build Coastguard Worker }
896*062a843bSAndroid Build Coastguard Worker
897*062a843bSAndroid Build Coastguard Worker case MsgId_RIL_SIM_SAP_SET_TRANSFER_PROTOCOL: {
898*062a843bSAndroid Build Coastguard Worker SapResultCode setTransferProtocolResponse;
899*062a843bSAndroid Build Coastguard Worker if (((RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP *)messagePtr)->response ==
900*062a843bSAndroid Build Coastguard Worker RIL_SIM_SAP_SET_TRANSFER_PROTOCOL_RSP_Response_RIL_E_SUCCESS) {
901*062a843bSAndroid Build Coastguard Worker setTransferProtocolResponse = SapResultCode::SUCCESS;
902*062a843bSAndroid Build Coastguard Worker } else {
903*062a843bSAndroid Build Coastguard Worker setTransferProtocolResponse = SapResultCode::NOT_SUPPORTED;
904*062a843bSAndroid Build Coastguard Worker }
905*062a843bSAndroid Build Coastguard Worker RLOGD("processResponse: calling sapCallback->transferProtocolResponse %d %d",
906*062a843bSAndroid Build Coastguard Worker rsp->token, setTransferProtocolResponse);
907*062a843bSAndroid Build Coastguard Worker retStatus = sapImpl->sapCallback->transferProtocolResponse(rsp->token,
908*062a843bSAndroid Build Coastguard Worker setTransferProtocolResponse);
909*062a843bSAndroid Build Coastguard Worker break;
910*062a843bSAndroid Build Coastguard Worker }
911*062a843bSAndroid Build Coastguard Worker
912*062a843bSAndroid Build Coastguard Worker default:
913*062a843bSAndroid Build Coastguard Worker return;
914*062a843bSAndroid Build Coastguard Worker }
915*062a843bSAndroid Build Coastguard Worker sapImpl->checkReturnStatus(retStatus);
916*062a843bSAndroid Build Coastguard Worker }
917*062a843bSAndroid Build Coastguard Worker
processResponse(MsgHeader * rsp,RilSapSocket * sapSocket)918*062a843bSAndroid Build Coastguard Worker void sap::processResponse(MsgHeader *rsp, RilSapSocket *sapSocket) {
919*062a843bSAndroid Build Coastguard Worker processResponse(rsp, sapSocket, MsgType_RESPONSE);
920*062a843bSAndroid Build Coastguard Worker }
921*062a843bSAndroid Build Coastguard Worker
processUnsolResponse(MsgHeader * rsp,RilSapSocket * sapSocket)922*062a843bSAndroid Build Coastguard Worker void sap::processUnsolResponse(MsgHeader *rsp, RilSapSocket *sapSocket) {
923*062a843bSAndroid Build Coastguard Worker processResponse(rsp, sapSocket, MsgType_UNSOL_RESPONSE);
924*062a843bSAndroid Build Coastguard Worker }
925*062a843bSAndroid Build Coastguard Worker
registerService(const RIL_RadioFunctions * callbacks)926*062a843bSAndroid Build Coastguard Worker void sap::registerService(const RIL_RadioFunctions *callbacks) {
927*062a843bSAndroid Build Coastguard Worker using namespace android::hardware;
928*062a843bSAndroid Build Coastguard Worker int simCount = 1;
929*062a843bSAndroid Build Coastguard Worker const char *serviceNames[] = {
930*062a843bSAndroid Build Coastguard Worker android::RIL_getServiceName()
931*062a843bSAndroid Build Coastguard Worker #if (SIM_COUNT >= 2)
932*062a843bSAndroid Build Coastguard Worker , RIL2_SERVICE_NAME
933*062a843bSAndroid Build Coastguard Worker #if (SIM_COUNT >= 3)
934*062a843bSAndroid Build Coastguard Worker , RIL3_SERVICE_NAME
935*062a843bSAndroid Build Coastguard Worker #if (SIM_COUNT >= 4)
936*062a843bSAndroid Build Coastguard Worker , RIL4_SERVICE_NAME
937*062a843bSAndroid Build Coastguard Worker #endif
938*062a843bSAndroid Build Coastguard Worker #endif
939*062a843bSAndroid Build Coastguard Worker #endif
940*062a843bSAndroid Build Coastguard Worker };
941*062a843bSAndroid Build Coastguard Worker
942*062a843bSAndroid Build Coastguard Worker RIL_SOCKET_ID socketIds[] = {
943*062a843bSAndroid Build Coastguard Worker RIL_SOCKET_1
944*062a843bSAndroid Build Coastguard Worker #if (SIM_COUNT >= 2)
945*062a843bSAndroid Build Coastguard Worker , RIL_SOCKET_2
946*062a843bSAndroid Build Coastguard Worker #if (SIM_COUNT >= 3)
947*062a843bSAndroid Build Coastguard Worker , RIL_SOCKET_3
948*062a843bSAndroid Build Coastguard Worker #if (SIM_COUNT >= 4)
949*062a843bSAndroid Build Coastguard Worker , RIL_SOCKET_4
950*062a843bSAndroid Build Coastguard Worker #endif
951*062a843bSAndroid Build Coastguard Worker #endif
952*062a843bSAndroid Build Coastguard Worker #endif
953*062a843bSAndroid Build Coastguard Worker };
954*062a843bSAndroid Build Coastguard Worker #if (SIM_COUNT >= 2)
955*062a843bSAndroid Build Coastguard Worker simCount = SIM_COUNT;
956*062a843bSAndroid Build Coastguard Worker #endif
957*062a843bSAndroid Build Coastguard Worker
958*062a843bSAndroid Build Coastguard Worker for (int i = 0; i < simCount; i++) {
959*062a843bSAndroid Build Coastguard Worker sapService[i] = new SapImpl;
960*062a843bSAndroid Build Coastguard Worker sapService[i]->slotId = i;
961*062a843bSAndroid Build Coastguard Worker sapService[i]->rilSocketId = socketIds[i];
962*062a843bSAndroid Build Coastguard Worker RLOGD("registerService: starting ISap %s for slotId %d", serviceNames[i], i);
963*062a843bSAndroid Build Coastguard Worker android::status_t status = sapService[i]->registerAsService(serviceNames[i]);
964*062a843bSAndroid Build Coastguard Worker RLOGD("registerService: started ISap %s status %d", serviceNames[i], status);
965*062a843bSAndroid Build Coastguard Worker }
966*062a843bSAndroid Build Coastguard Worker }
967