blob: 0e823f9dec91d58b9158a96efa0a562abee9756c [file] [log] [blame]
Harald Weltee72cf552016-04-28 07:18:49 +02001#include <string.h>
2
3#include <osmocom/core/utils.h>
4#include <osmocom/core/application.h>
5
6#include "db.h"
Maxd4bebbd2017-03-02 12:00:19 +01007#include "hlr.h"
Harald Weltee72cf552016-04-28 07:18:49 +02008#include "rand.h"
9#include "logging.h"
10
Maxd4bebbd2017-03-02 12:00:19 +010011static struct hlr *g_hlr;
Harald Weltee72cf552016-04-28 07:18:49 +020012
Maxd4bebbd2017-03-02 12:00:19 +010013static int test(const char *imsi, struct db_context *dbc)
Harald Weltee72cf552016-04-28 07:18:49 +020014{
15 struct osmo_auth_vector vec[3];
16 int rc, i;
17
18 /* initialize all vectors with a known token pattern */
19 memset(vec, 0x55, sizeof(vec));
20 for (i = 0; i < ARRAY_SIZE(vec); i++)
21 vec[i].res_len = 0;
22
Neels Hofmeyrcab2fcd2017-03-15 00:07:43 +010023 rc = db_get_auc(dbc, imsi, 0, vec, ARRAY_SIZE(vec), NULL, NULL);
Harald Weltee72cf552016-04-28 07:18:49 +020024 if (rc <= 0) {
25 LOGP(DMAIN, LOGL_ERROR, "Cannot obtain auth tuples for '%s'\n", imsi);
26 return rc;
27 }
28 LOGP(DMAIN, LOGL_INFO, "Obtained %u tuples for subscriber IMSI %s\n",
29 rc, imsi);
30
31 for (i = 0; i < rc; i++) {
32 struct osmo_auth_vector *v = vec + i;
33 LOGP(DMAIN, LOGL_DEBUG, "Tuple %u, auth_types=0x%x\n", i, v->auth_types);
34 LOGP(DMAIN, LOGL_DEBUG, "RAND=%s\n", osmo_hexdump_nospc(v->rand, sizeof(v->rand)));
35 LOGP(DMAIN, LOGL_DEBUG, "AUTN=%s\n", osmo_hexdump_nospc(v->autn, sizeof(v->autn)));
36 LOGP(DMAIN, LOGL_DEBUG, "CK=%s\n", osmo_hexdump_nospc(v->ck, sizeof(v->ck)));
37 LOGP(DMAIN, LOGL_DEBUG, "IK=%s\n", osmo_hexdump_nospc(v->ik, sizeof(v->ik)));
38 LOGP(DMAIN, LOGL_DEBUG, "RES=%s\n", osmo_hexdump_nospc(v->res, v->res_len));
39 LOGP(DMAIN, LOGL_DEBUG, "Kc=%s\n", osmo_hexdump_nospc(v->kc, sizeof(v->kc)));
40 LOGP(DMAIN, LOGL_DEBUG, "SRES=%s\n", osmo_hexdump_nospc(v->sres, sizeof(v->sres)));
41 }
42
43 return rc;
44}
45
46int main(int argc, char **argv)
47{
48 int rc;
49
Maxd4bebbd2017-03-02 12:00:19 +010050 g_hlr = talloc_zero(NULL, struct hlr);
51
Harald Weltee72cf552016-04-28 07:18:49 +020052 rc = osmo_init_logging(&hlr_log_info);
53 if (rc < 0) {
54 fprintf(stderr, "Error initializing logging\n");
55 exit(1);
56 }
57 LOGP(DMAIN, LOGL_NOTICE, "hlr starting\n");
58
59 rc = rand_init();
60 if (rc < 0) {
61 LOGP(DMAIN, LOGL_ERROR, "Error initializing random source\n");
62 exit(1);
63 }
64
Maxd4bebbd2017-03-02 12:00:19 +010065 g_hlr->dbc = db_open(NULL, "hlr.db");
66 if (!g_hlr->dbc) {
Harald Weltee72cf552016-04-28 07:18:49 +020067 LOGP(DMAIN, LOGL_ERROR, "Error opening database\n");
68 exit(1);
69 }
70
71 /* non-existing subscriber */
Maxd4bebbd2017-03-02 12:00:19 +010072 rc = test("901990123456789", g_hlr->dbc);
Harald Weltee72cf552016-04-28 07:18:49 +020073 /* 2G only AUC data (COMP128v1 / MILENAGE) */
Maxd4bebbd2017-03-02 12:00:19 +010074 rc = test("901990000000001", g_hlr->dbc);
Harald Weltee72cf552016-04-28 07:18:49 +020075 /* 2G + 3G AUC data (COMP128v1 / MILENAGE) */
Maxd4bebbd2017-03-02 12:00:19 +010076 rc = test("901990000000002", g_hlr->dbc);
Harald Weltee72cf552016-04-28 07:18:49 +020077 /* 3G AUC data (MILENAGE) */
Maxd4bebbd2017-03-02 12:00:19 +010078 rc = test("901990000000003", g_hlr->dbc);
Harald Weltee72cf552016-04-28 07:18:49 +020079
80 LOGP(DMAIN, LOGL_NOTICE, "Exiting\n");
81
Maxd4bebbd2017-03-02 12:00:19 +010082 db_close(g_hlr->dbc);
Harald Weltee72cf552016-04-28 07:18:49 +020083
84 log_fini();
85
86 exit(0);
87}