blob: b34a677b57ad151974a1c197074c2a445f3cff05 [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
Stefan Sperling11a4d9d2018-02-15 18:28:04 +010033/* Actually defined in 3GPP TS 48.008 3.2.2.27 Cell Identifier List,
34 * but conceptually belongs with the above structures. */
35struct osmo_lac_and_ci_id {
36 uint16_t lac;
37 uint16_t ci;
38};
39
Harald Weltebda26c02016-05-11 09:13:08 +020040/* 12.5 */
41struct osmo_service_area_id {
42 struct osmo_location_area_id lai;
43 uint16_t sac;
44};
45
46/* 12.6 */
47struct osmo_shared_network_area_id {
48 struct osmo_plmn_id plmn;
49 uint32_t snac;
50};
51
52/* 5.1 */
53enum osmo_gsn_addr_type {
54 GSN_ADDR_TYPE_IPV4 = 0,
55 GSN_ADDR_TYPE_IPV6 = 1,
56};
57
58/* 5.1 */
59struct osmo_gsn_address {
60 enum osmo_gsn_addr_type type;
61 uint8_t length;
62 uint8_t addr[16];
63};
64
65/* 19.4.2.3 */
66struct osmo_tracking_area_id {
67 struct osmo_plmn_id plmn;
68 uint16_t tac;
69};
70
71struct osmo_eutran_cell_global_id {
72 struct osmo_plmn_id plmn;
73 uint32_t eci; /* FIXME */
74};
75
76/* 2.8.1 */
77struct osmo_mme_id {
78 uint16_t group_id;
79 uint8_t code;
80};
81
82/* 2.8.1 */
83struct osmo_gummei {
84 struct osmo_plmn_id plmn;
85 struct osmo_mme_id mme;
86};
87
88/* 2.8.1 */
89struct osmo_guti {
90 struct osmo_gummei gummei;
91 uint32_t mtmsi;
92};
Neels Hofmeyr9cd1e742017-10-04 03:15:47 +020093
94bool osmo_imsi_str_valid(const char *imsi);
95bool osmo_msisdn_str_valid(const char *msisdn);
Oliver Smith894be2d2019-01-11 13:13:37 +010096bool osmo_imei_str_valid(const char *imei, bool with_15th_digit);
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010097
98const char *osmo_mcc_name(uint16_t mcc);
99const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits);
100const char *osmo_plmn_name(const struct osmo_plmn_id *plmn);
101const char *osmo_plmn_name2(const struct osmo_plmn_id *plmn);
102const char *osmo_lai_name(const struct osmo_location_area_id *lai);
Neels Hofmeyr43496202018-03-22 14:04:30 +0100103const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi);
104const char *osmo_cgi_name2(const struct osmo_cell_global_id *cgi);
Harald Weltede1da352018-10-08 22:27:04 +0200105const char *osmo_gummei_name(const struct osmo_gummei *gummei);
Neels Hofmeyrc4fce142018-02-20 13:47:08 +0100106
107void osmo_plmn_to_bcd(uint8_t *bcd_dst, const struct osmo_plmn_id *plmn);
108void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn);
Neels Hofmeyr721aa6d2018-02-20 21:38:00 +0100109
110int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits);
111
Neels Hofmeyr4d68fd02018-03-05 04:16:48 +0100112/* Convert string to MCC.
113 * \param mcc_str[in] String representation of an MCC, with or without leading zeros.
114 * \param mcc[out] MCC result buffer, or NULL.
115 * \returns zero on success, -EINVAL in case of surplus characters, negative errno in case of conversion
116 * errors. In case of error, do not modify the out-arguments.
117 */
118static inline int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc)
119{
120 return osmo_mnc_from_str(mcc_str, mcc, NULL);
121}
122
Neels Hofmeyr721aa6d2018-02-20 21:38:00 +0100123int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits);
124int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b);
Neels Hofmeyrd01ef752018-09-21 15:57:26 +0200125int osmo_lai_cmp(const struct osmo_location_area_id *a, const struct osmo_location_area_id *b);
126int osmo_cgi_cmp(const struct osmo_cell_global_id *a, const struct osmo_cell_global_id *b);
Harald Weltede1da352018-10-08 22:27:04 +0200127
128int osmo_gen_home_network_domain(char *out, const struct osmo_plmn_id *plmn);
129int osmo_parse_home_network_domain(struct osmo_plmn_id *out, const char *in);
130int osmo_gen_mme_domain(char *out, const struct osmo_gummei *gummei);
131int osmo_gen_mme_group_domain(char *out, uint16_t mmegi, const struct osmo_plmn_id *plmn);
132int osmo_parse_mme_domain(struct osmo_gummei *out, const char *in);