Stefan Sperling | 8f3a7cc | 2018-11-27 12:10:45 +0100 | [diff] [blame] | 1 | CREATE TABLE subscriber ( |
Neels Hofmeyr | 88c91f6 | 2017-10-25 00:26:29 +0200 | [diff] [blame] | 2 | -- OsmoHLR's DB scheme is modelled roughly after TS 23.008 version 13.3.0 |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 3 | id INTEGER PRIMARY KEY, |
| 4 | -- Chapter 2.1.1.1 |
Neels Hofmeyr | cc785f0 | 2017-02-01 17:08:56 +0100 | [diff] [blame] | 5 | imsi VARCHAR(15) UNIQUE NOT NULL, |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 6 | -- Chapter 2.1.2 |
Neels Hofmeyr | cc785f0 | 2017-02-01 17:08:56 +0100 | [diff] [blame] | 7 | msisdn VARCHAR(15) UNIQUE, |
Oliver Smith | 81db389 | 2019-01-09 12:03:51 +0100 | [diff] [blame] | 8 | -- Chapter 2.2.3: Most recent / current IMEISV |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 9 | imeisv VARCHAR, |
Oliver Smith | 81db389 | 2019-01-09 12:03:51 +0100 | [diff] [blame] | 10 | -- Chapter 2.1.9: Most recent / current IMEI |
| 11 | imei VARCHAR(14), |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 12 | -- Chapter 2.4.5 |
| 13 | vlr_number VARCHAR(15), |
| 14 | -- Chapter 2.4.6 |
Neels Hofmeyr | a8045da | 2019-10-31 01:19:44 +0100 | [diff] [blame] | 15 | msc_number VARCHAR(15), |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 16 | -- 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 Welte | 6122915 | 2016-05-03 18:47:08 +0200 | [diff] [blame] | 31 | nam_cs BOOLEAN NOT NULL DEFAULT 1, |
| 32 | nam_ps BOOLEAN NOT NULL DEFAULT 1, |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 33 | -- Chapter 2.1.8 |
| 34 | lmsi INTEGER, |
| 35 | |
Harald Welte | b18f0e0 | 2016-05-05 21:03:03 +0200 | [diff] [blame] | 36 | -- The below purged flags might not even be stored non-volatile, |
| 37 | -- refer to TS 23.012 Chapter 3.6.1.4 |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 38 | -- Chapter 2.7.5 |
Harald Welte | 6122915 | 2016-05-03 18:47:08 +0200 | [diff] [blame] | 39 | ms_purged_cs BOOLEAN NOT NULL DEFAULT 0, |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 40 | -- Chapter 2.7.6 |
Stefan Sperling | 638ba8c | 2018-12-04 15:07:29 +0100 | [diff] [blame] | 41 | 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 Hofmeyr | 07e1602 | 2019-11-20 02:36:35 +0100 | [diff] [blame] | 45 | last_lu_seen TIMESTAMP default NULL, |
Neels Hofmeyr | f0c02ad | 2019-11-25 03:59:50 +0100 | [diff] [blame] | 46 | last_lu_seen_ps TIMESTAMP default NULL, |
| 47 | |
Neels Hofmeyr | 5bc457e | 2018-12-29 03:28:38 +0100 | [diff] [blame] | 48 | -- 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 Hofmeyr | f0c02ad | 2019-11-25 03:59:50 +0100 | [diff] [blame] | 54 | -- 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 Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 58 | ); |
| 59 | |
Stefan Sperling | 8f3a7cc | 2018-11-27 12:10:45 +0100 | [diff] [blame] | 60 | CREATE TABLE subscriber_apn ( |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 61 | subscriber_id INTEGER, -- subscriber.id |
| 62 | apn VARCHAR(256) NOT NULL |
| 63 | ); |
| 64 | |
Stefan Sperling | 8f3a7cc | 2018-11-27 12:10:45 +0100 | [diff] [blame] | 65 | CREATE TABLE subscriber_multi_msisdn ( |
Neels Hofmeyr | 88c91f6 | 2017-10-25 00:26:29 +0200 | [diff] [blame] | 66 | -- Chapter 2.1.3 |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 67 | subscriber_id INTEGER, -- subscriber.id |
| 68 | msisdn VARCHAR(15) NOT NULL |
| 69 | ); |
| 70 | |
Stefan Sperling | 8f3a7cc | 2018-11-27 12:10:45 +0100 | [diff] [blame] | 71 | CREATE TABLE auc_2g ( |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 72 | subscriber_id INTEGER PRIMARY KEY, -- subscriber.id |
Neels Hofmeyr | 8089d51 | 2017-01-30 13:49:49 +0100 | [diff] [blame] | 73 | 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 Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 75 | ); |
| 76 | |
Stefan Sperling | 8f3a7cc | 2018-11-27 12:10:45 +0100 | [diff] [blame] | 77 | CREATE TABLE auc_3g ( |
Neels Hofmeyr | 2116ce2 | 2017-01-19 15:50:59 +0100 | [diff] [blame] | 78 | subscriber_id INTEGER PRIMARY KEY, -- subscriber.id |
Neels Hofmeyr | 8089d51 | 2017-01-30 13:49:49 +0100 | [diff] [blame] | 79 | 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 Hofmeyr | cab2fcd | 2017-03-15 00:07:43 +0100 | [diff] [blame] | 83 | sqn INTEGER NOT NULL DEFAULT 0, -- sequence number of key usage |
Neels Hofmeyr | f8ad67e | 2019-10-31 19:43:36 +0100 | [diff] [blame] | 84 | -- nr of index bits at lower SQN end |
| 85 | ind_bitlen INTEGER NOT NULL DEFAULT 5 |
Harald Welte | e72cf55 | 2016-04-28 07:18:49 +0200 | [diff] [blame] | 86 | ); |
| 87 | |
Neels Hofmeyr | 92d1c4a | 2019-12-12 04:04:53 +0100 | [diff] [blame] | 88 | CREATE 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 Hofmeyr | ce172ef | 2018-12-26 01:49:53 +0100 | [diff] [blame] | 96 | -- 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). |
| 98 | CREATE TABLE subscriber_rat ( |
| 99 | subscriber_id INTEGER, -- subscriber.id |
Piotr Krysik | a5ed663 | 2019-08-22 11:18:15 +0200 | [diff] [blame] | 100 | rat TEXT CHECK(rat in ('GERAN-A', 'UTRAN-Iu','EUTRAN-SGs')) NOT NULL, -- Radio Access Technology, see enum ran_type |
Neels Hofmeyr | ce172ef | 2018-12-26 01:49:53 +0100 | [diff] [blame] | 101 | allowed BOOLEAN CHECK(allowed in (0, 1)) NOT NULL DEFAULT 0, |
| 102 | UNIQUE (subscriber_id, rat) |
| 103 | ); |
| 104 | |
Stefan Sperling | 8f3a7cc | 2018-11-27 12:10:45 +0100 | [diff] [blame] | 105 | CREATE UNIQUE INDEX idx_subscr_imsi ON subscriber (imsi); |
Neels Hofmeyr | ce172ef | 2018-12-26 01:49:53 +0100 | [diff] [blame] | 106 | CREATE UNIQUE INDEX idx_subscr_rat_flag ON subscriber_rat (subscriber_id, rat); |
Stefan Sperling | 8f3a7cc | 2018-11-27 12:10:45 +0100 | [diff] [blame] | 107 | |
| 108 | -- Set HLR database schema version number |
Stefan Sperling | 638ba8c | 2018-12-04 15:07:29 +0100 | [diff] [blame] | 109 | -- Note: This constant is currently duplicated in src/db.c and must be kept in sync! |
Neels Hofmeyr | 5bc457e | 2018-12-29 03:28:38 +0100 | [diff] [blame] | 110 | PRAGMA user_version = 8; |