3 * oFono - Open Source Telephony
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
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.
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
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
29 #include <ofono/types.h>
32 struct ofono_sim_context;
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
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,
61 enum ofono_sim_phase {
64 OFONO_SIM_PHASE_2G_PLUS,
66 OFONO_SIM_PHASE_UNKNOWN,
69 enum ofono_sim_cphs_phase {
70 OFONO_SIM_CPHS_PHASE_NONE,
71 OFONO_SIM_CPHS_PHASE_1G,
72 OFONO_SIM_CPHS_PHASE_2G,
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,
82 typedef void (*ofono_sim_file_info_cb_t)(const struct ofono_error *error,
84 enum ofono_sim_file_structure structure,
86 const unsigned char access[3],
87 unsigned char file_status,
90 typedef void (*ofono_sim_read_cb_t)(const struct ofono_error *error,
91 const unsigned char *sdata, int length,
94 typedef void (*ofono_sim_write_cb_t)(const struct ofono_error *error,
97 typedef void (*ofono_sim_iccid_cb_t)(const struct ofono_error *error,
98 const char *iccid, void *data);
100 typedef void (*ofono_sim_imsi_cb_t)(const struct ofono_error *error,
101 const char *imsi, void *data);
103 typedef void (*ofono_sim_state_event_cb_t)(enum ofono_sim_state new_state,
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);
111 typedef void (*ofono_sim_file_write_cb_t)(int ok, void *userdata);
113 typedef void (*ofono_sim_passwd_cb_t)(const struct ofono_error *error,
114 enum ofono_sim_password_type type,
117 typedef void (*ofono_sim_pin_retries_cb_t)(const struct ofono_error *error,
118 int retries[OFONO_SIM_PASSWORD_INVALID], void *data);
120 typedef void (*ofono_sim_lock_unlock_cb_t)(const struct ofono_error *error,
123 typedef void (*ofono_sim_locked_cb_t)(const struct ofono_error *error,
124 int locked, void *data);
126 struct ofono_sim_driver {
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,
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);
175 int ofono_sim_driver_register(const struct ofono_sim_driver *d);
176 void ofono_sim_driver_unregister(const struct ofono_sim_driver *d);
178 struct ofono_sim *ofono_sim_create(struct ofono_modem *modem,
180 const char *driver, void *data);
182 void ofono_sim_register(struct ofono_sim *sim);
183 void ofono_sim_remove(struct ofono_sim *sim);
185 void ofono_sim_set_data(struct ofono_sim *sim, void *data);
186 void *ofono_sim_get_data(struct ofono_sim *sim);
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);
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);
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);
201 void ofono_sim_remove_state_watch(struct ofono_sim *sim, unsigned int id);
203 enum ofono_sim_state ofono_sim_get_state(struct ofono_sim *sim);
205 typedef void (*ofono_sim_spn_cb_t)(const char *spn, const char *dc, void *data);
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);
211 ofono_bool_t ofono_sim_remove_spn_watch(struct ofono_sim *sim, unsigned int *id);
213 void ofono_sim_inserted_notify(struct ofono_sim *sim, ofono_bool_t inserted);
215 struct ofono_sim_context *ofono_sim_context_create(struct ofono_sim *sim);
216 void ofono_sim_context_free(struct ofono_sim_context *context);
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
223 * Returns 0 if the request could be queued, -1 otherwise.
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);
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);
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);
238 unsigned int ofono_sim_add_file_watch(struct ofono_sim_context *context,
239 int id, ofono_sim_file_changed_cb_t cb,
241 ofono_destroy_func destroy);
242 void ofono_sim_remove_file_watch(struct ofono_sim_context *context,
249 #endif /* __OFONO_SIM_H */