2016-04-28 05:18:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-05-03 16:49:27 +00:00
|
|
|
#include <stdbool.h>
|
2016-04-28 05:18:49 +00:00
|
|
|
#include <sqlite3.h>
|
|
|
|
|
|
|
|
enum stmt_idx {
|
2017-10-06 01:09:34 +00:00
|
|
|
DB_STMT_SEL_BY_IMSI,
|
2017-10-09 15:30:32 +00:00
|
|
|
DB_STMT_SEL_BY_MSISDN,
|
|
|
|
DB_STMT_SEL_BY_ID,
|
2017-10-06 01:09:34 +00:00
|
|
|
DB_STMT_UPD_VLR_BY_ID,
|
|
|
|
DB_STMT_UPD_SGSN_BY_ID,
|
|
|
|
DB_STMT_AUC_BY_IMSI,
|
|
|
|
DB_STMT_AUC_UPD_SQN,
|
|
|
|
DB_STMT_UPD_PURGE_CS_BY_IMSI,
|
|
|
|
DB_STMT_UPD_PURGE_PS_BY_IMSI,
|
|
|
|
DB_STMT_SET_NAM_PS_BY_IMSI,
|
|
|
|
DB_STMT_UNSET_NAM_PS_BY_IMSI,
|
2017-10-09 15:55:16 +00:00
|
|
|
DB_STMT_SUBSCR_CREATE,
|
|
|
|
DB_STMT_DEL_BY_ID,
|
|
|
|
DB_STMT_SET_MSISDN_BY_IMSI,
|
2017-10-06 01:09:34 +00:00
|
|
|
_NUM_DB_STMT
|
2016-04-28 05:18:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct db_context {
|
|
|
|
char *fname;
|
|
|
|
sqlite3 *db;
|
2017-10-06 01:09:34 +00:00
|
|
|
sqlite3_stmt *stmt[_NUM_DB_STMT];
|
2016-04-28 05:18:49 +00:00
|
|
|
};
|
|
|
|
|
2017-10-06 01:50:30 +00:00
|
|
|
void db_remove_reset(sqlite3_stmt *stmt);
|
2017-10-06 01:40:52 +00:00
|
|
|
bool db_bind_text(sqlite3_stmt *stmt, const char *param_name, const char *text);
|
2017-10-06 01:44:57 +00:00
|
|
|
bool db_bind_int(sqlite3_stmt *stmt, const char *param_name, int nr);
|
|
|
|
bool db_bind_int64(sqlite3_stmt *stmt, const char *param_name, int64_t nr);
|
2016-04-28 05:18:49 +00:00
|
|
|
void db_close(struct db_context *dbc);
|
|
|
|
struct db_context *db_open(void *ctx, const char *fname);
|
|
|
|
|
|
|
|
#include <osmocom/crypt/auth.h>
|
|
|
|
|
|
|
|
/* obtain the authentication data for a given imsi */
|
|
|
|
int db_get_auth_data(struct db_context *dbc, const char *imsi,
|
|
|
|
struct osmo_sub_auth_data *aud2g,
|
|
|
|
struct osmo_sub_auth_data *aud3g,
|
2017-10-06 02:26:21 +00:00
|
|
|
int64_t *subscr_id);
|
2016-04-28 05:18:49 +00:00
|
|
|
|
2017-10-06 02:26:21 +00:00
|
|
|
int db_update_sqn(struct db_context *dbc, int64_t id,
|
2016-04-28 05:18:49 +00:00
|
|
|
uint64_t new_sqn);
|
|
|
|
|
|
|
|
int db_get_auc(struct db_context *dbc, const char *imsi,
|
2017-03-14 23:07:43 +00:00
|
|
|
unsigned int auc_3g_ind, struct osmo_auth_vector *vec,
|
|
|
|
unsigned int num_vec, const uint8_t *rand_auts,
|
|
|
|
const uint8_t *auts);
|
2016-05-03 16:49:27 +00:00
|
|
|
|
|
|
|
#include <osmocom/core/linuxlist.h>
|
|
|
|
#include <osmocom/gsm/protocol/gsm_23_003.h>
|
|
|
|
|
|
|
|
/* TODO: Get this from somewhere? */
|
|
|
|
#define GT_MAX_DIGITS 15
|
|
|
|
|
|
|
|
struct hlr_subscriber {
|
|
|
|
struct llist_head list;
|
|
|
|
|
2017-10-06 02:26:21 +00:00
|
|
|
int64_t id;
|
2016-05-03 16:49:27 +00:00
|
|
|
char imsi[GSM23003_IMSI_MAX_DIGITS+1];
|
|
|
|
char msisdn[GT_MAX_DIGITS+1];
|
|
|
|
/* imeisv? */
|
|
|
|
char vlr_number[GT_MAX_DIGITS+1];
|
|
|
|
char sgsn_number[GT_MAX_DIGITS+1];
|
|
|
|
char sgsn_address[GT_MAX_DIGITS+1];
|
|
|
|
/* ggsn number + address */
|
|
|
|
/* gmlc number */
|
|
|
|
/* smsc number */
|
|
|
|
uint32_t periodic_lu_timer;
|
|
|
|
uint32_t periodic_rau_tau_timer;
|
|
|
|
bool nam_cs;
|
|
|
|
bool nam_ps;
|
|
|
|
uint32_t lmsi;
|
|
|
|
bool ms_purged_cs;
|
|
|
|
bool ms_purged_ps;
|
|
|
|
};
|
|
|
|
|
2017-10-09 15:55:16 +00:00
|
|
|
int db_subscr_create(struct db_context *dbc, const char *imsi);
|
|
|
|
int db_subscr_delete_by_id(struct db_context *dbc, int64_t subscr_id);
|
|
|
|
|
|
|
|
int db_subscr_update_msisdn_by_imsi(struct db_context *dbc, const char *imsi,
|
|
|
|
const char *msisdn);
|
|
|
|
|
2017-10-06 01:20:14 +00:00
|
|
|
int db_subscr_get_by_imsi(struct db_context *dbc, const char *imsi,
|
|
|
|
struct hlr_subscriber *subscr);
|
2017-10-09 15:30:32 +00:00
|
|
|
int db_subscr_get_by_msisdn(struct db_context *dbc, const char *msisdn,
|
|
|
|
struct hlr_subscriber *subscr);
|
|
|
|
int db_subscr_get_by_id(struct db_context *dbc, int64_t id,
|
|
|
|
struct hlr_subscriber *subscr);
|
2017-02-20 10:18:04 +00:00
|
|
|
int db_subscr_ps(struct db_context *dbc, const char *imsi, bool enable);
|
2016-05-03 16:49:27 +00:00
|
|
|
int db_subscr_lu(struct db_context *dbc,
|
|
|
|
const struct hlr_subscriber *subscr,
|
|
|
|
const char *vlr_or_sgsn_number,
|
|
|
|
bool lu_is_ps);
|
2016-05-05 19:03:03 +00:00
|
|
|
|
|
|
|
int db_subscr_purge(struct db_context *dbc,
|
|
|
|
const char *imsi, bool is_ps);
|