sim: Revert adding special callback for EFiccid
[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_imsi_cb_t)(const struct ofono_error *error,
98                                         const char *imsi, void *data);
99
100 typedef void (*ofono_sim_state_event_cb_t)(enum ofono_sim_state new_state,
101                                         void *data);
102
103 typedef void (*ofono_sim_file_read_cb_t)(int ok, int total_length, int record,
104                                         const unsigned char *data,
105                                         int record_length, void *userdata);
106 typedef void (*ofono_sim_file_changed_cb_t)(int id, void *userdata);
107
108 typedef void (*ofono_sim_file_write_cb_t)(int ok, void *userdata);
109
110 typedef void (*ofono_sim_passwd_cb_t)(const struct ofono_error *error,
111                                         enum ofono_sim_password_type type,
112                                         void *data);
113
114 typedef void (*ofono_sim_pin_retries_cb_t)(const struct ofono_error *error,
115                         int retries[OFONO_SIM_PASSWORD_INVALID], void *data);
116
117 typedef void (*ofono_sim_lock_unlock_cb_t)(const struct ofono_error *error,
118                                         void *data);
119
120 typedef void (*ofono_sim_locked_cb_t)(const struct ofono_error *error,
121                                         int locked, void *data);
122
123 struct ofono_sim_driver {
124         const char *name;
125         int (*probe)(struct ofono_sim *sim, unsigned int vendor, void *data);
126         void (*remove)(struct ofono_sim *sim);
127         void (*read_file_info)(struct ofono_sim *sim, int fileid,
128                         ofono_sim_file_info_cb_t cb, void *data);
129         void (*read_file_transparent)(struct ofono_sim *sim, int fileid,
130                         int start, int length,
131                         ofono_sim_read_cb_t cb, void *data);
132         void (*read_file_linear)(struct ofono_sim *sim, int fileid,
133                         int record, int length,
134                         ofono_sim_read_cb_t cb, void *data);
135         void (*read_file_cyclic)(struct ofono_sim *sim, int fileid,
136                         int record, int length,
137                         ofono_sim_read_cb_t cb, void *data);
138         void (*write_file_transparent)(struct ofono_sim *sim, int fileid,
139                         int start, int length, const unsigned char *value,
140                         ofono_sim_write_cb_t cb, void *data);
141         void (*write_file_linear)(struct ofono_sim *sim, int fileid,
142                         int record, int length, const unsigned char *value,
143                         ofono_sim_write_cb_t cb, void *data);
144         void (*write_file_cyclic)(struct ofono_sim *sim, int fileid,
145                         int length, const unsigned char *value,
146                         ofono_sim_write_cb_t cb, void *data);
147         void (*read_imsi)(struct ofono_sim *sim,
148                         ofono_sim_imsi_cb_t cb, void *data);
149         void (*query_passwd_state)(struct ofono_sim *sim,
150                         ofono_sim_passwd_cb_t cb, void *data);
151         void (*send_passwd)(struct ofono_sim *sim, const char *passwd,
152                         ofono_sim_lock_unlock_cb_t cb, void *data);
153         void (*query_pin_retries)(struct ofono_sim *sim,
154                                 ofono_sim_pin_retries_cb_t cb, void *data);
155         void (*reset_passwd)(struct ofono_sim *sim, const char *puk,
156                         const char *passwd,
157                         ofono_sim_lock_unlock_cb_t cb, void *data);
158         void (*change_passwd)(struct ofono_sim *sim,
159                         enum ofono_sim_password_type type,
160                         const char *old_passwd, const char *new_passwd,
161                         ofono_sim_lock_unlock_cb_t cb, void *data);
162         void (*lock)(struct ofono_sim *sim, enum ofono_sim_password_type type,
163                         int enable, const char *passwd,
164                         ofono_sim_lock_unlock_cb_t cb, void *data);
165         void (*query_locked)(struct ofono_sim *sim,
166                         enum ofono_sim_password_type type,
167                         ofono_sim_locked_cb_t cb, void *data);
168 };
169
170 int ofono_sim_driver_register(const struct ofono_sim_driver *d);
171 void ofono_sim_driver_unregister(const struct ofono_sim_driver *d);
172
173 struct ofono_sim *ofono_sim_create(struct ofono_modem *modem,
174                                         unsigned int vendor,
175                                         const char *driver, void *data);
176
177 void ofono_sim_register(struct ofono_sim *sim);
178 void ofono_sim_remove(struct ofono_sim *sim);
179
180 void ofono_sim_set_data(struct ofono_sim *sim, void *data);
181 void *ofono_sim_get_data(struct ofono_sim *sim);
182
183 const char *ofono_sim_get_imsi(struct ofono_sim *sim);
184 const char *ofono_sim_get_mcc(struct ofono_sim *sim);
185 const char *ofono_sim_get_mnc(struct ofono_sim *sim);
186 const char *ofono_sim_get_spn(struct ofono_sim *sim);
187 enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);
188
189 enum ofono_sim_cphs_phase ofono_sim_get_cphs_phase(struct ofono_sim *sim);
190 const unsigned char *ofono_sim_get_cphs_service_table(struct ofono_sim *sim);
191
192 unsigned int ofono_sim_add_state_watch(struct ofono_sim *sim,
193                                         ofono_sim_state_event_cb_t cb,
194                                         void *data, ofono_destroy_func destroy);
195
196 void ofono_sim_remove_state_watch(struct ofono_sim *sim, unsigned int id);
197
198 enum ofono_sim_state ofono_sim_get_state(struct ofono_sim *sim);
199
200 typedef void (*ofono_sim_spn_cb_t)(const char *spn, const char *dc, void *data);
201
202 ofono_bool_t ofono_sim_add_spn_watch(struct ofono_sim *sim, unsigned int *id,
203                                         ofono_sim_spn_cb_t cb, void *data,
204                                         ofono_destroy_func destroy);
205
206 ofono_bool_t ofono_sim_remove_spn_watch(struct ofono_sim *sim, unsigned int *id);
207
208 void ofono_sim_inserted_notify(struct ofono_sim *sim, ofono_bool_t inserted);
209
210 struct ofono_sim_context *ofono_sim_context_create(struct ofono_sim *sim);
211 void ofono_sim_context_free(struct ofono_sim_context *context);
212
213 /* This will queue an operation to read all available records with id from the
214  * SIM.  Callback cb will be called every time a record has been read, or once
215  * if an error has occurred.  For transparent files, the callback will only
216  * be called once.
217  *
218  * Returns 0 if the request could be queued, -1 otherwise.
219  */
220 int ofono_sim_read(struct ofono_sim_context *context, int id,
221                         enum ofono_sim_file_structure expected,
222                         ofono_sim_file_read_cb_t cb, void *data);
223
224 int ofono_sim_write(struct ofono_sim_context *context, int id,
225                         ofono_sim_file_write_cb_t cb,
226                         enum ofono_sim_file_structure structure, int record,
227                         const unsigned char *data, int length, void *userdata);
228
229 int ofono_sim_read_bytes(struct ofono_sim_context *context, int id,
230                         unsigned short offset, unsigned short num_bytes,
231                         ofono_sim_file_read_cb_t cb, void *data);
232
233 unsigned int ofono_sim_add_file_watch(struct ofono_sim_context *context,
234                                         int id, ofono_sim_file_changed_cb_t cb,
235                                         void *userdata,
236                                         ofono_destroy_func destroy);
237 void ofono_sim_remove_file_watch(struct ofono_sim_context *context,
238                                         unsigned int id);
239
240 #ifdef __cplusplus
241 }
242 #endif
243
244 #endif /* __OFONO_SIM_H */