cd2f1e38f5fde410c4a7ab7b88e4b365cafda88d
[platform/upstream/ofono.git] / include / sim.h
1 /*
2  *
3  *  oFono - Open Source Telephony
4  *
5  *  Copyright (C) 2008-2011  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
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.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifndef __OFONO_SIM_H
23 #define __OFONO_SIM_H
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include <ofono/types.h>
30
31 struct ofono_sim;
32 struct ofono_sim_context;
33
34 /* 51.011 Section 9.3 */
35 enum ofono_sim_file_structure {
36         OFONO_SIM_FILE_STRUCTURE_TRANSPARENT = 0,
37         OFONO_SIM_FILE_STRUCTURE_FIXED = 1,
38         OFONO_SIM_FILE_STRUCTURE_CYCLIC = 3
39 };
40
41 enum ofono_sim_password_type {
42         OFONO_SIM_PASSWORD_NONE = 0,
43         OFONO_SIM_PASSWORD_SIM_PIN,
44         OFONO_SIM_PASSWORD_PHSIM_PIN,
45         OFONO_SIM_PASSWORD_PHFSIM_PIN,
46         OFONO_SIM_PASSWORD_SIM_PIN2,
47         OFONO_SIM_PASSWORD_PHNET_PIN,
48         OFONO_SIM_PASSWORD_PHNETSUB_PIN,
49         OFONO_SIM_PASSWORD_PHSP_PIN,
50         OFONO_SIM_PASSWORD_PHCORP_PIN,
51         OFONO_SIM_PASSWORD_SIM_PUK,
52         OFONO_SIM_PASSWORD_PHFSIM_PUK,
53         OFONO_SIM_PASSWORD_SIM_PUK2,
54         OFONO_SIM_PASSWORD_PHNET_PUK,
55         OFONO_SIM_PASSWORD_PHNETSUB_PUK,
56         OFONO_SIM_PASSWORD_PHSP_PUK,
57         OFONO_SIM_PASSWORD_PHCORP_PUK,
58         OFONO_SIM_PASSWORD_INVALID,
59 };
60
61 enum ofono_sim_phase {
62         OFONO_SIM_PHASE_1G,
63         OFONO_SIM_PHASE_2G,
64         OFONO_SIM_PHASE_2G_PLUS,
65         OFONO_SIM_PHASE_3G,
66         OFONO_SIM_PHASE_UNKNOWN,
67 };
68
69 enum ofono_sim_cphs_phase {
70         OFONO_SIM_CPHS_PHASE_NONE,
71         OFONO_SIM_CPHS_PHASE_1G,
72         OFONO_SIM_CPHS_PHASE_2G,
73 };
74
75 enum ofono_sim_state {
76         OFONO_SIM_STATE_NOT_PRESENT,
77         OFONO_SIM_STATE_INSERTED,
78         OFONO_SIM_STATE_LOCKED_OUT,
79         OFONO_SIM_STATE_READY,
80 };
81
82 typedef void (*ofono_sim_file_info_cb_t)(const struct ofono_error *error,
83                                         int filelength,
84                                         enum ofono_sim_file_structure structure,
85                                         int recordlength,
86                                         const unsigned char access[3],
87                                         unsigned char file_status,
88                                         void *data);
89
90 typedef void (*ofono_sim_read_cb_t)(const struct ofono_error *error,
91                                         const unsigned char *sdata, int length,
92                                         void *data);
93
94 typedef void (*ofono_sim_write_cb_t)(const struct ofono_error *error,
95                                         void *data);
96
97 typedef void (*ofono_sim_iccid_cb_t)(const struct ofono_error *error,
98                                         const char *iccid, void *data);
99
100 typedef void (*ofono_sim_imsi_cb_t)(const struct ofono_error *error,
101                                         const char *imsi, void *data);
102
103 typedef void (*ofono_sim_state_event_cb_t)(enum ofono_sim_state new_state,
104                                         void *data);
105
106 typedef void (*ofono_sim_file_read_cb_t)(int ok, int total_length, int record,
107                                         const unsigned char *data,
108                                         int record_length, void *userdata);
109 typedef void (*ofono_sim_file_changed_cb_t)(int id, void *userdata);
110
111 typedef void (*ofono_sim_file_write_cb_t)(int ok, void *userdata);
112
113 typedef void (*ofono_sim_passwd_cb_t)(const struct ofono_error *error,
114                                         enum ofono_sim_password_type type,
115                                         void *data);
116
117 typedef void (*ofono_sim_pin_retries_cb_t)(const struct ofono_error *error,
118                         int retries[OFONO_SIM_PASSWORD_INVALID], void *data);
119
120 typedef void (*ofono_sim_lock_unlock_cb_t)(const struct ofono_error *error,
121                                         void *data);
122
123 typedef void (*ofono_sim_locked_cb_t)(const struct ofono_error *error,
124                                         int locked, void *data);
125
126 struct ofono_sim_driver {
127         const char *name;
128         int (*probe)(struct ofono_sim *sim, unsigned int vendor, void *data);
129         void (*remove)(struct ofono_sim *sim);
130         void (*read_file_info)(struct ofono_sim *sim, int fileid,
131                         ofono_sim_file_info_cb_t cb, void *data);
132         void (*read_file_transparent)(struct ofono_sim *sim, int fileid,
133                         int start, int length,
134                         ofono_sim_read_cb_t cb, void *data);
135         void (*read_file_linear)(struct ofono_sim *sim, int fileid,
136                         int record, int length,
137                         ofono_sim_read_cb_t cb, void *data);
138         void (*read_file_cyclic)(struct ofono_sim *sim, int fileid,
139                         int record, int length,
140                         ofono_sim_read_cb_t cb, void *data);
141         void (*write_file_transparent)(struct ofono_sim *sim, int fileid,
142                         int start, int length, const unsigned char *value,
143                         ofono_sim_write_cb_t cb, void *data);
144         void (*write_file_linear)(struct ofono_sim *sim, int fileid,
145                         int record, int length, const unsigned char *value,
146                         ofono_sim_write_cb_t cb, void *data);
147         void (*write_file_cyclic)(struct ofono_sim *sim, int fileid,
148                         int length, const unsigned char *value,
149                         ofono_sim_write_cb_t cb, void *data);
150         void (*read_iccid)(struct ofono_sim *sim,
151                         ofono_sim_iccid_cb_t cb, void *data);
152         void (*read_imsi)(struct ofono_sim *sim,
153                         ofono_sim_imsi_cb_t cb, void *data);
154         void (*query_passwd_state)(struct ofono_sim *sim,
155                         ofono_sim_passwd_cb_t cb, void *data);
156         void (*send_passwd)(struct ofono_sim *sim, const char *passwd,
157                         ofono_sim_lock_unlock_cb_t cb, void *data);
158         void (*query_pin_retries)(struct ofono_sim *sim,
159                                 ofono_sim_pin_retries_cb_t cb, void *data);
160         void (*reset_passwd)(struct ofono_sim *sim, const char *puk,
161                         const char *passwd,
162                         ofono_sim_lock_unlock_cb_t cb, void *data);
163         void (*change_passwd)(struct ofono_sim *sim,
164                         enum ofono_sim_password_type type,
165                         const char *old_passwd, const char *new_passwd,
166                         ofono_sim_lock_unlock_cb_t cb, void *data);
167         void (*lock)(struct ofono_sim *sim, enum ofono_sim_password_type type,
168                         int enable, const char *passwd,
169                         ofono_sim_lock_unlock_cb_t cb, void *data);
170         void (*query_locked)(struct ofono_sim *sim,
171                         enum ofono_sim_password_type type,
172                         ofono_sim_locked_cb_t cb, void *data);
173 };
174
175 int ofono_sim_driver_register(const struct ofono_sim_driver *d);
176 void ofono_sim_driver_unregister(const struct ofono_sim_driver *d);
177
178 struct ofono_sim *ofono_sim_create(struct ofono_modem *modem,
179                                         unsigned int vendor,
180                                         const char *driver, void *data);
181
182 void ofono_sim_register(struct ofono_sim *sim);
183 void ofono_sim_remove(struct ofono_sim *sim);
184
185 void ofono_sim_set_data(struct ofono_sim *sim, void *data);
186 void *ofono_sim_get_data(struct ofono_sim *sim);
187
188 const char *ofono_sim_get_imsi(struct ofono_sim *sim);
189 const char *ofono_sim_get_mcc(struct ofono_sim *sim);
190 const char *ofono_sim_get_mnc(struct ofono_sim *sim);
191 const char *ofono_sim_get_spn(struct ofono_sim *sim);
192 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);
193
194 enum ofono_sim_cphs_phase ofono_sim_get_cphs_phase(struct ofono_sim *sim);
195 const unsigned char *ofono_sim_get_cphs_service_table(struct ofono_sim *sim);
196
197 unsigned int ofono_sim_add_state_watch(struct ofono_sim *sim,
198                                         ofono_sim_state_event_cb_t cb,
199                                         void *data, ofono_destroy_func destroy);
200
201 void ofono_sim_remove_state_watch(struct ofono_sim *sim, unsigned int id);
202
203 enum ofono_sim_state ofono_sim_get_state(struct ofono_sim *sim);
204
205 typedef void (*ofono_sim_spn_cb_t)(const char *spn, const char *dc, void *data);
206
207 ofono_bool_t ofono_sim_add_spn_watch(struct ofono_sim *sim, unsigned int *id,
208                                         ofono_sim_spn_cb_t cb, void *data,
209                                         ofono_destroy_func destroy);
210
211 ofono_bool_t ofono_sim_remove_spn_watch(struct ofono_sim *sim, unsigned int *id);
212
213 void ofono_sim_inserted_notify(struct ofono_sim *sim, ofono_bool_t inserted);
214
215 struct ofono_sim_context *ofono_sim_context_create(struct ofono_sim *sim);
216 void ofono_sim_context_free(struct ofono_sim_context *context);
217
218 /* This will queue an operation to read all available records with id from the
219  * SIM.  Callback cb will be called every time a record has been read, or once
220  * if an error has occurred.  For transparent files, the callback will only
221  * be called once.
222  *
223  * Returns 0 if the request could be queued, -1 otherwise.
224  */
225 int ofono_sim_read(struct ofono_sim_context *context, int id,
226                         enum ofono_sim_file_structure expected,
227                         ofono_sim_file_read_cb_t cb, void *data);
228
229 int ofono_sim_write(struct ofono_sim_context *context, int id,
230                         ofono_sim_file_write_cb_t cb,
231                         enum ofono_sim_file_structure structure, int record,
232                         const unsigned char *data, int length, void *userdata);
233
234 int ofono_sim_read_bytes(struct ofono_sim_context *context, int id,
235                         unsigned short offset, unsigned short num_bytes,
236                         ofono_sim_file_read_cb_t cb, void *data);
237
238 unsigned int ofono_sim_add_file_watch(struct ofono_sim_context *context,
239                                         int id, ofono_sim_file_changed_cb_t cb,
240                                         void *userdata,
241                                         ofono_destroy_func destroy);
242 void ofono_sim_remove_file_watch(struct ofono_sim_context *context,
243                                         unsigned int id);
244
245 #ifdef __cplusplus
246 }
247 #endif
248
249 #endif /* __OFONO_SIM_H */