blob: 2777c04f6cbb31ab97ef9364e2b2d1a7ac55eafa [file] [log] [blame]
Stefan Sperling8f3a7cc2018-11-27 12:10:45 +01001CREATE TABLE subscriber (
Neels Hofmeyr88c91f62017-10-25 00:26:29 +02002-- OsmoHLR's DB scheme is modelled roughly after TS 23.008 version 13.3.0
Harald Weltee72cf552016-04-28 07:18:49 +02003 id INTEGER PRIMARY KEY,
4 -- Chapter 2.1.1.1
Neels Hofmeyrcc785f02017-02-01 17:08:56 +01005 imsi VARCHAR(15) UNIQUE NOT NULL,
Harald Weltee72cf552016-04-28 07:18:49 +02006 -- Chapter 2.1.2
Neels Hofmeyrcc785f02017-02-01 17:08:56 +01007 msisdn VARCHAR(15) UNIQUE,
Oliver Smith81db3892019-01-09 12:03:51 +01008 -- Chapter 2.2.3: Most recent / current IMEISV
Harald Weltee72cf552016-04-28 07:18:49 +02009 imeisv VARCHAR,
Oliver Smith81db3892019-01-09 12:03:51 +010010 -- Chapter 2.1.9: Most recent / current IMEI
11 imei VARCHAR(14),
Harald Weltee72cf552016-04-28 07:18:49 +020012 -- Chapter 2.4.5
13 vlr_number VARCHAR(15),
14 -- Chapter 2.4.6
Neels Hofmeyra8045da2019-10-31 01:19:44 +010015 msc_number VARCHAR(15),
Harald Weltee72cf552016-04-28 07:18:49 +020016 -- Chapter 2.4.8.1
17 sgsn_number VARCHAR(15),
18 -- Chapter 2.13.10
19 sgsn_address VARCHAR,
20 -- Chapter 2.4.8.2
21 ggsn_number VARCHAR(15),
22 -- Chapter 2.4.9.2
23 gmlc_number VARCHAR(15),
24 -- Chapter 2.4.23
25 smsc_number VARCHAR(15),
26 -- Chapter 2.4.24
27 periodic_lu_tmr INTEGER,
28 -- Chapter 2.13.115
29 periodic_rau_tau_tmr INTEGER,
30 -- Chapter 2.1.1.2: network access mode
Harald Welte61229152016-05-03 18:47:08 +020031 nam_cs BOOLEAN NOT NULL DEFAULT 1,
32 nam_ps BOOLEAN NOT NULL DEFAULT 1,
Harald Weltee72cf552016-04-28 07:18:49 +020033 -- Chapter 2.1.8
34 lmsi INTEGER,
35
Harald Welteb18f0e02016-05-05 21:03:03 +020036 -- The below purged flags might not even be stored non-volatile,
37 -- refer to TS 23.012 Chapter 3.6.1.4
Harald Weltee72cf552016-04-28 07:18:49 +020038 -- Chapter 2.7.5
Harald Welte61229152016-05-03 18:47:08 +020039 ms_purged_cs BOOLEAN NOT NULL DEFAULT 0,
Harald Weltee72cf552016-04-28 07:18:49 +020040 -- Chapter 2.7.6
Stefan Sperling638ba8c2018-12-04 15:07:29 +010041 ms_purged_ps BOOLEAN NOT NULL DEFAULT 0,
42
43 -- Timestamp of last location update seen from subscriber
44 -- The value is a string which encodes a UTC timestamp in granularity of seconds.
Neels Hofmeyr07e16022019-11-20 02:36:35 +010045 last_lu_seen TIMESTAMP default NULL,
Neels Hofmeyrf0c02ad2019-11-25 03:59:50 +010046 last_lu_seen_ps TIMESTAMP default NULL,
47
Neels Hofmeyr5bc457e2018-12-29 03:28:38 +010048 -- Last Radio Access Type list as sent during Location Updating Request.
49 -- This is usually just one RAT name, but can be a comma separated list of strings
50 -- of all the RAT types sent during Location Updating Request.
51 last_lu_rat_cs TEXT default NULL,
52 last_lu_rat_ps TEXT default NULL,
53
Neels Hofmeyrf0c02ad2019-11-25 03:59:50 +010054 -- When a LU was received via a proxy, that proxy's hlr_number is stored here,
55 -- while vlr_number reflects the MSC on the far side of that proxy.
56 vlr_via_proxy VARCHAR,
57 sgsn_via_proxy VARCHAR
Harald Weltee72cf552016-04-28 07:18:49 +020058);
59
Stefan Sperling8f3a7cc2018-11-27 12:10:45 +010060CREATE TABLE subscriber_apn (
Harald Weltee72cf552016-04-28 07:18:49 +020061 subscriber_id INTEGER, -- subscriber.id
62 apn VARCHAR(256) NOT NULL
63);
64
Stefan Sperling8f3a7cc2018-11-27 12:10:45 +010065CREATE TABLE subscriber_multi_msisdn (
Neels Hofmeyr88c91f62017-10-25 00:26:29 +020066-- Chapter 2.1.3
Harald Weltee72cf552016-04-28 07:18:49 +020067 subscriber_id INTEGER, -- subscriber.id
68 msisdn VARCHAR(15) NOT NULL
69);
70
Stefan Sperling8f3a7cc2018-11-27 12:10:45 +010071CREATE TABLE auc_2g (
Harald Weltee72cf552016-04-28 07:18:49 +020072 subscriber_id INTEGER PRIMARY KEY, -- subscriber.id
Neels Hofmeyr8089d512017-01-30 13:49:49 +010073 algo_id_2g INTEGER NOT NULL, -- enum osmo_auth_algo value
74 ki VARCHAR(32) NOT NULL -- hex string: subscriber's secret key (128bit)
Harald Weltee72cf552016-04-28 07:18:49 +020075);
76
Stefan Sperling8f3a7cc2018-11-27 12:10:45 +010077CREATE TABLE auc_3g (
Neels Hofmeyr2116ce22017-01-19 15:50:59 +010078 subscriber_id INTEGER PRIMARY KEY, -- subscriber.id
Neels Hofmeyr8089d512017-01-30 13:49:49 +010079 algo_id_3g INTEGER NOT NULL, -- enum osmo_auth_algo value
80 k VARCHAR(32) NOT NULL, -- hex string: subscriber's secret key (128bit)
81 op VARCHAR(32), -- hex string: operator's secret key (128bit)
82 opc VARCHAR(32), -- hex string: derived from OP and K (128bit)
Neels Hofmeyrcab2fcd2017-03-15 00:07:43 +010083 sqn INTEGER NOT NULL DEFAULT 0, -- sequence number of key usage
Neels Hofmeyrf8ad67e2019-10-31 19:43:36 +010084 -- nr of index bits at lower SQN end
85 ind_bitlen INTEGER NOT NULL DEFAULT 5
Harald Weltee72cf552016-04-28 07:18:49 +020086);
87
Neels Hofmeyr92d1c4a2019-12-12 04:04:53 +010088CREATE TABLE ind (
89 -- 3G auth IND pool to be used for this VLR
90 ind INTEGER PRIMARY KEY,
91 -- VLR identification, usually the GSUP source_name
92 vlr TEXT NOT NULL,
93 UNIQUE (vlr)
94);
95
Neels Hofmeyrce172ef2018-12-26 01:49:53 +010096-- Optional: add subscriber entries to allow or disallow specific RATs (2G or 3G or ...).
97-- If a subscriber has no entry, that means that all RATs are allowed (backwards compat).
98CREATE TABLE subscriber_rat (
99 subscriber_id INTEGER, -- subscriber.id
Piotr Krysika5ed6632019-08-22 11:18:15 +0200100 rat TEXT CHECK(rat in ('GERAN-A', 'UTRAN-Iu','EUTRAN-SGs')) NOT NULL, -- Radio Access Technology, see enum ran_type
Neels Hofmeyrce172ef2018-12-26 01:49:53 +0100101 allowed BOOLEAN CHECK(allowed in (0, 1)) NOT NULL DEFAULT 0,
102 UNIQUE (subscriber_id, rat)
103);
104
Stefan Sperling8f3a7cc2018-11-27 12:10:45 +0100105CREATE UNIQUE INDEX idx_subscr_imsi ON subscriber (imsi);
Neels Hofmeyrce172ef2018-12-26 01:49:53 +0100106CREATE UNIQUE INDEX idx_subscr_rat_flag ON subscriber_rat (subscriber_id, rat);
Stefan Sperling8f3a7cc2018-11-27 12:10:45 +0100107
108-- Set HLR database schema version number
Stefan Sperling638ba8c2018-12-04 15:07:29 +0100109-- Note: This constant is currently duplicated in src/db.c and must be kept in sync!
Neels Hofmeyr5bc457e2018-12-29 03:28:38 +0100110PRAGMA user_version = 8;