Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 3 | #include <stdbool.h> |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 4 | #include <sqlite3.h> |
| 5 | |
| 6 | enum stmt_idx { |
| 7 | SEL_BY_IMSI = 0, |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 8 | UPD_VLR_BY_ID = 1, |
| 9 | UPD_SGSN_BY_ID = 2, |
| 10 | AUC_BY_IMSI = 3, |
| 11 | AUC_UPD_SQN = 4, |
Harald Welte | b18f0e0 | 2016-05-05 21:03:03 +0200 | [diff] [blame] | 12 | UPD_PURGE_CS_BY_IMSI, |
| 13 | UPD_PURGE_PS_BY_IMSI, |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 14 | _NUM_STMT |
| 15 | }; |
| 16 | |
| 17 | struct db_context { |
| 18 | char *fname; |
| 19 | sqlite3 *db; |
| 20 | sqlite3_stmt *stmt[_NUM_STMT]; |
| 21 | }; |
| 22 | |
| 23 | void db_close(struct db_context *dbc); |
| 24 | struct db_context *db_open(void *ctx, const char *fname); |
| 25 | |
| 26 | #include <osmocom/crypt/auth.h> |
| 27 | |
| 28 | /* obtain the authentication data for a given imsi */ |
| 29 | int db_get_auth_data(struct db_context *dbc, const char *imsi, |
| 30 | struct osmo_sub_auth_data *aud2g, |
| 31 | struct osmo_sub_auth_data *aud3g, |
| 32 | uint64_t *suscr_id); |
| 33 | |
| 34 | int db_update_sqn(struct db_context *dbc, uint64_t id, |
| 35 | uint64_t new_sqn); |
| 36 | |
| 37 | int db_get_auc(struct db_context *dbc, const char *imsi, |
| 38 | struct osmo_auth_vector *vec, unsigned int num_vec, |
| 39 | const uint8_t *rand_auts, const uint8_t *auts); |
Harald Welte | e687be5 | 2016-05-03 18:49:27 +0200 | [diff] [blame] | 40 | |
| 41 | #include <osmocom/core/linuxlist.h> |
| 42 | #include <osmocom/gsm/protocol/gsm_23_003.h> |
| 43 | |
| 44 | /* TODO: Get this from somewhere? */ |
| 45 | #define GT_MAX_DIGITS 15 |
| 46 | |
| 47 | struct hlr_subscriber { |
| 48 | struct llist_head list; |
| 49 | |
| 50 | uint64_t id; |
| 51 | char imsi[GSM23003_IMSI_MAX_DIGITS+1]; |
| 52 | char msisdn[GT_MAX_DIGITS+1]; |
| 53 | /* imeisv? */ |
| 54 | char vlr_number[GT_MAX_DIGITS+1]; |
| 55 | char sgsn_number[GT_MAX_DIGITS+1]; |
| 56 | char sgsn_address[GT_MAX_DIGITS+1]; |
| 57 | /* ggsn number + address */ |
| 58 | /* gmlc number */ |
| 59 | /* smsc number */ |
| 60 | uint32_t periodic_lu_timer; |
| 61 | uint32_t periodic_rau_tau_timer; |
| 62 | bool nam_cs; |
| 63 | bool nam_ps; |
| 64 | uint32_t lmsi; |
| 65 | bool ms_purged_cs; |
| 66 | bool ms_purged_ps; |
| 67 | }; |
| 68 | |
| 69 | int db_subscr_get(struct db_context *dbc, const char *imsi, |
| 70 | struct hlr_subscriber *subscr); |
| 71 | |
| 72 | int db_subscr_lu(struct db_context *dbc, |
| 73 | const struct hlr_subscriber *subscr, |
| 74 | const char *vlr_or_sgsn_number, |
| 75 | bool lu_is_ps); |
Harald Welte | b18f0e0 | 2016-05-05 21:03:03 +0200 | [diff] [blame] | 76 | |
| 77 | int db_subscr_purge(struct db_context *dbc, |
| 78 | const char *imsi, bool is_ps); |