blob: 786fbc9e6d1a15f9ce70f9c67e1059d0bea2fc04 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file gsm48.h */
2
Sylvain Munaut12ba7782014-06-16 10:13:40 +02003#pragma once
Harald Welte4fb20752010-03-02 23:17:33 +01004
Neels Hofmeyrc4fce142018-02-20 13:47:08 +01005#include <stdbool.h>
6
Vadim Yanitskiy30cfeeb2018-08-03 05:44:00 +07007#include <osmocom/core/msgb.h>
8
Pablo Neira Ayuso83419342011-03-22 16:36:13 +01009#include <osmocom/gsm/tlv.h>
10#include <osmocom/gsm/protocol/gsm_04_08.h>
11#include <osmocom/gsm/gsm48_ie.h>
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010012#include <osmocom/gsm/gsm23003.h>
Harald Welte4fb20752010-03-02 23:17:33 +010013
Harald Welte276ca4b2014-08-24 17:35:19 +020014/* reserved according to GSM 03.03 ยง 2.4 */
15#define GSM_RESERVED_TMSI 0xFFFFFFFF
16
Neels Hofmeyrccfc3872018-02-20 15:14:14 +010017/* Valid MCC and MNC range from 0 to 999.
18 * To mark an invalid / unset MNC, this value shall be used. */
19#define GSM_MCC_MNC_INVALID 0xFFFF
20
Harald Weltea1c4f762010-05-01 11:59:42 +020021/* A parsed GPRS routing area */
22struct gprs_ra_id {
Harald Weltea1c4f762010-05-01 11:59:42 +020023 uint16_t mcc;
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010024 uint16_t mnc;
25 bool mnc_3_digits;
Harald Weltea1c4f762010-05-01 11:59:42 +020026 uint16_t lac;
27 uint8_t rac;
28};
29
Harald Welte4fb20752010-03-02 23:17:33 +010030extern const struct tlv_definition gsm48_att_tlvdef;
Andreas Eversberg014cb872010-07-12 09:11:00 +020031extern const struct tlv_definition gsm48_rr_att_tlvdef;
32extern const struct tlv_definition gsm48_mm_att_tlvdef;
Harald Welte9eb6d882010-03-25 12:00:54 +080033const char *gsm48_cc_state_name(uint8_t state);
34const char *gsm48_cc_msg_name(uint8_t msgtype);
Philipp72e43f02016-10-27 13:35:20 +020035const char *gsm48_rr_msg_name(uint8_t msgtype);
Harald Welte4fb20752010-03-02 23:17:33 +010036const char *rr_cause_name(uint8_t cause);
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010037const char *osmo_rai_name(const struct gprs_ra_id *rai);
Harald Welte4a62eda2019-03-18 18:27:00 +010038char *osmo_rai_name_buf(char *buf, size_t buf_len, const struct gprs_ra_id *rai);
Harald Welte179f3572019-03-18 18:38:47 +010039char *osmo_rai_name_c(const void *ctx, const struct gprs_ra_id *rai);
Harald Welte4fb20752010-03-02 23:17:33 +010040
Harald Welte774a9de2012-07-13 21:35:13 +020041int gsm48_decode_lai(struct gsm48_loc_area_id *lai, uint16_t *mcc,
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +010042 uint16_t *mnc, uint16_t *lac)
43 OSMO_DEPRECATED("Use gsm48_decode_lai2() instead, to not lose leading zeros in the MNC");
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010044void gsm48_decode_lai2(const struct gsm48_loc_area_id *lai, struct osmo_location_area_id *decoded);
Harald Welte61e2bfc2010-03-04 10:53:03 +010045void gsm48_generate_lai(struct gsm48_loc_area_id *lai48, uint16_t mcc,
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +010046 uint16_t mnc, uint16_t lac)
47 OSMO_DEPRECATED("Use gsm48_generate_lai2() instead, to not lose leading zeros in the MNC");
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010048void gsm48_generate_lai2(struct gsm48_loc_area_id *lai48, const struct osmo_location_area_id *lai);
49
Harald Welte1c3bae12019-01-20 10:37:49 +010050#define GSM48_MID_MAX_SIZE 11
Harald Welte61e2bfc2010-03-04 10:53:03 +010051int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi);
52int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi);
Maxebf14922018-02-15 11:42:11 +010053uint8_t gsm48_generate_mid(uint8_t *buf, const char *id, uint8_t mi_type);
Harald Welte61e2bfc2010-03-04 10:53:03 +010054
Harald Welte9bb553e2010-03-28 18:14:50 +080055/* Convert Mobile Identity (10.5.1.4) to string */
56int gsm48_mi_to_string(char *string, const int str_len,
Harald Welte163d0ea2010-04-09 07:57:40 +020057 const uint8_t *mi, const int mi_len);
Harald Welte1a8c4e02015-08-16 17:56:25 +020058const char *gsm48_mi_type_name(uint8_t mi);
Neels Hofmeyr02fd83d2019-01-05 00:38:54 +010059const char *osmo_mi_name(const uint8_t *mi, uint8_t mi_len);
Harald Welte4a62eda2019-03-18 18:27:00 +010060char *osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_len);
Harald Welte179f3572019-03-18 18:38:47 +010061char *osmo_mi_name_c(const void *ctx, const uint8_t *mi, uint8_t mi_len);
Harald Welte9bb553e2010-03-28 18:14:50 +080062
Harald Weltea1c4f762010-05-01 11:59:42 +020063/* Parse Routeing Area Identifier */
64void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf);
Maxf1ad60e2018-01-05 14:19:33 +010065void gsm48_encode_ra(struct gsm48_ra_id *out, const struct gprs_ra_id *raid);
Max309d0e52018-01-05 14:21:25 +010066int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid) OSMO_DEPRECATED("Use gsm48_encode_ra() instead");
Harald Weltea1c4f762010-05-01 11:59:42 +020067
Harald Welte2aee7b12011-06-26 14:20:04 +020068int gsm48_number_of_paging_subchannels(struct gsm48_control_channel_descr *chan_desc);
Neels Hofmeyrbdccc1b2016-03-15 13:28:10 +010069
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +010070void gsm48_mcc_mnc_to_bcd(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc)
71 OSMO_DEPRECATED("Use osmo_plmn_to_bcd() instead, to not lose leading zeros in the MNC");
72void gsm48_mcc_mnc_from_bcd(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc)
73 OSMO_DEPRECATED("Use osmo_plmn_from_bcd() instead, to not lose leading zeros in the MNC");
Vadim Yanitskiy30cfeeb2018-08-03 05:44:00 +070074
75struct gsm48_hdr *gsm48_push_l3hdr(struct msgb *msg,
76 uint8_t pdisc, uint8_t msg_type);
77
78#define gsm48_push_l3hdr_tid(msg, pdisc, tid, msg_type) \
79 gsm48_push_l3hdr(msg, (pdisc & 0x0f) | (tid << 4), msg_type)