Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file gsm23003.h */ |
| 2 | |
Harald Welte | bda26c0 | 2016-05-11 09:13:08 +0200 | [diff] [blame] | 3 | #pragma once |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 4 | |
Harald Welte | bda26c0 | 2016-05-11 09:13:08 +0200 | [diff] [blame] | 5 | #include <stdint.h> |
Neels Hofmeyr | 9cd1e74 | 2017-10-04 03:15:47 +0200 | [diff] [blame] | 6 | #include <stdbool.h> |
Harald Welte | bda26c0 | 2016-05-11 09:13:08 +0200 | [diff] [blame] | 7 | |
| 8 | /* 23.003 Chapter 12.1 */ |
| 9 | struct osmo_plmn_id { |
| 10 | uint16_t mcc; |
| 11 | uint16_t mnc; |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 12 | bool mnc_3_digits; /*< ignored and implied true if mnc > 99, otherwise defines leading zeros. */ |
Harald Welte | bda26c0 | 2016-05-11 09:13:08 +0200 | [diff] [blame] | 13 | }; |
| 14 | |
| 15 | /* 4.1 */ |
| 16 | struct osmo_location_area_id { |
| 17 | struct osmo_plmn_id plmn; |
| 18 | uint16_t lac; |
| 19 | }; |
| 20 | |
| 21 | /* 4.2 */ |
| 22 | struct osmo_routing_area_id { |
| 23 | struct osmo_location_area_id lac; |
| 24 | uint8_t rac; |
| 25 | }; |
| 26 | |
| 27 | /* 4.3.1 */ |
| 28 | struct osmo_cell_global_id { |
| 29 | struct osmo_location_area_id lai; |
| 30 | uint16_t cell_identity; |
| 31 | }; |
| 32 | |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 33 | /* Actually defined in 3GPP TS 48.008 3.2.2.27 Cell Identifier List, |
| 34 | * but conceptually belongs with the above structures. */ |
| 35 | struct osmo_lac_and_ci_id { |
| 36 | uint16_t lac; |
| 37 | uint16_t ci; |
| 38 | }; |
| 39 | |
Harald Welte | bda26c0 | 2016-05-11 09:13:08 +0200 | [diff] [blame] | 40 | /* 12.5 */ |
| 41 | struct osmo_service_area_id { |
| 42 | struct osmo_location_area_id lai; |
| 43 | uint16_t sac; |
| 44 | }; |
| 45 | |
| 46 | /* 12.6 */ |
| 47 | struct osmo_shared_network_area_id { |
| 48 | struct osmo_plmn_id plmn; |
| 49 | uint32_t snac; |
| 50 | }; |
| 51 | |
| 52 | /* 5.1 */ |
| 53 | enum osmo_gsn_addr_type { |
| 54 | GSN_ADDR_TYPE_IPV4 = 0, |
| 55 | GSN_ADDR_TYPE_IPV6 = 1, |
| 56 | }; |
| 57 | |
| 58 | /* 5.1 */ |
| 59 | struct osmo_gsn_address { |
| 60 | enum osmo_gsn_addr_type type; |
| 61 | uint8_t length; |
| 62 | uint8_t addr[16]; |
| 63 | }; |
| 64 | |
| 65 | /* 19.4.2.3 */ |
| 66 | struct osmo_tracking_area_id { |
| 67 | struct osmo_plmn_id plmn; |
| 68 | uint16_t tac; |
| 69 | }; |
| 70 | |
| 71 | struct osmo_eutran_cell_global_id { |
| 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 | }; |
Neels Hofmeyr | 9cd1e74 | 2017-10-04 03:15:47 +0200 | [diff] [blame] | 93 | |
| 94 | bool osmo_imsi_str_valid(const char *imsi); |
| 95 | bool osmo_msisdn_str_valid(const char *msisdn); |
Oliver Smith | 894be2d | 2019-01-11 13:13:37 +0100 | [diff] [blame] | 96 | bool osmo_imei_str_valid(const char *imei, bool with_15th_digit); |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 97 | |
| 98 | const char *osmo_mcc_name(uint16_t mcc); |
| 99 | const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits); |
| 100 | const char *osmo_plmn_name(const struct osmo_plmn_id *plmn); |
| 101 | const char *osmo_plmn_name2(const struct osmo_plmn_id *plmn); |
| 102 | const char *osmo_lai_name(const struct osmo_location_area_id *lai); |
Neels Hofmeyr | 4349620 | 2018-03-22 14:04:30 +0100 | [diff] [blame] | 103 | const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi); |
| 104 | const char *osmo_cgi_name2(const struct osmo_cell_global_id *cgi); |
Harald Welte | de1da35 | 2018-10-08 22:27:04 +0200 | [diff] [blame] | 105 | const char *osmo_gummei_name(const struct osmo_gummei *gummei); |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 106 | |
| 107 | void osmo_plmn_to_bcd(uint8_t *bcd_dst, const struct osmo_plmn_id *plmn); |
| 108 | void osmo_plmn_from_bcd(const uint8_t *bcd_src, struct osmo_plmn_id *plmn); |
Neels Hofmeyr | 721aa6d | 2018-02-20 21:38:00 +0100 | [diff] [blame] | 109 | |
| 110 | int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits); |
| 111 | |
Neels Hofmeyr | 4d68fd0 | 2018-03-05 04:16:48 +0100 | [diff] [blame] | 112 | /* Convert string to MCC. |
| 113 | * \param mcc_str[in] String representation of an MCC, with or without leading zeros. |
| 114 | * \param mcc[out] MCC result buffer, or NULL. |
| 115 | * \returns zero on success, -EINVAL in case of surplus characters, negative errno in case of conversion |
| 116 | * errors. In case of error, do not modify the out-arguments. |
| 117 | */ |
| 118 | static inline int osmo_mcc_from_str(const char *mcc_str, uint16_t *mcc) |
| 119 | { |
| 120 | return osmo_mnc_from_str(mcc_str, mcc, NULL); |
| 121 | } |
| 122 | |
Neels Hofmeyr | 721aa6d | 2018-02-20 21:38:00 +0100 | [diff] [blame] | 123 | int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits); |
| 124 | int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b); |
Harald Welte | de1da35 | 2018-10-08 22:27:04 +0200 | [diff] [blame] | 125 | |
| 126 | int osmo_gen_home_network_domain(char *out, const struct osmo_plmn_id *plmn); |
| 127 | int osmo_parse_home_network_domain(struct osmo_plmn_id *out, const char *in); |
| 128 | int osmo_gen_mme_domain(char *out, const struct osmo_gummei *gummei); |
| 129 | int osmo_gen_mme_group_domain(char *out, uint16_t mmegi, const struct osmo_plmn_id *plmn); |
| 130 | int osmo_parse_mme_domain(struct osmo_gummei *out, const char *in); |