libosmogsm  1.5.1.118-645a
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 
35  uint16_t cell_identity;
36 };
37 
46 };
47 
48 /* Actually defined in 3GPP TS 48.008 3.2.2.27 Cell Identifier List,
49  * but conceptually belongs with the above structures. */
51  uint16_t lac;
52  uint16_t ci;
53 };
54 
55 /* 12.5 */
58  uint16_t sac;
59 };
60 
61 /* 12.6 */
63  struct osmo_plmn_id plmn;
64  uint32_t snac;
65 };
66 
67 /* 5.1 */
71 };
72 
73 /* 5.1 */
76  uint8_t length;
77  uint8_t addr[16];
78 };
79 
80 /* 19.4.2.3 */
82  struct osmo_plmn_id plmn;
83  uint16_t tac;
84 };
85 
87  struct osmo_plmn_id plmn;
88  uint32_t eci; /* FIXME */
89 };
90 
91 /* 2.8.1 */
92 struct osmo_mme_id {
93  uint16_t group_id;
94  uint8_t code;
95 };
96 
97 /* 2.8.1 */
98 struct osmo_gummei {
99  struct osmo_plmn_id plmn;
100  struct osmo_mme_id mme;
101 };
102 
103 /* 2.8.1 */
104 struct osmo_guti {
105  struct osmo_gummei gummei;
106  uint32_t mtmsi;
107 };
108 
109 bool osmo_imsi_str_valid(const char *imsi);
110 bool osmo_msisdn_str_valid(const char *msisdn);
111 bool osmo_imei_str_valid(const char *imei, bool with_15th_digit);
112 
113 const char *osmo_mcc_name(uint16_t mcc);
114 char *osmo_mcc_name_buf(char *buf, size_t buf_len, uint16_t mcc);
115 const char *osmo_mcc_name_c(const void *ctx, uint16_t mcc);
116 const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits);
117 char *osmo_mnc_name_buf(char *buf, size_t buf_len, uint16_t mnc, bool mnc_3_digits);
118 char *osmo_mnc_name_c(const void *ctx, uint16_t mnc, bool mnc_3_digits);
119 const char *osmo_plmn_name(const struct osmo_plmn_id *plmn);
120 const char *osmo_plmn_name2(const struct osmo_plmn_id *plmn);
121 char *osmo_plmn_name_buf(char *buf, size_t buf_len, const struct osmo_plmn_id *plmn);
122 char *osmo_plmn_name_c(const void *ctx, const struct osmo_plmn_id *plmn);
123 const char *osmo_lai_name(const struct osmo_location_area_id *lai);
124 char *osmo_lai_name_buf(char *buf, size_t buf_len, const struct osmo_location_area_id *lai);
125 char *osmo_lai_name_c(const void *ctx, const struct osmo_location_area_id *lai);
126 const char *osmo_rai_name2(const struct osmo_routing_area_id *rai);
127 char *osmo_rai_name2_buf(char *buf, size_t buf_len, const struct osmo_routing_area_id *rai);
128 char *osmo_rai_name2_c(const void *ctx, const struct osmo_routing_area_id *rai);
129 const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi);
130 const char *osmo_cgi_name2(const struct osmo_cell_global_id *cgi);
131 char *osmo_cgi_name_buf(char *buf, size_t buf_len, const struct osmo_cell_global_id *cgi);
132 char *osmo_cgi_name_c(const void *ctx, const struct osmo_cell_global_id *cgi);
133 const char *osmo_cgi_ps_name(const struct osmo_cell_global_id_ps *cgi_ps);
134 const char *osmo_cgi_ps_name2(const struct osmo_cell_global_id_ps *cgi_ps);
135 char *osmo_cgi_ps_name_buf(char *buf, size_t buf_len, const struct osmo_cell_global_id_ps *cgi_ps);
136 char *osmo_cgi_ps_name_c(const void *ctx, const struct osmo_cell_global_id_ps *cgi_ps);
137 const char *osmo_gummei_name(const struct osmo_gummei *gummei);
138 char *osmo_gummei_name_buf(char *buf, size_t buf_len, const struct osmo_gummei *gummei);
139 char *osmo_gummei_name_c(const void *ctx, const struct osmo_gummei *gummei);
140 
141 void osmo_plmn_to_bcd(uint8_t *bcd_dst, const struct osmo_plmn_id *plmn);
142 void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn);
143 
144 int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits);
145 
146 /* Convert string to MCC.
147  * \param mcc_str[in] String representation of an MCC, with or without leading zeros.
148  * \param mcc[out] MCC result buffer, or NULL.
149  * \returns zero on success, -EINVAL in case of surplus characters, negative errno in case of conversion
150  * errors. In case of error, do not modify the out-arguments.
151  */
152 static inline int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc)
153 {
154  return osmo_mnc_from_str(mcc_str, mcc, NULL);
155 }
156 
157 int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits);
158 int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b);
159 int osmo_lai_cmp(const struct osmo_location_area_id *a, const struct osmo_location_area_id *b);
160 int osmo_rai_cmp(const struct osmo_routing_area_id *a, const struct osmo_routing_area_id *b);
161 int osmo_cgi_cmp(const struct osmo_cell_global_id *a, const struct osmo_cell_global_id *b);
162 int osmo_cgi_ps_cmp(const struct osmo_cell_global_id_ps *a, const struct osmo_cell_global_id_ps *b);
163 
164 int osmo_gen_home_network_domain(char *out, const struct osmo_plmn_id *plmn);
165 int osmo_parse_home_network_domain(struct osmo_plmn_id *out, const char *in);
166 int osmo_gen_mme_domain(char *out, const struct osmo_gummei *gummei);
167 int osmo_gen_mme_group_domain(char *out, uint16_t mmegi, const struct osmo_plmn_id *plmn);
168 int osmo_parse_mme_domain(struct osmo_gummei *out, const char *in);
osmo_gsn_addr_type
Definition: gsm23003.h:68
int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits)
Definition: gsm23003.c:488
Definition: gsm23003.h:70
Definition: gsm23003.h:33
uint8_t type
Definition: gsm_08_08.h:470
Definition: gsm23003.h:98
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:434
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:242
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:293
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:623
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:653
bool osmo_msisdn_str_valid(const char *msisdn)
Determine whether the given MSISDN is valid according to 3GPP TS 23.003.
Definition: gsm23003.c:70
uint8_t rac
Definition: gsm23003.h:24
uint16_t lac
Definition: gsm23003.h:51
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:369
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:337
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:119
uint16_t tac
Definition: gsm23003.h:83
bool osmo_imsi_str_valid(const char *imsi)
Determine whether the given IMSI is valid according to 3GPP TS 23.003.
Definition: gsm23003.c:60
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:84
int osmo_rai_cmp(const struct osmo_routing_area_id *a, const struct osmo_routing_area_id *b)
Definition: gsm23003.c:573
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:171
Definition: gsm23003.h:9
uint16_t sac
Definition: gsm23003.h:58
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:256
Definition: gsm23003.h:86
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:325
static int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc)
Definition: gsm23003.h:152
Definition: gsm23003.h:50
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:636
Definition: gsm23003.h:62
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:134
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:358
Definition: gsm23003.h:43
Definition: gsm23003.h:92
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:98
Definition: gsm23003.h:69
Definition: gsm23003.h:74
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:183
Definition: gsm23003.h:104
uint16_t group_id
Definition: gsm23003.h:93
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:194
uint8_t length
Definition: gsm23003.h:76
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:687
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:314
int osmo_cgi_ps_cmp(const struct osmo_cell_global_id_ps *a, const struct osmo_cell_global_id_ps *b)
Definition: gsm23003.c:607
uint32_t eci
Definition: gsm23003.h:88
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:231
const char * osmo_gummei_name(const struct osmo_gummei *gummei)
Return string representation of GUMMEI in static output buffer.
Definition: gsm23003.c:402
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:390
Definition: gsm23003.h:56
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:206
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:41
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:524
uint32_t snac
Definition: gsm23003.h:64
void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn)
Definition: gsm23003.c:461
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:347
Definition: gsm23003.h:44
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:220
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:146
uint16_t ci
Definition: gsm23003.h:52
const char * osmo_mcc_name(uint16_t mcc)
Return MCC string as standardized 3-digit with leading zeros.
Definition: gsm23003.c:108
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:268
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:303
uint8_t code
Definition: gsm23003.h:94
struct osmo_plmn_id plmn
Definition: gsm23003.h:99
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:414
uint16_t lac
Definition: gsm23003.h:18
struct gsm48_loc_area_id lai
Definition: gsm_04_08.h:762
uint16_t lac
Definition: gsm_04_08.h:761
int osmo_lai_cmp(const struct osmo_location_area_id *a, const struct osmo_location_area_id *b)
Definition: gsm23003.c:556
int osmo_cgi_cmp(const struct osmo_cell_global_id *a, const struct osmo_cell_global_id *b)
Definition: gsm23003.c:590
uint16_t cell_identity
Definition: gsm23003.h:35
Definition: gsm23003.h:45
Definition: gsm23003.h:81
Definition: gsm23003.h:42
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:667
uint32_t mtmsi
Definition: gsm23003.h:106
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:159
int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b)
Definition: gsm23003.c:540
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:279