libosmogsm
0.11.0-dirty
Osmocom GSM library
|
00001 00003 #pragma once 00004 00005 #include <stdint.h> 00006 #include <stdbool.h> 00007 00008 /* 23.003 Chapter 12.1 */ 00009 struct osmo_plmn_id { 00010 uint16_t mcc; 00011 uint16_t mnc; 00012 bool mnc_3_digits; /*< ignored and implied true if mnc > 99, otherwise defines leading zeros. */ 00013 }; 00014 00015 /* 4.1 */ 00016 struct osmo_location_area_id { 00017 struct osmo_plmn_id plmn; 00018 uint16_t lac; 00019 }; 00020 00021 /* 4.2 */ 00022 struct osmo_routing_area_id { 00023 struct osmo_location_area_id lac; 00024 uint8_t rac; 00025 }; 00026 00027 /* 4.3.1 */ 00028 struct osmo_cell_global_id { 00029 struct osmo_location_area_id lai; 00030 uint16_t cell_identity; 00031 }; 00032 00033 /* Actually defined in 3GPP TS 48.008 3.2.2.27 Cell Identifier List, 00034 * but conceptually belongs with the above structures. */ 00035 struct osmo_lac_and_ci_id { 00036 uint16_t lac; 00037 uint16_t ci; 00038 }; 00039 00040 /* 12.5 */ 00041 struct osmo_service_area_id { 00042 struct osmo_location_area_id lai; 00043 uint16_t sac; 00044 }; 00045 00046 /* 12.6 */ 00047 struct osmo_shared_network_area_id { 00048 struct osmo_plmn_id plmn; 00049 uint32_t snac; 00050 }; 00051 00052 /* 5.1 */ 00053 enum osmo_gsn_addr_type { 00054 GSN_ADDR_TYPE_IPV4 = 0, 00055 GSN_ADDR_TYPE_IPV6 = 1, 00056 }; 00057 00058 /* 5.1 */ 00059 struct osmo_gsn_address { 00060 enum osmo_gsn_addr_type type; 00061 uint8_t length; 00062 uint8_t addr[16]; 00063 }; 00064 00065 /* 19.4.2.3 */ 00066 struct osmo_tracking_area_id { 00067 struct osmo_plmn_id plmn; 00068 uint16_t tac; 00069 }; 00070 00071 struct osmo_eutran_cell_global_id { 00072 struct osmo_plmn_id plmn; 00073 uint32_t eci; /* FIXME */ 00074 }; 00075 00076 /* 2.8.1 */ 00077 struct osmo_mme_id { 00078 uint16_t group_id; 00079 uint8_t code; 00080 }; 00081 00082 /* 2.8.1 */ 00083 struct osmo_gummei { 00084 struct osmo_plmn_id plmn; 00085 struct osmo_mme_id mme; 00086 }; 00087 00088 /* 2.8.1 */ 00089 struct osmo_guti { 00090 struct osmo_gummei gummei; 00091 uint32_t mtmsi; 00092 }; 00093 00094 bool osmo_imsi_str_valid(const char *imsi); 00095 bool osmo_msisdn_str_valid(const char *msisdn); 00096 00097 const char *osmo_mcc_name(uint16_t mcc); 00098 const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits); 00099 const char *osmo_plmn_name(const struct osmo_plmn_id *plmn); 00100 const char *osmo_plmn_name2(const struct osmo_plmn_id *plmn); 00101 const char *osmo_lai_name(const struct osmo_location_area_id *lai); 00102 const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi); 00103 const char *osmo_cgi_name2(const struct osmo_cell_global_id *cgi); 00104 00105 void osmo_plmn_to_bcd(uint8_t *bcd_dst, const struct osmo_plmn_id *plmn); 00106 void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn); 00107 00108 int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits); 00109 00110 /* Convert string to MCC. 00111 * \param mcc_str[in] String representation of an MCC, with or without leading zeros. 00112 * \param mcc[out] MCC result buffer, or NULL. 00113 * \returns zero on success, -EINVAL in case of surplus characters, negative errno in case of conversion 00114 * errors. In case of error, do not modify the out-arguments. 00115 */ 00116 static inline int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc) 00117 { 00118 return osmo_mnc_from_str(mcc_str, mcc, NULL); 00119 } 00120 00121 int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits); 00122 int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b);