sim.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. #ifndef __OFONO_SIM_H
  22. #define __OFONO_SIM_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. #include <ofono/types.h>
  27. struct ofono_sim;
  28. struct ofono_sim_context;
  29. /* 51.011 Section 9.3 */
  30. enum ofono_sim_file_structure {
  31. OFONO_SIM_FILE_STRUCTURE_TRANSPARENT = 0,
  32. OFONO_SIM_FILE_STRUCTURE_FIXED = 1,
  33. OFONO_SIM_FILE_STRUCTURE_CYCLIC = 3
  34. };
  35. enum ofono_sim_password_type {
  36. OFONO_SIM_PASSWORD_NONE = 0,
  37. OFONO_SIM_PASSWORD_SIM_PIN,
  38. OFONO_SIM_PASSWORD_PHSIM_PIN,
  39. OFONO_SIM_PASSWORD_PHFSIM_PIN,
  40. OFONO_SIM_PASSWORD_SIM_PIN2,
  41. OFONO_SIM_PASSWORD_PHNET_PIN,
  42. OFONO_SIM_PASSWORD_PHNETSUB_PIN,
  43. OFONO_SIM_PASSWORD_PHSP_PIN,
  44. OFONO_SIM_PASSWORD_PHCORP_PIN,
  45. OFONO_SIM_PASSWORD_SIM_PUK,
  46. OFONO_SIM_PASSWORD_PHFSIM_PUK,
  47. OFONO_SIM_PASSWORD_SIM_PUK2,
  48. OFONO_SIM_PASSWORD_PHNET_PUK,
  49. OFONO_SIM_PASSWORD_PHNETSUB_PUK,
  50. OFONO_SIM_PASSWORD_PHSP_PUK,
  51. OFONO_SIM_PASSWORD_PHCORP_PUK,
  52. OFONO_SIM_PASSWORD_INVALID,
  53. };
  54. enum ofono_sim_phase {
  55. OFONO_SIM_PHASE_1G,
  56. OFONO_SIM_PHASE_2G,
  57. OFONO_SIM_PHASE_2G_PLUS,
  58. OFONO_SIM_PHASE_3G,
  59. OFONO_SIM_PHASE_UNKNOWN,
  60. };
  61. enum ofono_sim_cphs_phase {
  62. OFONO_SIM_CPHS_PHASE_NONE,
  63. OFONO_SIM_CPHS_PHASE_1G,
  64. OFONO_SIM_CPHS_PHASE_2G,
  65. };
  66. enum ofono_sim_state {
  67. OFONO_SIM_STATE_NOT_PRESENT,
  68. OFONO_SIM_STATE_INSERTED,
  69. OFONO_SIM_STATE_LOCKED_OUT,
  70. OFONO_SIM_STATE_READY,
  71. OFONO_SIM_STATE_RESETTING,
  72. };
  73. typedef void (*ofono_sim_file_info_cb_t)(const struct ofono_error *error,
  74. int filelength,
  75. enum ofono_sim_file_structure structure,
  76. int recordlength,
  77. const unsigned char access[3],
  78. unsigned char file_status,
  79. void *data);
  80. typedef void (*ofono_sim_read_cb_t)(const struct ofono_error *error,
  81. const unsigned char *sdata, int length,
  82. void *data);
  83. typedef void (*ofono_sim_write_cb_t)(const struct ofono_error *error,
  84. void *data);
  85. typedef void (*ofono_sim_imsi_cb_t)(const struct ofono_error *error,
  86. const char *imsi, void *data);
  87. typedef void (*ofono_sim_state_event_cb_t)(enum ofono_sim_state new_state,
  88. void *data);
  89. typedef void (*ofono_sim_file_read_cb_t)(int ok, int total_length, int record,
  90. const unsigned char *data,
  91. int record_length, void *userdata);
  92. typedef void (*ofono_sim_file_changed_cb_t)(int id, void *userdata);
  93. typedef void (*ofono_sim_file_write_cb_t)(int ok, void *userdata);
  94. typedef void (*ofono_sim_passwd_cb_t)(const struct ofono_error *error,
  95. enum ofono_sim_password_type type,
  96. void *data);
  97. typedef void (*ofono_sim_pin_retries_cb_t)(const struct ofono_error *error,
  98. int retries[OFONO_SIM_PASSWORD_INVALID], void *data);
  99. typedef void (*ofono_sim_lock_unlock_cb_t)(const struct ofono_error *error,
  100. void *data);
  101. typedef void (*ofono_query_facility_lock_cb_t)(const struct ofono_error *error,
  102. ofono_bool_t status, void *data);
  103. struct ofono_sim_driver {
  104. const char *name;
  105. int (*probe)(struct ofono_sim *sim, unsigned int vendor, void *data);
  106. void (*remove)(struct ofono_sim *sim);
  107. void (*read_file_info)(struct ofono_sim *sim, int fileid,
  108. const unsigned char *path, unsigned int path_len,
  109. ofono_sim_file_info_cb_t cb, void *data);
  110. void (*read_file_transparent)(struct ofono_sim *sim, int fileid,
  111. int start, int length,
  112. const unsigned char *path, unsigned int path_len,
  113. ofono_sim_read_cb_t cb, void *data);
  114. void (*read_file_linear)(struct ofono_sim *sim, int fileid,
  115. int record, int length,
  116. const unsigned char *path, unsigned int path_len,
  117. ofono_sim_read_cb_t cb, void *data);
  118. void (*read_file_cyclic)(struct ofono_sim *sim, int fileid,
  119. int record, int length,
  120. const unsigned char *path, unsigned int path_len,
  121. ofono_sim_read_cb_t cb, void *data);
  122. void (*write_file_transparent)(struct ofono_sim *sim, int fileid,
  123. int start, int length, const unsigned char *value,
  124. const unsigned char *path, unsigned int path_len,
  125. ofono_sim_write_cb_t cb, void *data);
  126. void (*write_file_linear)(struct ofono_sim *sim, int fileid,
  127. int record, int length, const unsigned char *value,
  128. const unsigned char *path, unsigned int path_len,
  129. ofono_sim_write_cb_t cb, void *data);
  130. void (*write_file_cyclic)(struct ofono_sim *sim, int fileid,
  131. int length, const unsigned char *value,
  132. const unsigned char *path, unsigned int path_len,
  133. ofono_sim_write_cb_t cb, void *data);
  134. void (*read_imsi)(struct ofono_sim *sim,
  135. ofono_sim_imsi_cb_t cb, void *data);
  136. void (*query_passwd_state)(struct ofono_sim *sim,
  137. ofono_sim_passwd_cb_t cb, void *data);
  138. void (*send_passwd)(struct ofono_sim *sim, const char *passwd,
  139. ofono_sim_lock_unlock_cb_t cb, void *data);
  140. void (*query_pin_retries)(struct ofono_sim *sim,
  141. ofono_sim_pin_retries_cb_t cb, void *data);
  142. void (*reset_passwd)(struct ofono_sim *sim, const char *puk,
  143. const char *passwd,
  144. ofono_sim_lock_unlock_cb_t cb, void *data);
  145. void (*change_passwd)(struct ofono_sim *sim,
  146. enum ofono_sim_password_type type,
  147. const char *old_passwd, const char *new_passwd,
  148. ofono_sim_lock_unlock_cb_t cb, void *data);
  149. void (*lock)(struct ofono_sim *sim, enum ofono_sim_password_type type,
  150. int enable, const char *passwd,
  151. ofono_sim_lock_unlock_cb_t cb, void *data);
  152. void (*query_facility_lock)(struct ofono_sim *sim,
  153. enum ofono_sim_password_type lock,
  154. ofono_query_facility_lock_cb_t cb, void *data);
  155. };
  156. int ofono_sim_driver_register(const struct ofono_sim_driver *d);
  157. void ofono_sim_driver_unregister(const struct ofono_sim_driver *d);
  158. struct ofono_sim *ofono_sim_create(struct ofono_modem *modem,
  159. unsigned int vendor,
  160. const char *driver, void *data);
  161. void ofono_sim_register(struct ofono_sim *sim);
  162. void ofono_sim_remove(struct ofono_sim *sim);
  163. void ofono_sim_set_data(struct ofono_sim *sim, void *data);
  164. void *ofono_sim_get_data(struct ofono_sim *sim);
  165. const char *ofono_sim_get_imsi(struct ofono_sim *sim);
  166. const char *ofono_sim_get_mcc(struct ofono_sim *sim);
  167. const char *ofono_sim_get_mnc(struct ofono_sim *sim);
  168. const char *ofono_sim_get_spn(struct ofono_sim *sim);
  169. enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);
  170. enum ofono_sim_cphs_phase ofono_sim_get_cphs_phase(struct ofono_sim *sim);
  171. const unsigned char *ofono_sim_get_cphs_service_table(struct ofono_sim *sim);
  172. enum ofono_sim_password_type ofono_sim_get_password_type(struct ofono_sim *sim);
  173. unsigned int ofono_sim_add_state_watch(struct ofono_sim *sim,
  174. ofono_sim_state_event_cb_t cb,
  175. void *data, ofono_destroy_func destroy);
  176. void ofono_sim_remove_state_watch(struct ofono_sim *sim, unsigned int id);
  177. enum ofono_sim_state ofono_sim_get_state(struct ofono_sim *sim);
  178. typedef void (*ofono_sim_spn_cb_t)(const char *spn, const char *dc, void *data);
  179. ofono_bool_t ofono_sim_add_spn_watch(struct ofono_sim *sim, unsigned int *id,
  180. ofono_sim_spn_cb_t cb, void *data,
  181. ofono_destroy_func destroy);
  182. ofono_bool_t ofono_sim_remove_spn_watch(struct ofono_sim *sim, unsigned int *id);
  183. void ofono_sim_inserted_notify(struct ofono_sim *sim, ofono_bool_t inserted);
  184. struct ofono_sim_context *ofono_sim_context_create(struct ofono_sim *sim);
  185. void ofono_sim_context_free(struct ofono_sim_context *context);
  186. /* This will queue an operation to read all available records with id from the
  187. * SIM. Callback cb will be called every time a record has been read, or once
  188. * if an error has occurred. For transparent files, the callback will only
  189. * be called once.
  190. *
  191. * Returns 0 if the request could be queued, -1 otherwise.
  192. */
  193. int ofono_sim_read(struct ofono_sim_context *context, int id,
  194. enum ofono_sim_file_structure expected,
  195. ofono_sim_file_read_cb_t cb, void *data);
  196. int ofono_sim_write(struct ofono_sim_context *context, int id,
  197. ofono_sim_file_write_cb_t cb,
  198. enum ofono_sim_file_structure structure, int record,
  199. const unsigned char *data, int length, void *userdata);
  200. int ofono_sim_read_bytes(struct ofono_sim_context *context, int id,
  201. unsigned short offset, unsigned short num_bytes,
  202. const unsigned char *path, unsigned int path_len,
  203. ofono_sim_file_read_cb_t cb, void *data);
  204. unsigned int ofono_sim_add_file_watch(struct ofono_sim_context *context,
  205. int id, ofono_sim_file_changed_cb_t cb,
  206. void *userdata,
  207. ofono_destroy_func destroy);
  208. void ofono_sim_remove_file_watch(struct ofono_sim_context *context,
  209. unsigned int id);
  210. #ifdef __cplusplus
  211. }
  212. #endif
  213. #endif /* __OFONO_SIM_H */