libosmogsm  1.9.0.19-e4f34.202310252026
Osmocom GSM library
gsm23003.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <stdint.h>
6 #include <stdbool.h>
7 
8 /* 23.003 Chapter 12.1 */
9 struct osmo_plmn_id {
10  uint16_t mcc;
11  uint16_t mnc;
12  bool mnc_3_digits; /*< ignored and implied true if mnc > 99, otherwise defines leading zeros. */
13 };
14 
15 /* 4.1 */
17  struct osmo_plmn_id plmn;
18  uint16_t lac;
19 };
20 
21 /* 4.2 */
24  uint8_t rac;
25 };
26 
27 /* 4.3.1 */
30  uint16_t cell_identity;
31 };
32 
33 /* 3GPP TS 48.018:
34  * 8c.1.4.1.1 GERAN BSS identification (RIM)
35  * sec 11.3.9 Cell Identifier */
38  uint16_t cell_identity;
39 };
40 
49 };
50 
51 /* Actually defined in 3GPP TS 48.008 3.2.2.27 Cell Identifier List,
52  * but conceptually belongs with the above structures. */
54  uint16_t lac;
55  uint16_t ci;
56 };
57 
58 /* 12.5 */
61  uint16_t sac;
62 };
63 
64 /* 12.6 */
66  struct osmo_plmn_id plmn;
67  uint32_t snac;
68 };
69 
70 /* 5.1 */
74 };
75 
76 /* 5.1 */
79  uint8_t length;
80  uint8_t addr[16];
81 };
82 
83 /* 19.4.2.3 */
85  struct osmo_plmn_id plmn;
86  uint16_t tac;
87 };
88 
90  struct osmo_plmn_id plmn;
91  uint32_t eci; /* FIXME */
92 };
93 
94 /* 2.8.1 */
95 struct osmo_mme_id {
96  uint16_t group_id;
97  uint8_t code;
98 };
99 
100 /* 2.8.1 */
101 struct osmo_gummei {
102  struct osmo_plmn_id plmn;
103  struct osmo_mme_id mme;
104 };
105 
106 /* 2.8.1 */
107 struct osmo_guti {
108  struct osmo_gummei gummei;
109  uint32_t mtmsi;
110 };
111 
112 bool osmo_imsi_str_valid(const char *imsi);
113 bool osmo_msisdn_str_valid(const char *msisdn);
114 bool osmo_imei_str_valid(const char *imei, bool with_15th_digit);
115 
116 const char *osmo_mcc_name(uint16_t mcc);
117 char *osmo_mcc_name_buf(char *buf, size_t buf_len, uint16_t mcc);
118 const char *osmo_mcc_name_c(const void *ctx, uint16_t mcc);
119 const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits);
120 char *osmo_mnc_name_buf(char *buf, size_t buf_len, uint16_t mnc, bool mnc_3_digits);
121 char *osmo_mnc_name_c(const void *ctx, uint16_t mnc, bool mnc_3_digits);
122 const char *osmo_plmn_name(const struct osmo_plmn_id *plmn);
123 const char *osmo_plmn_name2(const struct osmo_plmn_id *plmn);
124 char *osmo_plmn_name_buf(char *buf, size_t buf_len, const struct osmo_plmn_id *plmn);
125 char *osmo_plmn_name_c(const void *ctx, const struct osmo_plmn_id *plmn);
126 const char *osmo_lai_name(const struct osmo_location_area_id *lai);
127 char *osmo_lai_name_buf(char *buf, size_t buf_len, const struct osmo_location_area_id *lai);
128 char *osmo_lai_name_c(const void *ctx, const struct osmo_location_area_id *lai);
129 const char *osmo_rai_name2(const struct osmo_routing_area_id *rai);
130 char *osmo_rai_name2_buf(char *buf, size_t buf_len, const struct osmo_routing_area_id *rai);
131 char *osmo_rai_name2_c(const void *ctx, const struct osmo_routing_area_id *rai);
132 const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi);
133 const char *osmo_cgi_name2(const struct osmo_cell_global_id *cgi);
134 char *osmo_cgi_name_buf(char *buf, size_t buf_len, const struct osmo_cell_global_id *cgi);
135 char *osmo_cgi_name_c(const void *ctx, const struct osmo_cell_global_id *cgi);
136 const char *osmo_cgi_ps_name(const struct osmo_cell_global_id_ps *cgi_ps);
137 const char *osmo_cgi_ps_name2(const struct osmo_cell_global_id_ps *cgi_ps);
138 char *osmo_cgi_ps_name_buf(char *buf, size_t buf_len, const struct osmo_cell_global_id_ps *cgi_ps);
139 char *osmo_cgi_ps_name_c(const void *ctx, const struct osmo_cell_global_id_ps *cgi_ps);
140 const char *osmo_sai_name(const struct osmo_service_area_id *sai);
141 const char *osmo_sai_name2(const struct osmo_service_area_id *sai);
142 char *osmo_sai_name_buf(char *buf, size_t buf_len, const struct osmo_service_area_id *sai);
143 char *osmo_sai_name_c(const void *ctx, const struct osmo_service_area_id *sai);
144 const char *osmo_gummei_name(const struct osmo_gummei *gummei);
145 char *osmo_gummei_name_buf(char *buf, size_t buf_len, const struct osmo_gummei *gummei);
146 char *osmo_gummei_name_c(const void *ctx, const struct osmo_gummei *gummei);
147 
148 void osmo_plmn_to_bcd(uint8_t *bcd_dst, const struct osmo_plmn_id *plmn);
149 void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn);
150 
151 int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits);
152 
153 /* Convert string to MCC.
154  * \param mcc_str[in] String representation of an MCC, with or without leading zeros.
155  * \param mcc[out] MCC result buffer, or NULL.
156  * \returns zero on success, -EINVAL in case of surplus characters, negative errno in case of conversion
157  * errors. In case of error, do not modify the out-arguments.
158  */
159 static inline int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc)
160 {
161  return osmo_mnc_from_str(mcc_str, mcc, NULL);
162 }
163 
164 int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits);
165 int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b);
166 int osmo_lai_cmp(const struct osmo_location_area_id *a, const struct osmo_location_area_id *b);
167 int osmo_rai_cmp(const struct osmo_routing_area_id *a, const struct osmo_routing_area_id *b);
168 int osmo_cgi_cmp(const struct osmo_cell_global_id *a, const struct osmo_cell_global_id *b);
169 int osmo_cgi_ps_cmp(const struct osmo_cell_global_id_ps *a, const struct osmo_cell_global_id_ps *b);
170 
171 int osmo_gen_home_network_domain(char *out, const struct osmo_plmn_id *plmn);
172 int osmo_parse_home_network_domain(struct osmo_plmn_id *out, const char *in);
173 int osmo_gen_mme_domain(char *out, const struct osmo_gummei *gummei);
174 int osmo_gen_mme_group_domain(char *out, uint16_t mmegi, const struct osmo_plmn_id *plmn);
175 int osmo_parse_mme_domain(struct osmo_gummei *out, const char *in);
osmo_gsn_addr_type
Definition: gsm23003.h:71
int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits)
Definition: gsm23003.c:527
Definition: gsm23003.h:73
Definition: gsm23003.h:36
uint8_t type
Definition: gsm_08_08.h:484
Definition: gsm23003.h:101
uint16_t cell_identity
Definition: gsm23003.h:30
void osmo_plmn_to_bcd(uint8_t *bcd_dst, const struct osmo_plmn_id *plmn)
Definition: gsm23003.c:475
char * osmo_lai_name_c(const void *ctx, const struct osmo_location_area_id *lai)
Return MCC-MNC-LAC as string, in a talloc-allocated output buffer.
Definition: gsm23003.c:238
char * osmo_cgi_name_buf(char *buf, size_t buf_len, const struct osmo_cell_global_id *cgi)
Return MCC-MNC-LAC-CI as string, in caller-provided output buffer.
Definition: gsm23003.c:289
int osmo_gen_home_network_domain(char *out, const struct osmo_plmn_id *plmn)
Generate TS 23.003 Section 19.2 Home Network Realm/Domain (text form)
Definition: gsm23003.c:663
int osmo_gen_mme_domain(char *out, const struct osmo_gummei *gummei)
Generate TS 23.003 Section 19.4.2.4 MME Domain (text form)
Definition: gsm23003.c:693
bool osmo_msisdn_str_valid(const char *msisdn)
Determine whether the given MSISDN is valid according to 3GPP TS 23.003.
Definition: gsm23003.c:66
uint8_t rac
Definition: gsm23003.h:24
uint16_t lac
Definition: gsm23003.h:54
char * osmo_cgi_ps_name_c(const void *ctx, const struct osmo_cell_global_id_ps *cgi_ps)
Return MCC-MNC-LAC-RAC-CI as string, in a talloc-allocated output buffer.
Definition: gsm23003.c:365
char * osmo_cgi_ps_name_buf(char *buf, size_t buf_len, const struct osmo_cell_global_id_ps *cgi_ps)
Return MCC-MNC-LAC-RAC-CI as string, in caller-provided output buffer.
Definition: gsm23003.c:333
Definition: gsm23003.h:22
const char * osmo_mcc_name_c(const void *ctx, uint16_t mcc)
Return MCC string as standardized 3-digit with leading zeros, into a talloc-allocated buffer...
Definition: gsm23003.c:115
uint16_t tac
Definition: gsm23003.h:86
bool osmo_imsi_str_valid(const char *imsi)
Determine whether the given IMSI is valid according to 3GPP TS 23.003.
Definition: gsm23003.c:56
bool osmo_imei_str_valid(const char *imei, bool with_15th_digit)
Determine whether the given IMEI is valid according to 3GPP TS 23.003, Section 6.2.1.
Definition: gsm23003.c:80
int osmo_rai_cmp(const struct osmo_routing_area_id *a, const struct osmo_routing_area_id *b)
Definition: gsm23003.c:613
char * osmo_plmn_name_buf(char *buf, size_t buf_len, const struct osmo_plmn_id *plmn)
Return MCC-MNC string as standardized 3-digit-dash-2/3-digit with leading zeros.
Definition: gsm23003.c:167
Definition: gsm23003.h:9
uint16_t sac
Definition: gsm23003.h:61
char * osmo_rai_name2_buf(char *buf, size_t buf_len, const struct osmo_routing_area_id *rai)
Return MCC-MNC-LAC-RAC as string, in caller-provided output buffer.
Definition: gsm23003.c:252
Definition: gsm23003.h:89
char * osmo_cgi_name_c(const void *ctx, const struct osmo_cell_global_id *cgi)
Return MCC-MNC-LAC-CI as string, in a talloc-allocated output buffer.
Definition: gsm23003.c:321
static int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc)
Definition: gsm23003.h:159
Definition: gsm23003.h:53
int osmo_parse_home_network_domain(struct osmo_plmn_id *out, const char *in)
Parse a TS 23.003 Section 19.2 Home Network Realm/Domain (text form) into a osmo_plmn_id.
Definition: gsm23003.c:676
const char * osmo_sai_name(const struct osmo_service_area_id *sai)
Return MCC-MNC-LAC-SAC as string, in a static buffer.
Definition: gsm23003.c:387
Definition: gsm23003.h:65
char * osmo_mnc_name_buf(char *buf, size_t buf_len, uint16_t mnc, bool mnc_3_digits)
Return MNC string as standardized 2- or 3-digit with leading zeros.
Definition: gsm23003.c:130
const char * osmo_sai_name2(const struct osmo_service_area_id *sai)
Same as osmo_cgi_name(), but uses a different static buffer.
Definition: gsm23003.c:398
const char * osmo_cgi_ps_name2(const struct osmo_cell_global_id_ps *cgi_ps)
Same as osmo_cgi_ps_name(), but uses a different static buffer.
Definition: gsm23003.c:354
Definition: gsm23003.h:46
Definition: gsm23003.h:95
char * osmo_mcc_name_buf(char *buf, size_t buf_len, uint16_t mcc)
Return MCC string as standardized 3-digit with leading zeros.
Definition: gsm23003.c:94
Definition: gsm23003.h:72
char * osmo_sai_name_c(const void *ctx, const struct osmo_service_area_id *sai)
Return MCC-MNC-LAC-SAC as string, in a talloc-allocated output buffer.
Definition: gsm23003.c:409
Definition: gsm23003.h:77
const char * osmo_plmn_name(const struct osmo_plmn_id *plmn)
Return MCC-MNC string as standardized 3-digit-dash-2/3-digit with leading zeros.
Definition: gsm23003.c:179
Definition: gsm23003.h:107
uint16_t group_id
Definition: gsm23003.h:96
uint16_t mnc
Definition: gsm23003.h:11
uint16_t mcc
Definition: gsm23003.h:10
const char * osmo_plmn_name2(const struct osmo_plmn_id *plmn)
Same as osmo_plmn_name(), but returning in a different static buffer.
Definition: gsm23003.c:190
uint8_t length
Definition: gsm23003.h:79
int osmo_gen_mme_group_domain(char *out, uint16_t mmegi, const struct osmo_plmn_id *plmn)
Generate TS 23.003 Section 19.4.2.4 MME Group Domain (text form)
Definition: gsm23003.c:727
const char * osmo_cgi_name2(const struct osmo_cell_global_id *cgi)
Same as osmo_cgi_name(), but uses a different static buffer.
Definition: gsm23003.c:310
int osmo_cgi_ps_cmp(const struct osmo_cell_global_id_ps *a, const struct osmo_cell_global_id_ps *b)
Definition: gsm23003.c:647
uint32_t eci
Definition: gsm23003.h:91
const char * osmo_lai_name(const struct osmo_location_area_id *lai)
Return MCC-MNC-LAC as string, in a static buffer.
Definition: gsm23003.c:227
const char * osmo_gummei_name(const struct osmo_gummei *gummei)
Return string representation of GUMMEI in static output buffer.
Definition: gsm23003.c:443
Definition: gsm23003.h:28
char * osmo_gummei_name_buf(char *buf, size_t buf_len, const struct osmo_gummei *gummei)
Return string representation of GUMMEI in caller-provided output buffer.
Definition: gsm23003.c:431
Definition: gsm23003.h:59
char * osmo_plmn_name_c(const void *ctx, const struct osmo_plmn_id *plmn)
Return MCC-MNC string as standardized 3-digit-dash-2/3-digit with leading zeros, into a dynamically-a...
Definition: gsm23003.c:202
bool mnc_3_digits
Definition: gsm23003.h:12
osmo_cgi_part
Bitmask of items contained in a struct osmo_cell_global_id.
Definition: gsm23003.h:44
int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits)
Definition: gsm23003.c:564
uint32_t snac
Definition: gsm23003.h:67
void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn)
Definition: gsm23003.c:500
Definition: gsm23003.h:16
const char * osmo_cgi_ps_name(const struct osmo_cell_global_id_ps *cgi_ps)
Return MCC-MNC-LAC-RAC-CI as string, in a static buffer.
Definition: gsm23003.c:343
char * osmo_sai_name_buf(char *buf, size_t buf_len, const struct osmo_service_area_id *sai)
Return MCC-MNC-LAC-SAC as string, in caller-provided output buffer.
Definition: gsm23003.c:377
Definition: gsm23003.h:47
char * osmo_lai_name_buf(char *buf, size_t buf_len, const struct osmo_location_area_id *lai)
Return MCC-MNC-LAC as string, in caller-provided output buffer.
Definition: gsm23003.c:216
char * osmo_mnc_name_c(const void *ctx, uint16_t mnc, bool mnc_3_digits)
Return MNC string as standardized 2- or 3-digit with leading zeros, into a talloc-allocated buffer...
Definition: gsm23003.c:142
uint16_t ci
Definition: gsm23003.h:55
const char * osmo_mcc_name(uint16_t mcc)
Return MCC string as standardized 3-digit with leading zeros.
Definition: gsm23003.c:104
const char * osmo_rai_name2(const struct osmo_routing_area_id *rai)
Return MCC-MNC-LAC-RAC as string, in a static buffer.
Definition: gsm23003.c:264
const char * osmo_cgi_name(const struct osmo_cell_global_id *cgi)
Return MCC-MNC-LAC-CI as string, in a static buffer.
Definition: gsm23003.c:299
uint8_t code
Definition: gsm23003.h:97
struct osmo_plmn_id plmn
Definition: gsm23003.h:102
char * osmo_gummei_name_c(const void *ctx, const struct osmo_gummei *gummei)
Return string representation of GUMMEI in static output buffer.
Definition: gsm23003.c:455
uint16_t lac
Definition: gsm23003.h:18
struct gsm48_loc_area_id lai
Definition: gsm_04_08.h:808
uint16_t lac
Definition: gsm_04_08.h:807
int osmo_lai_cmp(const struct osmo_location_area_id *a, const struct osmo_location_area_id *b)
Definition: gsm23003.c:596
int osmo_cgi_cmp(const struct osmo_cell_global_id *a, const struct osmo_cell_global_id *b)
Definition: gsm23003.c:630
uint16_t cell_identity
Definition: gsm23003.h:38
Definition: gsm23003.h:48
Definition: gsm23003.h:84
Definition: gsm23003.h:45
int osmo_parse_mme_domain(struct osmo_gummei *out, const char *in)
Parse a TS 23.003 Section 19.4.2.4 MME Domain (text form) into a osmo_gummei.
Definition: gsm23003.c:707
uint32_t mtmsi
Definition: gsm23003.h:109
const char * osmo_mnc_name(uint16_t mnc, bool mnc_3_digits)
Return MNC string as standardized 2- or 3-digit with leading zeros.
Definition: gsm23003.c:155
int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b)
Definition: gsm23003.c:580
char * osmo_rai_name2_c(const void *ctx, const struct osmo_routing_area_id *rai)
Return MCC-MNC-LAC-RAC as string, in a talloc-allocated output buffer.
Definition: gsm23003.c:275