libosmogsm  0.12.0
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 /* Actually defined in 3GPP TS 48.008 3.2.2.27 Cell Identifier List,
34  * but conceptually belongs with the above structures. */
36  uint16_t lac;
37  uint16_t ci;
38 };
39 
40 /* 12.5 */
43  uint16_t sac;
44 };
45 
46 /* 12.6 */
48  struct osmo_plmn_id plmn;
49  uint32_t snac;
50 };
51 
52 /* 5.1 */
56 };
57 
58 /* 5.1 */
61  uint8_t length;
62  uint8_t addr[16];
63 };
64 
65 /* 19.4.2.3 */
67  struct osmo_plmn_id plmn;
68  uint16_t tac;
69 };
70 
72  struct osmo_plmn_id plmn;
73  uint32_t eci; /* FIXME */
74 };
75 
76 /* 2.8.1 */
77 struct osmo_mme_id {
78  uint16_t group_id;
79  uint8_t code;
80 };
81 
82 /* 2.8.1 */
83 struct osmo_gummei {
84  struct osmo_plmn_id plmn;
85  struct osmo_mme_id mme;
86 };
87 
88 /* 2.8.1 */
89 struct osmo_guti {
90  struct osmo_gummei gummei;
91  uint32_t mtmsi;
92 };
93 
94 bool osmo_imsi_str_valid(const char *imsi);
95 bool osmo_msisdn_str_valid(const char *msisdn);
96 
97 const char *osmo_mcc_name(uint16_t mcc);
98 const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits);
99 const char *osmo_plmn_name(const struct osmo_plmn_id *plmn);
100 const char *osmo_plmn_name2(const struct osmo_plmn_id *plmn);
101 const char *osmo_lai_name(const struct osmo_location_area_id *lai);
102 const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi);
103 const char *osmo_cgi_name2(const struct osmo_cell_global_id *cgi);
104 
105 void osmo_plmn_to_bcd(uint8_t *bcd_dst, const struct osmo_plmn_id *plmn);
106 void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn);
107 
108 int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits);
109 
110 /* Convert string to MCC.
111  * \param mcc_str[in] String representation of an MCC, with or without leading zeros.
112  * \param mcc[out] MCC result buffer, or NULL.
113  * \returns zero on success, -EINVAL in case of surplus characters, negative errno in case of conversion
114  * errors. In case of error, do not modify the out-arguments.
115  */
116 static inline int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc)
117 {
118  return osmo_mnc_from_str(mcc_str, mcc, NULL);
119 }
120 
121 int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits);
122 int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b);
osmo_gsn_addr_type
Definition: gsm23003.h:53
int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits)
Definition: gsm23003.c:238
Definition: gsm23003.h:55
Definition: gsm23003.h:83
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:184
bool osmo_msisdn_str_valid(const char *msisdn)
Determine whether the given MSISDN is valid according to 3GPP TS 23.003.
Definition: gsm23003.c:69
uint8_t rac
Definition: gsm23003.h:24
uint16_t lac
Definition: gsm23003.h:36
Definition: gsm23003.h:22
uint16_t tac
Definition: gsm23003.h:68
bool osmo_imsi_str_valid(const char *imsi)
Determine whether the given IMSI is valid according to 3GPP TS 23.003.
Definition: gsm23003.c:59
uint8_t type
Definition: gsm_04_08.h:557
Definition: gsm23003.h:9
uint16_t sac
Definition: gsm23003.h:43
Definition: gsm23003.h:71
static int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc)
Definition: gsm23003.h:116
Definition: gsm23003.h:35
Definition: gsm23003.h:47
Definition: gsm23003.h:77
Definition: gsm23003.h:54
Definition: gsm23003.h:59
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:107
Definition: gsm23003.h:89
uint16_t group_id
Definition: gsm23003.h:78
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_mcc_mnc_name(), but returning in a different static buffer.
Definition: gsm23003.c:118
uint8_t length
Definition: gsm23003.h:61
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:157
uint32_t eci
Definition: gsm23003.h:73
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:129
Definition: gsm23003.h:28
Definition: gsm23003.h:41
bool mnc_3_digits
Definition: gsm23003.h:12
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:274
uint32_t snac
Definition: gsm23003.h:49
void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn)
Definition: gsm23003.c:211
Definition: gsm23003.h:16
uint16_t ci
Definition: gsm23003.h:37
const char * osmo_mcc_name(uint16_t mcc)
Return MCC string as standardized 3-digit with leading zeros.
Definition: gsm23003.c:78
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:146
uint8_t code
Definition: gsm23003.h:79
struct osmo_plmn_id plmn
Definition: gsm23003.h:84
uint16_t lac
Definition: gsm23003.h:18
struct gsm48_loc_area_id lai
Definition: gsm_04_08.h:559
uint16_t lac
Definition: gsm_04_08.h:558
Definition: gsm23003.h:66
uint32_t mtmsi
Definition: gsm23003.h:91
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:90
int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b)
Definition: gsm23003.c:290