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_imsi_cb_t)(const struct ofono_error *error,
98 const char *imsi, void *data);
100 typedef void (*ofono_sim_state_event_cb_t)(enum ofono_sim_state new_state,
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);
108 typedef void (*ofono_sim_file_write_cb_t)(int ok, void *userdata);
110 typedef void (*ofono_sim_passwd_cb_t)(const struct ofono_error *error,
111 enum ofono_sim_password_type type,
114 typedef void (*ofono_sim_pin_retries_cb_t)(const struct ofono_error *error,
115 int retries[OFONO_SIM_PASSWORD_INVALID], void *data);
117 typedef void (*ofono_sim_lock_unlock_cb_t)(const struct ofono_error *error,
120 typedef void (*ofono_sim_locked_cb_t)(const struct ofono_error *error,
121 int locked, void *data);
123 struct ofono_sim_driver {
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,
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);
170 int ofono_sim_driver_register(const struct ofono_sim_driver *d);
171 void ofono_sim_driver_unregister(const struct ofono_sim_driver *d);
173 struct ofono_sim *ofono_sim_create(struct ofono_modem *modem,
175 const char *driver, void *data);
177 void ofono_sim_register(struct ofono_sim *sim);
178 void ofono_sim_remove(struct ofono_sim *sim);
180 void ofono_sim_set_data(struct ofono_sim *sim, void *data);
181 void *ofono_sim_get_data(struct ofono_sim *sim);
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);
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);
192 enum ofono_sim_password_type ofono_sim_get_password_type(struct ofono_sim *sim);
194 unsigned int ofono_sim_add_state_watch(struct ofono_sim *sim,
195 ofono_sim_state_event_cb_t cb,
196 void *data, ofono_destroy_func destroy);
198 void ofono_sim_remove_state_watch(struct ofono_sim *sim, unsigned int id);
200 enum ofono_sim_state ofono_sim_get_state(struct ofono_sim *sim);
202 typedef void (*ofono_sim_spn_cb_t)(const char *spn, const char *dc, void *data);
204 ofono_bool_t ofono_sim_add_spn_watch(struct ofono_sim *sim, unsigned int *id,
205 ofono_sim_spn_cb_t cb, void *data,
206 ofono_destroy_func destroy);
208 ofono_bool_t ofono_sim_remove_spn_watch(struct ofono_sim *sim, unsigned int *id);
210 void ofono_sim_inserted_notify(struct ofono_sim *sim, ofono_bool_t inserted);
212 struct ofono_sim_context *ofono_sim_context_create(struct ofono_sim *sim);
213 void ofono_sim_context_free(struct ofono_sim_context *context);
215 /* This will queue an operation to read all available records with id from the
216 * SIM. Callback cb will be called every time a record has been read, or once
217 * if an error has occurred. For transparent files, the callback will only
220 * Returns 0 if the request could be queued, -1 otherwise.
222 int ofono_sim_read(struct ofono_sim_context *context, int id,
223 enum ofono_sim_file_structure expected,
224 ofono_sim_file_read_cb_t cb, void *data);
226 int ofono_sim_write(struct ofono_sim_context *context, int id,
227 ofono_sim_file_write_cb_t cb,
228 enum ofono_sim_file_structure structure, int record,
229 const unsigned char *data, int length, void *userdata);
231 int ofono_sim_read_bytes(struct ofono_sim_context *context, int id,
232 unsigned short offset, unsigned short num_bytes,
233 ofono_sim_file_read_cb_t cb, void *data);
235 unsigned int ofono_sim_add_file_watch(struct ofono_sim_context *context,
236 int id, ofono_sim_file_changed_cb_t cb,
238 ofono_destroy_func destroy);
239 void ofono_sim_remove_file_watch(struct ofono_sim_context *context,
246 #endif /* __OFONO_SIM_H */