blob: 0064a4d1a24d54b86658282d3da7dc1d5d7bb932 [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);
26bool db_bind_imsi(sqlite3_stmt *stmt, const char *imsi);
Harald Weltee72cf552016-04-28 07:18:49 +020027void db_close(struct db_context *dbc);
28struct db_context *db_open(void *ctx, const char *fname);
29
30#include <osmocom/crypt/auth.h>
31
32/* obtain the authentication data for a given imsi */
33int db_get_auth_data(struct db_context *dbc, const char *imsi,
34 struct osmo_sub_auth_data *aud2g,
35 struct osmo_sub_auth_data *aud3g,
36 uint64_t *suscr_id);
37
38int db_update_sqn(struct db_context *dbc, uint64_t id,
39 uint64_t new_sqn);
40
41int db_get_auc(struct db_context *dbc, const char *imsi,
Neels Hofmeyrcab2fcd2017-03-15 00:07:43 +010042 unsigned int auc_3g_ind, struct osmo_auth_vector *vec,
43 unsigned int num_vec, const uint8_t *rand_auts,
44 const uint8_t *auts);
Harald Weltee687be52016-05-03 18:49:27 +020045
46#include <osmocom/core/linuxlist.h>
47#include <osmocom/gsm/protocol/gsm_23_003.h>
48
49/* TODO: Get this from somewhere? */
50#define GT_MAX_DIGITS 15
51
52struct hlr_subscriber {
53 struct llist_head list;
54
55 uint64_t id;
56 char imsi[GSM23003_IMSI_MAX_DIGITS+1];
57 char msisdn[GT_MAX_DIGITS+1];
58 /* imeisv? */
59 char vlr_number[GT_MAX_DIGITS+1];
60 char sgsn_number[GT_MAX_DIGITS+1];
61 char sgsn_address[GT_MAX_DIGITS+1];
62 /* ggsn number + address */
63 /* gmlc number */
64 /* smsc number */
65 uint32_t periodic_lu_timer;
66 uint32_t periodic_rau_tau_timer;
67 bool nam_cs;
68 bool nam_ps;
69 uint32_t lmsi;
70 bool ms_purged_cs;
71 bool ms_purged_ps;
72};
73
Neels Hofmeyr518335e2017-10-06 03:20:14 +020074int db_subscr_get_by_imsi(struct db_context *dbc, const char *imsi,
75 struct hlr_subscriber *subscr);
Max3ce36862017-02-20 11:18:04 +010076int db_subscr_ps(struct db_context *dbc, const char *imsi, bool enable);
Harald Weltee687be52016-05-03 18:49:27 +020077int db_subscr_lu(struct db_context *dbc,
78 const struct hlr_subscriber *subscr,
79 const char *vlr_or_sgsn_number,
80 bool lu_is_ps);
Harald Welteb18f0e02016-05-05 21:03:03 +020081
82int db_subscr_purge(struct db_context *dbc,
83 const char *imsi, bool is_ps);