libosmogsm 1.13.1.1-afb4 Osmocom GSM library

gsm48.h
Go to the documentation of this file.
1
3#pragma once
4
5#include <stdbool.h>
6
7#include <osmocom/core/defs.h>
8#include <osmocom/core/msgb.h>
9
10#include <osmocom/gsm/tlv.h>
11#include <osmocom/gsm/protocol/gsm_04_08.h>
12#include <osmocom/gsm/protocol/gsm_23_003.h>
13#include <osmocom/gsm/gsm48_ie.h>
14#include <osmocom/gsm/gsm23003.h>
15
16/* reserved according to GSM 03.03 § 2.4 */
17#define GSM_RESERVED_TMSI 0xFFFFFFFF
18
19/* Valid MCC and MNC range from 0 to 999.
20 * To mark an invalid / unset MNC, this value shall be used. */
21#define GSM_MCC_MNC_INVALID 0xFFFF
22
23/* A parsed GPRS routing area.
24 * Preferably use struct osmo_routing_area_id, it is better integrated with API like osmo_plmn_cmp().
25 */
26 struct gprs_ra_id {
27 uint16_t mcc;
28 uint16_t mnc;
29 bool mnc_3_digits;
30 uint16_t lac;
31 uint8_t rac;
32};
33
34 extern const struct tlv_definition gsm48_att_tlvdef;
35 extern const struct tlv_definition gsm48_rr_att_tlvdef;
36 extern const struct tlv_definition gsm48_mm_att_tlvdef;
37 const char *gsm48_cc_state_name(uint8_t state);
38 const char *gsm48_cc_msg_name(uint8_t msgtype);
39 const char *gsm48_rr_msg_name(uint8_t msgtype);
40 const char *gsm48_rr_short_pd_msg_name(uint8_t msgtype);
41 const char *rr_cause_name(uint8_t cause);
42 const char *osmo_rai_name(const struct gprs_ra_id *rai);
43 char *osmo_rai_name_buf(char *buf, size_t buf_len, const struct gprs_ra_id *rai);
44 char *osmo_rai_name_c(const void *ctx, const struct gprs_ra_id *rai);
45 void osmo_rai_to_gprs(struct gprs_ra_id *dest, const struct osmo_routing_area_id *src);
46 void gprs_rai_to_osmo(struct osmo_routing_area_id *dest, const struct gprs_ra_id *src);
47
48 int gsm48_decode_lai(struct gsm48_loc_area_id *lai, uint16_t *mcc,
49 uint16_t *mnc, uint16_t *lac)
50 OSMO_DEPRECATED("Use gsm48_decode_lai2() instead, to not lose leading zeros in the MNC");
51 void gsm48_decode_lai2(const struct gsm48_loc_area_id *lai, struct osmo_location_area_id *decoded);
52 void gsm48_generate_lai(struct gsm48_loc_area_id *lai48, uint16_t mcc,
53 uint16_t mnc, uint16_t lac)
54 OSMO_DEPRECATED("Use gsm48_generate_lai2() instead, to not lose leading zeros in the MNC");
55 void gsm48_generate_lai2(struct gsm48_loc_area_id *lai48, const struct osmo_location_area_id *lai);
56
57#define GSM48_MID_MAX_SIZE 11
58 int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi)
59 OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
60 " *l = osmo_mobile_identity_encode_msgb(...)");
61 int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi)
62 OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
63 " *l = osmo_mobile_identity_encode_msgb(...)");
64uint8_t gsm48_generate_mid(uint8_t *buf, const char *id, uint8_t mi_type)
65 OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
66 " *l = osmo_mobile_identity_encode_msgb(...)");
67
68 const char *gsm48_mi_type_name(uint8_t mi);
69/* Convert encoded Mobile Identity (10.5.1.4) to string */
70 int gsm48_mi_to_string(char *string, int str_len, const uint8_t *mi, int mi_len)
71 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_decode()");
72 const char *osmo_mi_name(const uint8_t *mi, uint8_t mi_len)
73 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_c()");
74 char *osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_len)
75 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_buf()");
76 char *osmo_mi_name_c(const void *ctx, const uint8_t *mi, uint8_t mi_len)
77 OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_c()");
78
81 struct osmo_mobile_identity {
83 uint8_t type;
86 union {
88 char imsi[GSM23003_IMSI_MAX_DIGITS + 1];
90 char imei[GSM23003_IMEI_NUM_DIGITS + 1];
92 char imeisv[GSM23003_IMEISV_NUM_DIGITS + 1];
94 uint32_t tmsi;
95 };
96};
97
98 int osmo_mobile_identity_to_str_buf(char *buf, size_t buflen, const struct osmo_mobile_identity *mi);
99 char *osmo_mobile_identity_to_str_c(void *ctx, const struct osmo_mobile_identity *mi);
100 int osmo_mobile_identity_cmp(const struct osmo_mobile_identity *a, const struct osmo_mobile_identity *b);
101 int osmo_mobile_identity_decode(struct osmo_mobile_identity *mi, const uint8_t *mi_data, uint8_t mi_len,
102 bool allow_hex);
103 int osmo_mobile_identity_decode_from_l3_buf(struct osmo_mobile_identity *mi, const uint8_t *l3_data, size_t l3_len,
104 bool allow_hex);
105 int osmo_mobile_identity_decode_from_l3(struct osmo_mobile_identity *mi, struct msgb *msg, bool allow_hex);
106 int osmo_mobile_identity_encoded_len(const struct osmo_mobile_identity *mi, int *mi_digits);
107 int osmo_mobile_identity_encode_buf(uint8_t *buf, size_t buflen, const struct osmo_mobile_identity *mi, bool allow_hex);
108 int osmo_mobile_identity_encode_msgb(struct msgb *msg, const struct osmo_mobile_identity *mi, bool allow_hex);
109
110/* Parse Routeing Area Identifier */
111 int osmo_routing_area_id_decode(struct osmo_routing_area_id *dst, const uint8_t *ra_data, size_t ra_data_len);
112 int osmo_routing_area_id_encode_buf(uint8_t *buf, size_t buflen, const struct osmo_routing_area_id *src);
113 int osmo_routing_area_id_encode_msgb(struct msgb *msg, const struct osmo_routing_area_id *src);
114 void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf);
115 void gsm48_encode_ra(struct gsm48_ra_id *out, const struct gprs_ra_id *raid);
116 int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid) OSMO_DEPRECATED("Use gsm48_encode_ra() instead");
117 bool gsm48_ra_equal(const struct gprs_ra_id *raid1, const struct gprs_ra_id *raid2);
118
119 int gsm48_number_of_paging_subchannels(const struct gsm48_control_channel_descr *chan_desc);
120
121 void gsm48_mcc_mnc_to_bcd(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc)
122 OSMO_DEPRECATED("Use osmo_plmn_to_bcd() instead, to not lose leading zeros in the MNC");
123 void gsm48_mcc_mnc_from_bcd(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc)
124 OSMO_DEPRECATED("Use osmo_plmn_from_bcd() instead, to not lose leading zeros in the MNC");
125
126 struct gsm48_hdr *gsm48_push_l3hdr(struct msgb *msg,
127 uint8_t pdisc, uint8_t msg_type);
128
129#define gsm48_push_l3hdr_tid(msg, pdisc, tid, msg_type) \
130 gsm48_push_l3hdr(msg, (pdisc & 0x0f) | (tid << 4), msg_type)
131
132 enum gsm48_chan_mode gsm48_chan_mode_to_vamos(enum gsm48_chan_mode mode);
133 enum gsm48_chan_mode gsm48_chan_mode_to_non_vamos(enum gsm48_chan_mode mode);
defs.h
rr_cause_name
const char * rr_cause_name(uint8_t cause)
return string representation of RR Cause value
Definition: gsm48.c:183
gsm48_mcc_mnc_to_bcd
void gsm48_mcc_mnc_to_bcd(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc)
Definition: gsm48.c:1142
gprs_rai_to_osmo
void gprs_rai_to_osmo(struct osmo_routing_area_id *dest, const struct gprs_ra_id *src)
Convert gprs_ra_id (old) into osmo_routing_area_id (new)
Definition: gsm48.c:240
osmo_mobile_identity_encode_msgb
int osmo_mobile_identity_encode_msgb(struct msgb *msg, const struct osmo_mobile_identity *mi, bool allow_hex)
Encode Mobile Identity type and BCD digits, appended to a msgb.
Definition: gsm48.c:882
osmo_mobile_identity_to_str_buf
int osmo_mobile_identity_to_str_buf(char *buf, size_t buflen, const struct osmo_mobile_identity *mi)
Return a human readable representation of a struct osmo_mobile_identity.
Definition: gsm48.c:1048
osmo_mi_name_buf
char * osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_len)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:582
osmo_mobile_identity_to_str_c
char * osmo_mobile_identity_to_str_c(void *ctx, const struct osmo_mobile_identity *mi)
Like osmo_mobile_identity_to_str_buf(), but return the string in a talloc buffer.
Definition: gsm48.c:1078
osmo_routing_area_id_encode_msgb
int osmo_routing_area_id_encode_msgb(struct msgb *msg, const struct osmo_routing_area_id *src)
Encode struct osmo_routing_area_id to a 3GPP TS 24.008 § 10.5.5.15 Routing area identification: appen...
Definition: gsm48.c:1425
gsm48_rr_msg_name
const char * gsm48_rr_msg_name(uint8_t msgtype)
return string representation of RR Message Type
Definition: gsm48.c:446
osmo_mobile_identity_cmp
int osmo_mobile_identity_cmp(const struct osmo_mobile_identity *a, const struct osmo_mobile_identity *b)
Compare two osmo_mobile_identity structs, returning typical cmp() result.
Definition: gsm48.c:1088
osmo_rai_name
const char * osmo_rai_name(const struct gprs_ra_id *rai)
Return MCC-MNC-LAC-RAC as string, in a static buffer.
Definition: gsm48.c:206
osmo_mi_name
const char * osmo_mi_name(const uint8_t *mi, uint8_t mi_len)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:620
osmo_rai_name_c
char * osmo_rai_name_c(const void *ctx, const struct gprs_ra_id *rai)
Return MCC-MNC-LAC-RAC as string, in dynamically-allocated output buffer.
Definition: gsm48.c:217
gsm48_mi_type_name
const char * gsm48_mi_type_name(uint8_t mi)
return string representation of Mobile Identity Type
Definition: gsm48.c:569
gsm48_generate_mid_from_imsi
int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:1322
gsm48_generate_mid_from_tmsi
int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:1272
gsm48_parse_ra
void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf)
Parse TS 04.08 Routing Area Identifier.
Definition: gsm48.c:1439
osmo_routing_area_id_decode
int osmo_routing_area_id_decode(struct osmo_routing_area_id *dst, const uint8_t *ra_data, size_t ra_data_len)
Decode to struct osmo_routing_area_id from a 3GPP TS 24.008 § 10.5.5.15 Routing area identification.
Definition: gsm48.c:1385
gsm48_ra_equal
bool gsm48_ra_equal(const struct gprs_ra_id *raid1, const struct gprs_ra_id *raid2)
Compare a TS 04.08 Routing Area Identifier.
Definition: gsm48.c:1498
gsm48_encode_ra
void gsm48_encode_ra(struct gsm48_ra_id *out, const struct gprs_ra_id *raid)
Encode a 3GPP TS 24.008 § 10.5.5.15 Routing area identification.
Definition: gsm48.c:1466
osmo_mobile_identity_encode_buf
int osmo_mobile_identity_encode_buf(uint8_t *buf, size_t buflen, const struct osmo_mobile_identity *mi, bool allow_hex)
Encode Mobile Identity from uint32_t (TMSI) or digits string (all others) (3GPP TS 24....
Definition: gsm48.c:820
gsm48_rr_att_tlvdef
const struct tlv_definition gsm48_rr_att_tlvdef
TLV parser definitions for TS 04.08 RR.
Definition: gsm48.c:95
gsm48_generate_lai2
void gsm48_generate_lai2(struct gsm48_loc_area_id *lai48, const struct osmo_location_area_id *lai)
Encode TS 04.08 Location Area Identifier.
Definition: gsm48.c:1186
gsm48_decode_lai2
void gsm48_decode_lai2(const struct gsm48_loc_area_id *lai, struct osmo_location_area_id *decoded)
Decode TS 04.08 Location Area Identifier.
Definition: gsm48.c:1217
gsm48_rr_short_pd_msg_name
const char * gsm48_rr_short_pd_msg_name(uint8_t msgtype)
return string representation of RR Message Type using the RR short protocol discriminator
Definition: gsm48.c:470
osmo_mobile_identity_decode_from_l3
int osmo_mobile_identity_decode_from_l3(struct osmo_mobile_identity *mi, struct msgb *msg, bool allow_hex)
Extract Mobile Identity from a Complete Layer 3 message.
Definition: gsm48.c:1036
osmo_mobile_identity_decode_from_l3_buf
int osmo_mobile_identity_decode_from_l3_buf(struct osmo_mobile_identity *mi, const uint8_t *l3_data, size_t l3_len, bool allow_hex)
Extract Mobile Identity from a Complete Layer 3 message.
Definition: gsm48.c:902
gsm48_chan_mode_to_vamos
enum gsm48_chan_mode gsm48_chan_mode_to_vamos(enum gsm48_chan_mode mode)
Translate GSM48_CMODE_SPEECH_* to its corresponding GSM48_CMODE_SPEECH_*_VAMOS mode.
Definition: gsm48.c:509
gsm48_mm_att_tlvdef
const struct tlv_definition gsm48_mm_att_tlvdef
TLV parser definitions for TS 04.08 MM.
Definition: gsm48.c:141
osmo_rai_to_gprs
void osmo_rai_to_gprs(struct gprs_ra_id *dest, const struct osmo_routing_area_id *src)
Convert osmo_routing_area_id (new) into gprs_ra_id (old)
Definition: gsm48.c:226
gsm48_cc_msg_name
const char * gsm48_cc_msg_name(uint8_t msgtype)
return string representation of CC Message Type
Definition: gsm48.c:338
osmo_mi_name_c
char * osmo_mi_name_c(const void *ctx, const uint8_t *mi, uint8_t mi_len)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:634
gsm48_generate_mid
uint8_t gsm48_generate_mid(uint8_t *buf, const char *id, uint8_t mi_type)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:1290
osmo_mobile_identity_encoded_len
int osmo_mobile_identity_encoded_len(const struct osmo_mobile_identity *mi, int *mi_digits)
Return the number of encoded Mobile Identity octets, without actually encoding.
Definition: gsm48.c:773
gsm48_cc_state_name
const char * gsm48_cc_state_name(uint8_t state)
return string representation of CC State
Definition: gsm48.c:290
gsm48_push_l3hdr
struct gsm48_hdr * gsm48_push_l3hdr(struct msgb *msg, uint8_t pdisc, uint8_t msg_type)
Wrap a given msg with gsm48_hdr structure.
Definition: gsm48.c:1895
osmo_mobile_identity_decode
int osmo_mobile_identity_decode(struct osmo_mobile_identity *mi, const uint8_t *mi_data, uint8_t mi_len, bool allow_hex)
Extract Mobile Identity from encoded bytes (3GPP TS 24.008 10.5.1.4).
Definition: gsm48.c:664
gsm48_construct_ra
int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid)
Encode a TS 04.08 Routing Area Identifier.
Definition: gsm48.c:1487
gsm48_number_of_paging_subchannels
int gsm48_number_of_paging_subchannels(const struct gsm48_control_channel_descr *chan_desc)
Determine number of paging sub-channels.
Definition: gsm48.c:1520
gsm48_att_tlvdef
const struct tlv_definition gsm48_att_tlvdef
TLV parser definitions for TS 04.08 CC.
Definition: gsm48.c:53
gsm48_mi_to_string
int gsm48_mi_to_string(char *string, int str_len, const uint8_t *mi, int mi_len)
Deprecated, see osmo_mobile_identity instead.
Definition: gsm48.c:1340
osmo_routing_area_id_encode_buf
int osmo_routing_area_id_encode_buf(uint8_t *buf, size_t buflen, const struct osmo_routing_area_id *src)
Encode struct osmo_routing_area_id to a 3GPP TS 24.008 § 10.5.5.15 Routing area identification: write...
Definition: gsm48.c:1405
gsm48_chan_mode_to_non_vamos
enum gsm48_chan_mode gsm48_chan_mode_to_non_vamos(enum gsm48_chan_mode mode)
Translate GSM48_CMODE_SPEECH_*_VAMOS to its corresponding GSM48_CMODE_SPEECH_* non-vamos mode.
Definition: gsm48.c:531
osmo_rai_name_buf
char * osmo_rai_name_buf(char *buf, size_t buf_len, const struct gprs_ra_id *rai)
Return MCC-MNC-LAC-RAC as string, in a caller-provided output buffer.
Definition: gsm48.c:194
OSMO_DEPRECATED_OUTSIDE
#define OSMO_DEPRECATED_OUTSIDE(text)
OSMO_DEPRECATED
#define OSMO_DEPRECATED(text)
gsm23003.h
gsm48_mcc_mnc_from_bcd
void gsm48_mcc_mnc_from_bcd(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc) OSMO_DEPRECATED("Use osmo_plmn_from_bcd() instead
gsm48_generate_lai
void gsm48_generate_lai(struct gsm48_loc_area_id *lai48, uint16_t mcc, uint16_t mnc, uint16_t lac) OSMO_DEPRECATED("Use gsm48_generate_lai2() instead
gsm48_decode_lai
int gsm48_decode_lai(struct gsm48_loc_area_id *lai, uint16_t *mcc, uint16_t *mnc, uint16_t *lac) OSMO_DEPRECATED("Use gsm48_decode_lai2() instead
MNC
int to not lose leading zeros in the MNC
Definition: gsm48.h:50
gsm48_ie.h
gsm_04_08.h
GSM TS 04.08 definitions.
cause
uint8_t cause
Definition: gsm_04_08.h:2
gsm48_chan_mode
gsm48_chan_mode
10.5.2.6 Channel Mode value
Definition: gsm_04_08.h:750
mode
uint8_t mode
Definition: gsm_04_08.h:1
lac
uint16_t lac
Definition: gsm_04_08.h:1
mi_len
uint8_t mi_len
Definition: gsm_04_08.h:1
lai
struct gsm48_loc_area_id lai
Definition: gsm_04_08.h:2
chan_desc
struct gsm48_chan_desc chan_desc
Definition: gsm_04_08.h:0
mi
uint8_t mi[0]
Definition: gsm_04_08.h:2
msg_type
uint8_t msg_type
Definition: gsm_04_08.h:2
type
uint8_t type
Definition: gsm_04_08_gprs.h:7
msg
uint8_t msg[0]
Definition: gsm_08_08.h:8
gsm_23_003.h
GSM23003_IMEI_NUM_DIGITS
#define GSM23003_IMEI_NUM_DIGITS
Definition: gsm_23_003.h:30
GSM23003_IMEISV_NUM_DIGITS
#define GSM23003_IMEISV_NUM_DIGITS
Definition: gsm_23_003.h:32
GSM23003_IMSI_MAX_DIGITS
#define GSM23003_IMSI_MAX_DIGITS
Definition: gsm_23_003.h:6
instead
_parse instead
Definition: ipa.h:30
msgb.h
gprs_ra_id
Definition: gsm48.h:26
gprs_ra_id::mnc_3_digits
bool mnc_3_digits
Definition: gsm48.h:29
gprs_ra_id::mcc
uint16_t mcc
Definition: gsm48.h:27
gprs_ra_id::lac
uint16_t lac
Definition: gsm48.h:30
gprs_ra_id::rac
uint8_t rac
Definition: gsm48.h:31
gprs_ra_id::mnc
uint16_t mnc
Definition: gsm48.h:28
gsm48_control_channel_descr
Definition: gsm_04_08.h:992
gsm48_hdr
Definition: gsm_04_08.h:941
gsm48_loc_area_id
Definition: gsm_04_08.h:898
gsm48_ra_id
Definition: gsm_04_08.h:2269
msgb
osmo_location_area_id
Definition: gsm23003.h:17
osmo_routing_area_id
Definition: gsm23003.h:23
tlv_definition
Definition of All 256 IE / TLV.
Definition: tlv.h:527
tlv.h