libosmogsm  1.3.1
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 
40 };
41 
42 /* Actually defined in 3GPP TS 48.008 3.2.2.27 Cell Identifier List,
43  * but conceptually belongs with the above structures. */
45  uint16_t lac;
46  uint16_t ci;
47 };
48 
49 /* 12.5 */
52  uint16_t sac;
53 };
54 
55 /* 12.6 */
57  struct osmo_plmn_id plmn;
58  uint32_t snac;
59 };
60 
61 /* 5.1 */
65 };
66 
67 /* 5.1 */
70  uint8_t length;
71  uint8_t addr[16];
72 };
73 
74 /* 19.4.2.3 */
76  struct osmo_plmn_id plmn;
77  uint16_t tac;
78 };
79 
81  struct osmo_plmn_id plmn;
82  uint32_t eci; /* FIXME */
83 };
84 
85 /* 2.8.1 */
86 struct osmo_mme_id {
87  uint16_t group_id;
88  uint8_t code;
89 };
90 
91 /* 2.8.1 */
92 struct osmo_gummei {
93  struct osmo_plmn_id plmn;
94  struct osmo_mme_id mme;
95 };
96 
97 /* 2.8.1 */
98 struct osmo_guti {
99  struct osmo_gummei gummei;
100  uint32_t mtmsi;
101 };
102 
103 bool osmo_imsi_str_valid(const char *imsi);
104 bool osmo_msisdn_str_valid(const char *msisdn);
105 bool osmo_imei_str_valid(const char *imei, bool with_15th_digit);
106 
107 const char *osmo_mcc_name(uint16_t mcc);
108 char *osmo_mcc_name_buf(char *buf, size_t buf_len, uint16_t mcc);
109 const char *osmo_mcc_name_c(const void *ctx, uint16_t mcc);
110 const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits);
111 char *osmo_mnc_name_buf(char *buf, size_t buf_len, uint16_t mnc, bool mnc_3_digits);
112 char *osmo_mnc_name_c(const void *ctx, uint16_t mnc, bool mnc_3_digits);
113 const char *osmo_plmn_name(const struct osmo_plmn_id *plmn);
114 const char *osmo_plmn_name2(const struct osmo_plmn_id *plmn);
115 char *osmo_plmn_name_buf(char *buf, size_t buf_len, const struct osmo_plmn_id *plmn);
116 char *osmo_plmn_name_c(const void *ctx, const struct osmo_plmn_id *plmn);
117 const char *osmo_lai_name(const struct osmo_location_area_id *lai);
118 char *osmo_lai_name_buf(char *buf, size_t buf_len, const struct osmo_location_area_id *lai);
119 char *osmo_lai_name_c(const void *ctx, const struct osmo_location_area_id *lai);
120 const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi);
121 const char *osmo_cgi_name2(const struct osmo_cell_global_id *cgi);
122 char *osmo_cgi_name_buf(char *buf, size_t buf_len, const struct osmo_cell_global_id *cgi);
123 char *osmo_cgi_name_c(const void *ctx, const struct osmo_cell_global_id *cgi);
124 const char *osmo_gummei_name(const struct osmo_gummei *gummei);
125 char *osmo_gummei_name_buf(char *buf, size_t buf_len, const struct osmo_gummei *gummei);
126 char *osmo_gummei_name_c(const void *ctx, const struct osmo_gummei *gummei);
127 
128 void osmo_plmn_to_bcd(uint8_t *bcd_dst, const struct osmo_plmn_id *plmn);
129 void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn);
130 
131 int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits);
132 
133 /* 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  */
139 static 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 
144 int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits);
145 int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b);
146 int osmo_lai_cmp(const struct osmo_location_area_id *a, const struct osmo_location_area_id *b);
147 int osmo_cgi_cmp(const struct osmo_cell_global_id *a, const struct osmo_cell_global_id *b);
148 
149 int osmo_gen_home_network_domain(char *out, const struct osmo_plmn_id *plmn);
150 int osmo_parse_home_network_domain(struct osmo_plmn_id *out, const char *in);
151 int osmo_gen_mme_domain(char *out, const struct osmo_gummei *gummei);
152 int osmo_gen_mme_group_domain(char *out, uint16_t mmegi, const struct osmo_plmn_id *plmn);
153 int osmo_parse_mme_domain(struct osmo_gummei *out, const char *in);
osmo_gsn_addr_type
Definition: gsm23003.h:62
int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits)
Definition: gsm23003.c:407
Definition: gsm23003.h:64
uint8_t type
Definition: gsm_08_08.h:469
Definition: gsm23003.h:92
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:353
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:256
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:508
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:538
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:45
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:77
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
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:52
Definition: gsm23003.h:80
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:288
static int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc)
Definition: gsm23003.h:139
Definition: gsm23003.h:44
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:521
Definition: gsm23003.h:56
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
Definition: gsm23003.h:38
Definition: gsm23003.h:86
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:63
Definition: gsm23003.h:68
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:98
uint16_t group_id
Definition: gsm23003.h:87
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:70
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:572
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:277
uint32_t eci
Definition: gsm23003.h:82
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:321
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:309
Definition: gsm23003.h:50
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:36
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:443
uint32_t snac
Definition: gsm23003.h:58
void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn)
Definition: gsm23003.c:380
Definition: gsm23003.h:16
Definition: gsm23003.h:39
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:46
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_cgi_name(const struct osmo_cell_global_id *cgi)
Return MCC-MNC-LAC-CI as string, in a static buffer.
Definition: gsm23003.c:266
uint8_t code
Definition: gsm23003.h:88
struct osmo_plmn_id plmn
Definition: gsm23003.h:93
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:333
uint16_t lac
Definition: gsm23003.h:18
struct gsm48_loc_area_id lai
Definition: gsm_04_08.h:827
uint16_t lac
Definition: gsm_04_08.h:826
int osmo_lai_cmp(const struct osmo_location_area_id *a, const struct osmo_location_area_id *b)
Definition: gsm23003.c:475
int osmo_cgi_cmp(const struct osmo_cell_global_id *a, const struct osmo_cell_global_id *b)
Definition: gsm23003.c:492
Definition: gsm23003.h:75
Definition: gsm23003.h:37
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:552
uint32_t mtmsi
Definition: gsm23003.h:100
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:459