blob: d569fb0c16338d83d7a4c8f26c2ccb196ed04519 [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 {
7 SEL_BY_IMSI = 0,
Harald Weltee687be52016-05-03 18:49:27 +02008 UPD_VLR_BY_ID = 1,
9 UPD_SGSN_BY_ID = 2,
10 AUC_BY_IMSI = 3,
11 AUC_UPD_SQN = 4,
Harald Welteb18f0e02016-05-05 21:03:03 +020012 UPD_PURGE_CS_BY_IMSI,
13 UPD_PURGE_PS_BY_IMSI,
Harald Weltee72cf552016-04-28 07:18:49 +020014 _NUM_STMT
15};
16
17struct db_context {
18 char *fname;
19 sqlite3 *db;
20 sqlite3_stmt *stmt[_NUM_STMT];
21};
22
23void db_close(struct db_context *dbc);
24struct 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 */
29int 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
34int db_update_sqn(struct db_context *dbc, uint64_t id,
35 uint64_t new_sqn);
36
37int 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 Weltee687be52016-05-03 18:49:27 +020040
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
47struct 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
69int db_subscr_get(struct db_context *dbc, const char *imsi,
70 struct hlr_subscriber *subscr);
71
72int 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 Welteb18f0e02016-05-05 21:03:03 +020076
77int db_subscr_purge(struct db_context *dbc,
78 const char *imsi, bool is_ps);