blob: 533c4d2398f6ce661896bf3012c9036ac6e3c3ae [file] [log] [blame]
Harald Weltee72cf552016-04-28 07:18:49 +02001#pragma once
2
Harald Weltee687be52016-05-03 18:49:27 +02003#include <stdbool.h>
Harald Weltee72cf552016-04-28 07:18:49 +02004#include <sqlite3.h>
5
6enum stmt_idx {
Neels Hofmeyr4bde9492017-10-06 03:09:34 +02007 DB_STMT_SEL_BY_IMSI,
8 DB_STMT_UPD_VLR_BY_ID,
9 DB_STMT_UPD_SGSN_BY_ID,
10 DB_STMT_AUC_BY_IMSI,
11 DB_STMT_AUC_UPD_SQN,
12 DB_STMT_UPD_PURGE_CS_BY_IMSI,
13 DB_STMT_UPD_PURGE_PS_BY_IMSI,
14 DB_STMT_SET_NAM_PS_BY_IMSI,
15 DB_STMT_UNSET_NAM_PS_BY_IMSI,
16 _NUM_DB_STMT
Harald Weltee72cf552016-04-28 07:18:49 +020017};
18
19struct db_context {
20 char *fname;
21 sqlite3 *db;
Neels Hofmeyr4bde9492017-10-06 03:09:34 +020022 sqlite3_stmt *stmt[_NUM_DB_STMT];
Harald Weltee72cf552016-04-28 07:18:49 +020023};
24
Max00b37152017-02-20 11:09:27 +010025bool db_remove_reset(sqlite3_stmt *stmt);
Neels Hofmeyrf3144592017-10-06 03:40:52 +020026bool db_bind_text(sqlite3_stmt *stmt, const char *param_name, const char *text);
Neels Hofmeyr28da26e2017-10-06 03:44:57 +020027bool db_bind_int(sqlite3_stmt *stmt, const char *param_name, int nr);
28bool db_bind_int64(sqlite3_stmt *stmt, const char *param_name, int64_t nr);
Harald Weltee72cf552016-04-28 07:18:49 +020029void db_close(struct db_context *dbc);
30struct db_context *db_open(void *ctx, const char *fname);
31
32#include <osmocom/crypt/auth.h>
33
34/* obtain the authentication data for a given imsi */
35int db_get_auth_data(struct db_context *dbc, const char *imsi,
36 struct osmo_sub_auth_data *aud2g,
37 struct osmo_sub_auth_data *aud3g,
38 uint64_t *suscr_id);
39
40int db_update_sqn(struct db_context *dbc, uint64_t id,
41 uint64_t new_sqn);
42
43int db_get_auc(struct db_context *dbc, const char *imsi,
Neels Hofmeyrcab2fcd2017-03-15 00:07:43 +010044 unsigned int auc_3g_ind, struct osmo_auth_vector *vec,
45 unsigned int num_vec, const uint8_t *rand_auts,
46 const uint8_t *auts);
Harald Weltee687be52016-05-03 18:49:27 +020047
48#include <osmocom/core/linuxlist.h>
49#include <osmocom/gsm/protocol/gsm_23_003.h>
50
51/* TODO: Get this from somewhere? */
52#define GT_MAX_DIGITS 15
53
54struct hlr_subscriber {
55 struct llist_head list;
56
57 uint64_t id;
58 char imsi[GSM23003_IMSI_MAX_DIGITS+1];
59 char msisdn[GT_MAX_DIGITS+1];
60 /* imeisv? */
61 char vlr_number[GT_MAX_DIGITS+1];
62 char sgsn_number[GT_MAX_DIGITS+1];
63 char sgsn_address[GT_MAX_DIGITS+1];
64 /* ggsn number + address */
65 /* gmlc number */
66 /* smsc number */
67 uint32_t periodic_lu_timer;
68 uint32_t periodic_rau_tau_timer;
69 bool nam_cs;
70 bool nam_ps;
71 uint32_t lmsi;
72 bool ms_purged_cs;
73 bool ms_purged_ps;
74};
75
Neels Hofmeyr518335e2017-10-06 03:20:14 +020076int db_subscr_get_by_imsi(struct db_context *dbc, const char *imsi,
77 struct hlr_subscriber *subscr);
Max3ce36862017-02-20 11:18:04 +010078int db_subscr_ps(struct db_context *dbc, const char *imsi, bool enable);
Harald Weltee687be52016-05-03 18:49:27 +020079int db_subscr_lu(struct db_context *dbc,
80 const struct hlr_subscriber *subscr,
81 const char *vlr_or_sgsn_number,
82 bool lu_is_ps);
Harald Welteb18f0e02016-05-05 21:03:03 +020083
84int db_subscr_purge(struct db_context *dbc,
85 const char *imsi, bool is_ps);