blob: 69f00f68dd19175f1e80a3c7cca22f82df6884a4 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file gsm23003.h */
2
Harald Weltebda26c02016-05-11 09:13:08 +02003#pragma once
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02004
Harald Weltebda26c02016-05-11 09:13:08 +02005#include <stdint.h>
Neels Hofmeyr9cd1e742017-10-04 03:15:47 +02006#include <stdbool.h>
Harald Weltebda26c02016-05-11 09:13:08 +02007
8/* 23.003 Chapter 12.1 */
9struct osmo_plmn_id {
10 uint16_t mcc;
11 uint16_t mnc;
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010012 bool mnc_3_digits; /*< ignored and implied true if mnc > 99, otherwise defines leading zeros. */
Harald Weltebda26c02016-05-11 09:13:08 +020013};
14
15/* 4.1 */
16struct osmo_location_area_id {
17 struct osmo_plmn_id plmn;
18 uint16_t lac;
19};
20
21/* 4.2 */
22struct osmo_routing_area_id {
23 struct osmo_location_area_id lac;
24 uint8_t rac;
25};
26
27/* 4.3.1 */
28struct osmo_cell_global_id {
29 struct osmo_location_area_id lai;
30 uint16_t cell_identity;
31};
32
Neels Hofmeyr3a504532019-02-10 22:28:27 +010033/*! Bitmask of items contained in a struct osmo_cell_global_id.
34 * See also gsm0808_cell_id_to_cgi().
35 */
36enum osmo_cgi_part {
37 OSMO_CGI_PART_PLMN = 1,
38 OSMO_CGI_PART_LAC = 2,
39 OSMO_CGI_PART_CI = 4,
40};
41
Stefan Sperling11a4d9d2018-02-15 18:28:04 +010042/* Actually defined in 3GPP TS 48.008 3.2.2.27 Cell Identifier List,
43 * but conceptually belongs with the above structures. */
44struct osmo_lac_and_ci_id {
45 uint16_t lac;
46 uint16_t ci;
47};
48
Harald Weltebda26c02016-05-11 09:13:08 +020049/* 12.5 */
50struct osmo_service_area_id {
51 struct osmo_location_area_id lai;
52 uint16_t sac;
53};
54
55/* 12.6 */
56struct osmo_shared_network_area_id {
57 struct osmo_plmn_id plmn;
58 uint32_t snac;
59};
60
61/* 5.1 */
62enum osmo_gsn_addr_type {
63 GSN_ADDR_TYPE_IPV4 = 0,
64 GSN_ADDR_TYPE_IPV6 = 1,
65};
66
67/* 5.1 */
68struct osmo_gsn_address {
69 enum osmo_gsn_addr_type type;
70 uint8_t length;
71 uint8_t addr[16];
72};
73
74/* 19.4.2.3 */
75struct osmo_tracking_area_id {
76 struct osmo_plmn_id plmn;
77 uint16_t tac;
78};
79
80struct osmo_eutran_cell_global_id {
81 struct osmo_plmn_id plmn;
82 uint32_t eci; /* FIXME */
83};
84
85/* 2.8.1 */
86struct osmo_mme_id {
87 uint16_t group_id;
88 uint8_t code;
89};
90
91/* 2.8.1 */
92struct osmo_gummei {
93 struct osmo_plmn_id plmn;
94 struct osmo_mme_id mme;
95};
96
97/* 2.8.1 */
98struct osmo_guti {
99 struct osmo_gummei gummei;
100 uint32_t mtmsi;
101};
Neels Hofmeyr9cd1e742017-10-04 03:15:47 +0200102
103bool osmo_imsi_str_valid(const char *imsi);
104bool osmo_msisdn_str_valid(const char *msisdn);
Oliver Smith894be2d2019-01-11 13:13:37 +0100105bool osmo_imei_str_valid(const char *imei, bool with_15th_digit);
Neels Hofmeyrc4fce142018-02-20 13:47:08 +0100106
107const char *osmo_mcc_name(uint16_t mcc);
Harald Welte4a62eda2019-03-18 18:27:00 +0100108char *osmo_mcc_name_buf(char *buf, size_t buf_len, uint16_t mcc);
Harald Welte179f3572019-03-18 18:38:47 +0100109const char *osmo_mcc_name_c(const void *ctx, uint16_t mcc);
Neels Hofmeyrc4fce142018-02-20 13:47:08 +0100110const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits);
Harald Welte4a62eda2019-03-18 18:27:00 +0100111char *osmo_mnc_name_buf(char *buf, size_t buf_len, uint16_t mnc, bool mnc_3_digits);
Harald Welte179f3572019-03-18 18:38:47 +0100112char *osmo_mnc_name_c(const void *ctx, uint16_t mnc, bool mnc_3_digits);
Neels Hofmeyrc4fce142018-02-20 13:47:08 +0100113const char *osmo_plmn_name(const struct osmo_plmn_id *plmn);
114const char *osmo_plmn_name2(const struct osmo_plmn_id *plmn);
Harald Welte4a62eda2019-03-18 18:27:00 +0100115char *osmo_plmn_name_buf(char *buf, size_t buf_len, const struct osmo_plmn_id *plmn);
Harald Welte179f3572019-03-18 18:38:47 +0100116char *osmo_plmn_name_c(const void *ctx, const struct osmo_plmn_id *plmn);
Neels Hofmeyrc4fce142018-02-20 13:47:08 +0100117const char *osmo_lai_name(const struct osmo_location_area_id *lai);
Harald Welte4a62eda2019-03-18 18:27:00 +0100118char *osmo_lai_name_buf(char *buf, size_t buf_len, const struct osmo_location_area_id *lai);
Harald Welte179f3572019-03-18 18:38:47 +0100119char *osmo_lai_name_c(const void *ctx, const struct osmo_location_area_id *lai);
Neels Hofmeyr43496202018-03-22 14:04:30 +0100120const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi);
121const char *osmo_cgi_name2(const struct osmo_cell_global_id *cgi);
Harald Welte4a62eda2019-03-18 18:27:00 +0100122char *osmo_cgi_name_buf(char *buf, size_t buf_len, const struct osmo_cell_global_id *cgi);
Harald Welte179f3572019-03-18 18:38:47 +0100123char *osmo_cgi_name_c(const void *ctx, const struct osmo_cell_global_id *cgi);
Harald Weltede1da352018-10-08 22:27:04 +0200124const char *osmo_gummei_name(const struct osmo_gummei *gummei);
Harald Welte4a62eda2019-03-18 18:27:00 +0100125char *osmo_gummei_name_buf(char *buf, size_t buf_len, const struct osmo_gummei *gummei);
Harald Welte179f3572019-03-18 18:38:47 +0100126char *osmo_gummei_name_c(const void *ctx, const struct osmo_gummei *gummei);
Neels Hofmeyrc4fce142018-02-20 13:47:08 +0100127
128void osmo_plmn_to_bcd(uint8_t *bcd_dst, const struct osmo_plmn_id *plmn);
129void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn);
Neels Hofmeyr721aa6d2018-02-20 21:38:00 +0100130
131int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits);
132
Neels Hofmeyr4d68fd02018-03-05 04:16:48 +0100133/* Convert string to MCC.
134 * \param mcc_str[in] String representation of an MCC, with or without leading zeros.
135 * \param mcc[out] MCC result buffer, or NULL.
136 * \returns zero on success, -EINVAL in case of surplus characters, negative errno in case of conversion
137 * errors. In case of error, do not modify the out-arguments.
138 */
139static inline int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc)
140{
141 return osmo_mnc_from_str(mcc_str, mcc, NULL);
142}
143
Neels Hofmeyr721aa6d2018-02-20 21:38:00 +0100144int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits);
145int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b);
Neels Hofmeyrd01ef752018-09-21 15:57:26 +0200146int osmo_lai_cmp(const struct osmo_location_area_id *a, const struct osmo_location_area_id *b);
147int osmo_cgi_cmp(const struct osmo_cell_global_id *a, const struct osmo_cell_global_id *b);
Harald Weltede1da352018-10-08 22:27:04 +0200148
149int osmo_gen_home_network_domain(char *out, const struct osmo_plmn_id *plmn);
150int osmo_parse_home_network_domain(struct osmo_plmn_id *out, const char *in);
151int osmo_gen_mme_domain(char *out, const struct osmo_gummei *gummei);
152int osmo_gen_mme_group_domain(char *out, uint16_t mmegi, const struct osmo_plmn_id *plmn);
153int osmo_parse_mme_domain(struct osmo_gummei *out, const char *in);