1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_RIL_VENDOR_SIM_DEFS_H
17 #define OHOS_RIL_VENDOR_SIM_DEFS_H
18 
19 #include <stddef.h>
20 
21 #include "hril_public_struct.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /**
28  * @brief Defines the SIM data request information.
29  *
30  * Form 3GPP TS 27.007 V4.3.0 (2001-12) 8.18, + CRSM
31  */
32 typedef struct {
33     /**
34      * Command passed on by the MT to the SIM; refer 3GPP TS 51.011 [28]
35      * 176 READ BINARY
36      * 178 READ RECORD
37      * 192 GET RESPONSE
38      * 214 UPDATE BINARY
39      * 220 UPDATE RECORD
40      * 242 STATUS
41      * 203 RETRIEVE DATA
42      * 219 SET DATA
43      */
44     int32_t command;
45     /**
46      * This is the identifier of an elementary datafile on SIM.
47      * Mandatory for every command except STATUS.
48      */
49     int32_t fileid;
50     /**
51      * Parameters passed on by the MT to the SIM. These parameters are mandatory for every command,
52      * except GET RESPONSE and STATUS. The values are described in 3GPP TS 51.011 [28].
53      */
54     int32_t p1;
55     /**
56      * Parameters passed on by the MT to the SIM. These parameters are mandatory for every command,
57      * except GET RESPONSE and STATUS. The values are described in 3GPP TS 51.011 [28].
58      */
59     int32_t p2;
60     /**
61      * Parameters passed on by the MT to the SIM. These parameters are mandatory for every command,
62      * except GET RESPONSE and STATUS. The values are described in 3GPP TS 51.011 [28].
63      */
64     int32_t p3;
65     /**
66      *  Information which shall be written to the SIM (hexadecimal character format; refer +CSCS).
67      */
68     char *data;
69     /**
70      * Contains the path of an elementary file on the SIM/UICC in hexadecimal format
71      * as defined in ETSI TS 102 221 [60] (e.g. "7F205F70" in SIM and UICC case).
72      * The <pathid> shall only be used in the mode "select by path from MF"
73      * as defined in ETSI TS 102 221 [60].
74      */
75     char *pathid;
76     /**
77      * PIN2
78      */
79     char *pin2;
80 } HRilSimIO;
81 
82 /**
83  * @brief Defines the response to the SIM data request.
84  *
85  * Form TS 27.007.8.18 +CRSM
86  */
87 typedef struct {
88     /**
89      * Information from the SIM about the execution of the actual command.
90      * These parameters are delivered to the TE in both cases,
91      * on successful or failed execution of the command.
92      */
93     int32_t sw1;
94     /**
95      * Information from the SIM about the execution of the actual command.
96      * These parameters are delivered to the TE in both cases,
97      * on successful or failed execution of the command.
98      */
99     int32_t sw2;
100     /**
101      * Response of a successful completion of the command previously issued
102      * (hexadecimal character format; refer +CSCS). STATUS and GET RESPONSE return data,
103      * which gives information about the current elementary datafield.This information
104      * includes the type of file and its size (refer 3GPP TS 51.011 [28]). After READ BINARY,
105      * READ RECORD or RETRIEVE DATA command the requested data will be returned.
106      * <response> is not returned after a successful UPDATE BINARY,
107      * UPDATE RECORD or SET DATA command
108      */
109     char *response;
110 } HRilSimIOResponse;
111 
112 /**
113  * @brief Defines the response to the request for enabling the logical channel of the APDU.
114  */
115 typedef struct {
116     /**
117      * Information from the SIM about the execution of the actual command.
118      * These parameters are delivered to the TE in both cases,
119      * on successful or failed execution of the command.
120      */
121     int32_t sw1;
122     /**
123      * Information from the SIM about the execution of the actual command.
124      * These parameters are delivered to the TE in both cases,
125      * on successful or failed execution of the command.
126      */
127     int32_t sw2;
128     /**
129      * ID of the opened logical channel
130      */
131     int32_t channelId;
132     /**
133      * Response information
134      */
135     char *response;
136 } HRilOpenLogicalChannelResponse;
137 
138 /**
139  * @brief Defines the SIM card status information.
140  */
141 typedef struct {
142     /**
143      * SIM card index
144      */
145     int32_t index;
146     /**
147      * SIM card type:
148      */
149     HRilSimType simType;
150     /**
151      * SIM card status:
152      */
153     HRilSimState simState;
154     /**
155      * SIM card iccid:
156      */
157     char *iccid;
158 } HRilCardState;
159 
160 /**
161  * @brief Defines the lock status information.
162  */
163 typedef struct {
164     /**
165      * Query result. For details, see {@link RilErrType}.
166      */
167     int32_t result;
168     /**
169      * Number of remaining attempts
170      */
171     int32_t remain;
172 } HRilLockStatus;
173 
174 /**
175  * @brief Defines the SIM card lock information.
176  *
177  * From 3GPP TS 27.007 7.4
178  */
179 typedef struct {
180     /**
181      * ("SC","AO","OI","OX","AI","IR","AB","AG","AC","FD","PN","PU","PP")
182      */
183     char *fac;
184     /**
185      * 0 unlock
186      * 1 lock
187      * 2 query status
188      */
189     int32_t mode;
190     /**
191      * 0 not active
192      * 1 active
193      */
194     int32_t status;
195     /**
196      * Shall be the same as password specified for the facility
197      * from the MT user interface or with command Change Password +CPWD
198      */
199     char *passwd;
200     /**
201      * Is a sum of integers each representing a class of information (default 7 - voice, data and
202      * fax): 1 voice (telephony) 2 data (refers to all bearer services; with <mode>=2 this may refer
203      * only to some bearer service if TA does not support values 16, 32, 64 and 128) 4 fax (facsimile
204      * services) 8 short message service 16 data circuit sync 32 data circuit async 64
205      * dedicated packet access 128 dedicated PAD access
206      */
207     int32_t classx;
208 } HRilSimClock;
209 
210 /**
211  * @brief Defines the SIM card password information.
212  *
213  * From 3GPP TS 27.007 7.5
214  */
215 typedef struct {
216     /**
217      * ("SC","AO","OI","OX","AI","IR","AB","AG","AC","FD","PN","PU","PP")
218      */
219     char *fac;
220     /**
221      *  <oldPassword> shall be the same as password specified for the facility from the MT
222      * user interface or with command Change Password +CPWD and <newPassword> is the new
223      * password
224      */
225     char *oldPassword;
226     char *newPassword;
227     /**
228      * Maximum length of the password for the facility
229      */
230     int32_t passwordLength;
231 } HRilSimPassword;
232 
233 /**
234  * @brief Defines the maximum number of SIM password attempts.
235  */
236 typedef struct {
237     char *code;
238     /**
239      * Number of remaining password attempts
240      */
241     int32_t times;
242     /**
243      * Number of remaining PUK attempts
244      */
245     int32_t pukTimes;
246     /**
247      * Number of remaining PIN attempts
248      */
249     int32_t pinTimes;
250     /**
251      * Number of remaining PUK2 attempts
252      */
253     int32_t puk2Times;
254     /**
255      * Number of remaining PIN2 attempts
256      */
257     int32_t pin2Times;
258 } HRilPinInputTimes;
259 
260 /**
261  * @brief Enumerates radio protocol phases.
262  */
263 typedef struct {
264     /**
265      * Session ID
266      */
267     int32_t sessionId;
268     /**
269      * Radio protocol parameters.
270      */
271     HRilRadioProtocolPhase phase;
272     /**
273      * Radio protocol technology:
274      */
275     int32_t technology;
276     /**
277      * Modem ID, corresponding to slotId at the bottom layer
278      */
279     int32_t modemId;
280     /**
281      * Radio protocol status.
282      */
283     HRilRadioProtocolStatus status;
284 } HRilRadioProtocol;
285 
286 /**
287  * @brief Defines the APDU data transmission request information.
288  */
289 typedef struct {
290     /**
291      * Channel ID
292      */
293     int32_t channelId;
294     /**
295      * APDU instruction type. For details, see ETSI 102 221 [55].
296      */
297     int32_t type;
298     /**
299      * APDU instruction. For details, see ETSI 102 221 [55].
300      */
301     int32_t instruction;
302     /**
303      * Command parameter 1 of the SIM data request. For details, see 3GPP TS 51.011[28].
304      */
305     int32_t p1;
306     /**
307      * Command parameter 2 of the SIM data request. For details, see 3GPP TS 51.011[28].
308      */
309     int32_t p2;
310     /**
311      * Command parameter 3 of the SIM data request. For details, see 3GPP TS 51.011[28].
312      * If p3 is a negative value, a 4-byte APDU is sent to the SIM card.
313      */
314     int32_t p3;
315     /**
316      * Data to be transmitted
317      */
318     char *data;
319 } HRilApduSimIO;
320 
321 /**
322  * @brief Defines the SIM card authentication request information.
323  */
324 typedef struct {
325     /**
326      * Request SN
327      */
328     int32_t serial;
329     /**
330      * App ID
331      */
332     char *aid;
333     /**
334      * Authentication data
335      */
336     char *data;
337 } HRilSimAuthenticationRequestInfo;
338 
339 /**
340  * @brief Defines ncfg request information.
341  */
342 typedef struct {
343     /**
344      * Operator Name Matched with SIM card
345      */
346     char *operName;
347     /**
348      * Operator Key Matched with SIM card
349      */
350     char *operKey;
351     /**
352      * Current SIM State
353      */
354     int state;
355     /**
356      * Reserved Field
357      */
358     char *reserve;
359 } HRilNcfgOperatorInfo;
360 
361 typedef struct {
362     void (*GetSimStatus)(const ReqDataInfo *requestInfo);
363     void (*GetSimIO)(const ReqDataInfo *requestInfo, const HRilSimIO *data, size_t dataLen);
364     void (*GetSimImsi)(const ReqDataInfo *requestInfo);
365     void (*GetSimLockStatus)(const ReqDataInfo *requestInfo, const HRilSimClock *data, size_t dataLen);
366     void (*SetSimLock)(const ReqDataInfo *requestInfo, const HRilSimClock *data, size_t dataLen);
367     void (*ChangeSimPassword)(const ReqDataInfo *requestInfo, const HRilSimPassword *data, size_t dataLen);
368     void (*UnlockPin)(const ReqDataInfo *requestInfo, const char *pin);
369     void (*UnlockPuk)(const ReqDataInfo *requestInfo, const char *puk, const char *pin);
370     void (*GetSimPinInputTimes)(const ReqDataInfo *requestInfo);
371     void (*UnlockPin2)(const ReqDataInfo *requestInfo, const char *pin2);
372     void (*UnlockPuk2)(const ReqDataInfo *requestInfo, const char *puk2, const char *pin2);
373     void (*GetSimPin2InputTimes)(const ReqDataInfo *requestInfo);
374     void (*SetActiveSim)(const ReqDataInfo *requestInfo, int32_t index, int32_t enable);
375     void (*SimStkSendTerminalResponse)(const ReqDataInfo *requestInfo, const char *strCmd);
376     void (*SimStkSendEnvelope)(const ReqDataInfo *requestInfo, const char *strCmd);
377     void (*SimStkSendEnvelopeResponseContainStatus)(const ReqDataInfo *requestInfo, const char *strCmd);
378     void (*SimStkSendCallSetupRequestResult)(const ReqDataInfo *requestInfo, int32_t accept);
379     void (*SimStkIsReady)(const ReqDataInfo *requestInfo);
380     void (*GetRadioProtocol)(const ReqDataInfo *requestInfo);
381     void (*SetRadioProtocol)(const ReqDataInfo *requestInfo, const HRilRadioProtocol *data);
382     void (*SimOpenLogicalChannel)(const ReqDataInfo *requestInfo, const char *appID, int32_t p2);
383     void (*SimCloseLogicalChannel)(const ReqDataInfo *requestInfo, int32_t channelId);
384     void (*SimTransmitApduLogicalChannel)(const ReqDataInfo *requestInfo, HRilApduSimIO *data, size_t dataLen);
385     void (*SimTransmitApduBasicChannel)(const ReqDataInfo *requestInfo, HRilApduSimIO *data, size_t dataLen);
386     void (*SimAuthentication)(const ReqDataInfo *requestInfo, HRilSimAuthenticationRequestInfo *data, size_t dataLen);
387     void (*UnlockSimLock)(const ReqDataInfo *requestInfo, int32_t lockType, const char *password);
388     void (*SendSimMatchedOperatorInfo)(const ReqDataInfo *requestInfo, HRilNcfgOperatorInfo *data, size_t dataLen);
389     /**
390      * @brief Set SIM card power state.
391      *
392      * @param requestInfo Request data info, for details, see {@link
393      * ReqDataInfo}.
394      * @param state The power state of SIM card to set, value as following:
395      * - 0 indicates CardPowerState#CARD_POWER_DOWN
396      * - 1 indicates CardPowerState#CARD_POWER_UP
397      * - 2 indicates CardPowerState#CARD_POWER_UP_PASS_THROUGH
398      * @see ReqDataInfo
399      */
400     void (*SetSimPowerState)(const ReqDataInfo *requestInfo, int32_t state);
401 } HRilSimReq;
402 #ifdef __cplusplus
403 }
404 #endif
405 #endif // OHOS_RIL_VENDOR_SIM_DEFS_H
406