2 * (C) 2010 by Andreas Eversberg <jolly@eversberg.eu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #define GSM1111_CLASS_GSM 0xa0
25 #define GSM1111_INST_SELECT 0xa4
26 #define GSM1111_INST_STATUS 0xf2
27 #define GSM1111_INST_READ_BINARY 0xb0
28 #define GSM1111_INST_UPDATE_BINARY 0xd6
29 #define GSM1111_INST_READ_RECORD 0xb2
30 #define GSM1111_INST_UPDATE_RECORD 0xdc
31 #define GSM1111_INST_SEEK 0xa2
32 #define GSM1111_INST_INCREASE 0x32
33 #define GSM1111_INST_VERIFY_CHV 0x20
34 #define GSM1111_INST_CHANGE_CHV 0x24
35 #define GSM1111_INST_DISABLE_CHV 0x26
36 #define GSM1111_INST_ENABLE_CHV 0x28
37 #define GSM1111_INST_UNBLOCK_CHV 0x2c
38 #define GSM1111_INST_INVALIDATE 0x04
39 #define GSM1111_INST_REHABLILITATE 0x44
40 #define GSM1111_INST_RUN_GSM_ALGO 0x88
41 #define GSM1111_INST_SLEEP 0xfa
42 #define GSM1111_INST_GET_RESPONSE 0xc0
43 #define GSM1111_INST_TERMINAL_PROFILE 0x10
44 #define GSM1111_INST_ENVELOPE 0xc2
45 #define GSM1111_INST_FETCH 0x12
46 #define GSM1111_INST_TERMINAL_RESPONSE 0x14
48 /* 9.3 access conditions */
49 #define GSM1111_ACC_ALWAYS 0x0
50 #define GSM1111_ACC_CHV1 0x1
51 #define GSM1111_ACC_CHV2 0x2
52 #define GSM1111_ACC_RFU 0x3
53 #define GSM1111_ACC_NEW 0xf
56 /* 9.3 type of file */
57 #define GSM1111_TOF_RFU 0x00
58 #define GSM1111_TOF_MF 0x01
59 #define GSM1111_TOF_DF 0x02
60 #define GSM1111_TOF_EF 0x04
62 /* 9.3 struct of file */
63 #define GSM1111_SOF_TRANSPARENT 0x00
64 #define GSM1111_SOF_LINEAR 0x01
65 #define GSM1111_SOF_CYCLIC 0x03
68 #define GSM1111_STAT_NORMAL 0x90
69 #define GSM1111_STAT_PROACTIVE 0x91
70 #define GSM1111_STAT_DL_ERROR 0x9e
71 #define GSM1111_STAT_RESPONSE 0x9f
72 #define GSM1111_STAT_RESPONSE_TOO 0x61
73 #define GSM1111_STAT_APP_TK_BUSY 0x93
74 #define GSM1111_STAT_MEM_PROBLEM 0x92
75 #define GSM1111_STAT_REFERENCING 0x94
76 #define GSM1111_STAT_SECURITY 0x98
77 #define GSM1111_STAT_INCORR_P3 0x67
78 #define GSM1111_STAT_INCORR_P1_P2 0x6b
79 #define GSM1111_STAT_UKN_INST 0x6d
80 #define GSM1111_STAT_WRONG_CLASS 0x6e
81 #define GSM1111_STAT_TECH_PROBLEM 0x6f
83 /* 9.4.4 Referencing management SW2 */
84 #define GSM1111_REF_NO_EF 0x00
85 #define GSM1111_REF_OUT_OF_RANGE 0x02
86 #define GSM1111_REF_FILE_NOT_FOUND 0x04
87 #define GSM1111_REF_FILE_INCONSI 0x08
89 /* 9.4.5 Security management SW2 */
90 #define GSM1111_SEC_NO_CHV 0x02
91 #define GSM1111_SEC_NO_ACCESS 0x04
92 #define GSM1111_SEC_CONTRA_CHV 0x08
93 #define GSM1111_SEC_CONTRA_INVAL 0x10
94 #define GSM1111_SEC_BLOCKED 0x40
95 #define GSM1111_SEC_MAX_VALUE 0x50
97 /* messages from application to sim client */
101 SIM_JOB_UPDATE_BINARY,
103 SIM_JOB_UPDATE_RECORD,
107 SIM_JOB_REHABILITATE,
108 SIM_JOB_RUN_GSM_ALGO,
111 SIM_JOB_PIN1_DISABLE,
113 SIM_JOB_PIN1_UNBLOCK,
116 SIM_JOB_PIN2_UNBLOCK,
123 /* messages from sim client to application */
125 #define SIM_JOB_ERROR 1
128 #define SIM_CAUSE_NO_SIM 0 /* no SIM present, if detectable */
129 #define SIM_CAUSE_SIM_ERROR 1 /* any error while reading SIM */
130 #define SIM_CAUSE_REQUEST_ERROR 2 /* error in request */
131 #define SIM_CAUSE_PIN1_REQUIRED 3 /* CHV1 is required for access */
132 #define SIM_CAUSE_PIN2_REQUIRED 4 /* CHV2 is required for access */
133 #define SIM_CAUSE_PIN1_BLOCKED 5 /* CHV1 was entered too many times */
134 #define SIM_CAUSE_PIN2_BLOCKED 6 /* CHV2 was entered too many times */
135 #define SIM_CAUSE_PUC_BLOCKED 7 /* unblock entered too many times */
140 SIM_JST_SELECT_MFDF, /* SELECT sent */
141 SIM_JST_SELECT_MFDF_RESP, /* GET RESPONSE sent */
142 SIM_JST_SELECT_EF, /* SELECT sent */
143 SIM_JST_SELECT_EF_RESP, /* GET RESPONSE sent */
144 SIM_JST_WAIT_FILE, /* file command sent */
145 SIM_JST_RUN_GSM_ALGO, /* wait for algorithm to process */
146 SIM_JST_RUN_GSM_ALGO_RESP, /* wait for response */
149 SIM_JST_PIN1_DISABLE,
151 SIM_JST_PIN1_UNBLOCK,
154 SIM_JST_PIN2_UNBLOCK,
157 #define MAX_SIM_PATH_LENGTH 6 + 1 /* one for the termination */
159 struct gsm_sim_handler {
160 struct llist_head entry;
163 void (*cb)(struct osmocom_ms *ms, struct msgb *msg);
167 struct llist_head handlers; /* gsm_sim_handler */
168 struct llist_head jobs; /* messages */
169 uint16_t path[MAX_SIM_PATH_LENGTH];
172 struct msgb *job_msg;
177 uint8_t chv1_remain, chv2_remain;
178 uint8_t unblk1_remain, unblk2_remain;
184 uint16_t path[MAX_SIM_PATH_LENGTH];
186 uint8_t rec_no, rec_mode; /* in case of record */
187 uint8_t seek_type_mode; /* in case of seek command */
190 #define SIM_ALLOC_SIZE 512
191 #define SIM_ALLOC_HEADROOM 64
193 struct msgb *gsm_sim_msgb_alloc(uint32_t handle, uint8_t job_type);
194 uint32_t sim_open(struct osmocom_ms *ms,
195 void (*cb)(struct osmocom_ms *ms, struct msgb *msg));
196 void sim_close(struct osmocom_ms *ms, uint32_t handle);
197 void sim_job(struct osmocom_ms *ms, struct msgb *msg);
199 /* Section 9.2.1 (response to selecting DF or MF) */
200 struct gsm1111_response_mfdf {
208 } __attribute__ ((packed));
210 struct gsm1111_response_mfdf_gsm {
216 uint8_t chv1_remain:4,
219 uint8_t unblk1_remain:4,
222 uint8_t chv2_remain:4,
225 uint8_t unblk2_remain:4,
228 uint8_t more_data[0];
229 } __attribute__ ((packed));
231 /* Section 9.2.1 (response to selecting EF) */
232 struct gsm1111_response_ef {
238 uint8_t acc_update:4,
250 } __attribute__ ((packed));
252 /* Section 10.3.17 */
253 struct gsm1111_ef_loci {
255 struct gsm48_loc_area_id lai;
258 } __attribute__ ((packed));
261 struct gsm1111_ef_adn {
267 } __attribute__ ((packed));
269 int sim_apdu_resp(struct osmocom_ms *ms, struct msgb *msg);
270 int gsm_sim_init(struct osmocom_ms *ms);
271 int gsm_sim_exit(struct osmocom_ms *ms);
272 int gsm_sim_job_dequeue(struct osmocom_ms *ms);