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