blob: a776099219b8f13cc0b46b2674c570e922cdcf80 [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 Weltee72cf552016-04-28 07:18:49 +020012 _NUM_STMT
13};
14
15struct db_context {
16 char *fname;
17 sqlite3 *db;
18 sqlite3_stmt *stmt[_NUM_STMT];
19};
20
21void db_close(struct db_context *dbc);
22struct 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 */
27int 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
32int db_update_sqn(struct db_context *dbc, uint64_t id,
33 uint64_t new_sqn);
34
35int 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 Weltee687be52016-05-03 18:49:27 +020038
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
45struct 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
67int db_subscr_get(struct db_context *dbc, const char *imsi,
68 struct hlr_subscriber *subscr);
69
70int 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);