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 | |
| 33 | /* 12.5 */ |
| 34 | struct osmo_service_area_id { |
| 35 | struct osmo_location_area_id lai; |
| 36 | uint16_t sac; |
| 37 | }; |
| 38 | |
| 39 | /* 12.6 */ |
| 40 | struct osmo_shared_network_area_id { |
| 41 | struct osmo_plmn_id plmn; |
| 42 | uint32_t snac; |
| 43 | }; |
| 44 | |
| 45 | /* 5.1 */ |
| 46 | enum osmo_gsn_addr_type { |
| 47 | GSN_ADDR_TYPE_IPV4 = 0, |
| 48 | GSN_ADDR_TYPE_IPV6 = 1, |
| 49 | }; |
| 50 | |
| 51 | /* 5.1 */ |
| 52 | struct osmo_gsn_address { |
| 53 | enum osmo_gsn_addr_type type; |
| 54 | uint8_t length; |
| 55 | uint8_t addr[16]; |
| 56 | }; |
| 57 | |
| 58 | /* 19.4.2.3 */ |
| 59 | struct osmo_tracking_area_id { |
| 60 | struct osmo_plmn_id plmn; |
| 61 | uint16_t tac; |
| 62 | }; |
| 63 | |
| 64 | struct osmo_eutran_cell_global_id { |
| 65 | struct osmo_plmn_id plmn; |
| 66 | uint32_t eci; /* FIXME */ |
| 67 | }; |
| 68 | |
| 69 | /* 2.8.1 */ |
| 70 | struct osmo_mme_id { |
| 71 | uint16_t group_id; |
| 72 | uint8_t code; |
| 73 | }; |
| 74 | |
| 75 | /* 2.8.1 */ |
| 76 | struct osmo_gummei { |
| 77 | struct osmo_plmn_id plmn; |
| 78 | struct osmo_mme_id mme; |
| 79 | }; |
| 80 | |
| 81 | /* 2.8.1 */ |
| 82 | struct osmo_guti { |
| 83 | struct osmo_gummei gummei; |
| 84 | uint32_t mtmsi; |
| 85 | }; |
Neels Hofmeyr | 9cd1e74 | 2017-10-04 03:15:47 +0200 | [diff] [blame] | 86 | |
| 87 | bool osmo_imsi_str_valid(const char *imsi); |
| 88 | bool osmo_msisdn_str_valid(const char *msisdn); |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 89 | |
| 90 | const char *osmo_mcc_name(uint16_t mcc); |
| 91 | const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits); |
| 92 | const char *osmo_plmn_name(const struct osmo_plmn_id *plmn); |
| 93 | const char *osmo_plmn_name2(const struct osmo_plmn_id *plmn); |
| 94 | const char *osmo_lai_name(const struct osmo_location_area_id *lai); |
| 95 | |
| 96 | void osmo_plmn_to_bcd(uint8_t *bcd_dst, const struct osmo_plmn_id *plmn); |
| 97 | 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] | 98 | |
| 99 | int osmo_mnc_from_str(const char *mnc_str, uint16_t *mnc, bool *mnc_3_digits); |
| 100 | |
| 101 | int osmo_mnc_cmp(uint16_t a_mnc, bool a_mnc_3_digits, uint16_t b_mnc, bool b_mnc_3_digits); |
| 102 | int osmo_plmn_cmp(const struct osmo_plmn_id *a, const struct osmo_plmn_id *b); |