blob: 761d88ef3c3342980182646bbd30a220aabe4b17 [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,
Neels Hofmeyrf7c3e6e2017-10-09 17:55:16 +020016 DB_STMT_SUBSCR_CREATE,
17 DB_STMT_DEL_BY_ID,
18 DB_STMT_SET_MSISDN_BY_IMSI,
Neels Hofmeyr4bde9492017-10-06 03:09:34 +020019 _NUM_DB_STMT
Harald Weltee72cf552016-04-28 07:18:49 +020020};
21
22struct db_context {
23 char *fname;
24 sqlite3 *db;
Neels Hofmeyr4bde9492017-10-06 03:09:34 +020025 sqlite3_stmt *stmt[_NUM_DB_STMT];
Harald Weltee72cf552016-04-28 07:18:49 +020026};
27
Neels Hofmeyrd7d96972017-10-06 03:50:30 +020028void db_remove_reset(sqlite3_stmt *stmt);
Neels Hofmeyrf3144592017-10-06 03:40:52 +020029bool db_bind_text(sqlite3_stmt *stmt, const char *param_name, const char *text);
Neels Hofmeyr28da26e2017-10-06 03:44:57 +020030bool db_bind_int(sqlite3_stmt *stmt, const char *param_name, int nr);
31bool db_bind_int64(sqlite3_stmt *stmt, const char *param_name, int64_t nr);
Harald Weltee72cf552016-04-28 07:18:49 +020032void db_close(struct db_context *dbc);
33struct db_context *db_open(void *ctx, const char *fname);
34
35#include <osmocom/crypt/auth.h>
36
37/* obtain the authentication data for a given imsi */
38int db_get_auth_data(struct db_context *dbc, const char *imsi,
39 struct osmo_sub_auth_data *aud2g,
40 struct osmo_sub_auth_data *aud3g,
Neels Hofmeyr32633e22017-10-06 04:26:21 +020041 int64_t *subscr_id);
Harald Weltee72cf552016-04-28 07:18:49 +020042
Neels Hofmeyr32633e22017-10-06 04:26:21 +020043int db_update_sqn(struct db_context *dbc, int64_t id,
Harald Weltee72cf552016-04-28 07:18:49 +020044 uint64_t new_sqn);
45
46int db_get_auc(struct db_context *dbc, const char *imsi,
Neels Hofmeyrcab2fcd2017-03-15 00:07:43 +010047 unsigned int auc_3g_ind, struct osmo_auth_vector *vec,
48 unsigned int num_vec, const uint8_t *rand_auts,
49 const uint8_t *auts);
Harald Weltee687be52016-05-03 18:49:27 +020050
51#include <osmocom/core/linuxlist.h>
52#include <osmocom/gsm/protocol/gsm_23_003.h>
53
54/* TODO: Get this from somewhere? */
55#define GT_MAX_DIGITS 15
56
57struct hlr_subscriber {
58 struct llist_head list;
59
Neels Hofmeyr32633e22017-10-06 04:26:21 +020060 int64_t id;
Harald Weltee687be52016-05-03 18:49:27 +020061 char imsi[GSM23003_IMSI_MAX_DIGITS+1];
62 char msisdn[GT_MAX_DIGITS+1];
63 /* imeisv? */
64 char vlr_number[GT_MAX_DIGITS+1];
65 char sgsn_number[GT_MAX_DIGITS+1];
66 char sgsn_address[GT_MAX_DIGITS+1];
67 /* ggsn number + address */
68 /* gmlc number */
69 /* smsc number */
70 uint32_t periodic_lu_timer;
71 uint32_t periodic_rau_tau_timer;
72 bool nam_cs;
73 bool nam_ps;
74 uint32_t lmsi;
75 bool ms_purged_cs;
76 bool ms_purged_ps;
77};
78
Neels Hofmeyrf7c3e6e2017-10-09 17:55:16 +020079int db_subscr_create(struct db_context *dbc, const char *imsi);
80int db_subscr_delete_by_id(struct db_context *dbc, int64_t subscr_id);
81
82int db_subscr_update_msisdn_by_imsi(struct db_context *dbc, const char *imsi,
83 const char *msisdn);
84
Neels Hofmeyr518335e2017-10-06 03:20:14 +020085int db_subscr_get_by_imsi(struct db_context *dbc, const char *imsi,
86 struct hlr_subscriber *subscr);
Max3ce36862017-02-20 11:18:04 +010087int db_subscr_ps(struct db_context *dbc, const char *imsi, bool enable);
Harald Weltee687be52016-05-03 18:49:27 +020088int db_subscr_lu(struct db_context *dbc,
89 const struct hlr_subscriber *subscr,
90 const char *vlr_or_sgsn_number,
91 bool lu_is_ps);
Harald Welteb18f0e02016-05-05 21:03:03 +020092
93int db_subscr_purge(struct db_context *dbc,
94 const char *imsi, bool is_ps);