gsm48.h
Go to the documentation of this file.
#pragma once
#include <stdbool.h>
#include <osmocom/core/defs.h>
#include <osmocom/core/msgb.h>
#include <osmocom/gsm/tlv.h>
#include <osmocom/gsm/protocol/gsm_04_08.h>
#include <osmocom/gsm/protocol/gsm_23_003.h>
#include <osmocom/gsm/gsm48_ie.h>
#include <osmocom/gsm/gsm23003.h>
/* reserved according to GSM 03.03 § 2.4 */
#define GSM_RESERVED_TMSI 0xFFFFFFFF
/* Valid MCC and MNC range from 0 to 999.
* To mark an invalid / unset MNC, this value shall be used. */
#define GSM_MCC_MNC_INVALID 0xFFFF
/* A parsed GPRS routing area */
struct gprs_ra_id {
uint16_t mcc;
uint16_t mnc;
bool mnc_3_digits;
uint16_t lac;
uint8_t rac;
};
extern const struct tlv_definition gsm48_att_tlvdef;
extern const struct tlv_definition gsm48_rr_att_tlvdef;
extern const struct tlv_definition gsm48_mm_att_tlvdef;
const char *gsm48_cc_state_name(uint8_t state);
const char *gsm48_cc_msg_name(uint8_t msgtype);
const char *gsm48_rr_msg_name(uint8_t msgtype);
const char *rr_cause_name(uint8_t cause);
const char *osmo_rai_name(const struct gprs_ra_id *rai);
char *osmo_rai_name_buf(char *buf, size_t buf_len, const struct gprs_ra_id *rai);
char *osmo_rai_name_c(const void *ctx, const struct gprs_ra_id *rai);
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, to not lose leading zeros in the MNC");
void gsm48_decode_lai2(const struct gsm48_loc_area_id *lai, struct osmo_location_area_id *decoded);
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, to not lose leading zeros in the MNC");
void gsm48_generate_lai2(struct gsm48_loc_area_id *lai48, const struct osmo_location_area_id *lai);
#define GSM48_MID_MAX_SIZE 11
int gsm48_generate_mid_from_tmsi(uint8_t *buf, uint32_t tmsi)
OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
" *l = osmo_mobile_identity_encode_msgb(...)");
int gsm48_generate_mid_from_imsi(uint8_t *buf, const char *imsi)
OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
" *l = osmo_mobile_identity_encode_msgb(...)");
uint8_t gsm48_generate_mid(uint8_t *buf, const char *id, uint8_t mi_type)
OSMO_DEPRECATED_OUTSIDE("Instead use: l = msgb_tl_put(msg, GSM48_IE_MOBILE_ID);"
" *l = osmo_mobile_identity_encode_msgb(...)");
const char *gsm48_mi_type_name(uint8_t mi);
/* Convert encoded Mobile Identity (10.5.1.4) to string */
int gsm48_mi_to_string(char *string, int str_len, const uint8_t *mi, int mi_len)
OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_decode()");
const char *osmo_mi_name(const uint8_t *mi, uint8_t mi_len)
OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_c()");
char *osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_len)
OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_buf()");
char *osmo_mi_name_c(const void *ctx, const uint8_t *mi, uint8_t mi_len)
OSMO_DEPRECATED_OUTSIDE("Instead use osmo_mobile_identity_to_str_c()");
struct osmo_mobile_identity {
uint8_t type;
union {
char imsi[GSM23003_IMSI_MAX_DIGITS + 1];
char imei[GSM23003_IMEI_NUM_DIGITS + 1];
char imeisv[GSM23003_IMEISV_NUM_DIGITS + 1];
uint32_t tmsi;
};
};
int osmo_mobile_identity_to_str_buf(char *buf, size_t buflen, const struct osmo_mobile_identity *mi);
char *osmo_mobile_identity_to_str_c(void *ctx, const struct osmo_mobile_identity *mi);
int osmo_mobile_identity_cmp(const struct osmo_mobile_identity *a, const struct osmo_mobile_identity *b);
int osmo_mobile_identity_decode(struct osmo_mobile_identity *mi, const uint8_t *mi_data, uint8_t mi_len,
bool allow_hex);
int osmo_mobile_identity_decode_from_l3(struct osmo_mobile_identity *mi, struct msgb *msg, bool allow_hex);
int osmo_mobile_identity_encoded_len(const struct osmo_mobile_identity *mi, int *mi_digits);
int osmo_mobile_identity_encode_buf(uint8_t *buf, size_t buflen, const struct osmo_mobile_identity *mi, bool allow_hex);
int osmo_mobile_identity_encode_msgb(struct msgb *msg, const struct osmo_mobile_identity *mi, bool allow_hex);
/* Parse Routeing Area Identifier */
void gsm48_parse_ra(struct gprs_ra_id *raid, const uint8_t *buf);
void gsm48_encode_ra(struct gsm48_ra_id *out, const struct gprs_ra_id *raid);
int gsm48_construct_ra(uint8_t *buf, const struct gprs_ra_id *raid) OSMO_DEPRECATED("Use gsm48_encode_ra() instead");
bool gsm48_ra_equal(const struct gprs_ra_id *raid1, const struct gprs_ra_id *raid2);
int gsm48_number_of_paging_subchannels(struct gsm48_control_channel_descr *chan_desc);
void gsm48_mcc_mnc_to_bcd(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc)
OSMO_DEPRECATED("Use osmo_plmn_to_bcd() instead, to not lose leading zeros in the MNC");
void gsm48_mcc_mnc_from_bcd(uint8_t *bcd_src, uint16_t *mcc, uint16_t *mnc)
OSMO_DEPRECATED("Use osmo_plmn_from_bcd() instead, to not lose leading zeros in the MNC");
struct gsm48_hdr *gsm48_push_l3hdr(struct msgb *msg,
uint8_t pdisc, uint8_t msg_type);
#define gsm48_push_l3hdr_tid(msg, pdisc, tid, msg_type) \
gsm48_push_l3hdr(msg, (pdisc & 0x0f) | (tid << 4), msg_type)
enum gsm48_chan_mode gsm48_chan_mode_to_vamos(enum gsm48_chan_mode mode);
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:186
gsm48_mcc_mnc_to_bcd
void gsm48_mcc_mnc_to_bcd(uint8_t *bcd_dst, uint16_t mcc, uint16_t mnc)
Definition: gsm48.c:1047
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:815
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:953
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:555
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:993
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:197
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:1227
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:983
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:1177
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:1287
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:1346
gsm48_cc_state_name
const char * gsm48_cc_state_name(uint8_t state)
return string representation of CC State
Definition: gsm48.c:265
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:209
gsm48_number_of_paging_subchannels
int gsm48_number_of_paging_subchannels(struct gsm48_control_channel_descr *chan_desc)
Determine number of paging sub-channels.
Definition: gsm48.c:1368
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:1314
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:753
gsm48_rr_msg_name
const char * gsm48_rr_msg_name(uint8_t msgtype)
return string representation of RR Message Type
Definition: gsm48.c:421
gsm48_cc_msg_name
const char * gsm48_cc_msg_name(uint8_t msgtype)
return string representation of CC Message Type
Definition: gsm48.c:313
gsm48_rr_att_tlvdef
const struct tlv_definition gsm48_rr_att_tlvdef
TLV parser definitions for TS 04.08 RR.
Definition: gsm48.c:98
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:517
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:1733
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:1091
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:1122
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:834
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:446
gsm48_mm_att_tlvdef
const struct tlv_definition gsm48_mm_att_tlvdef
TLV parser definitions for TS 04.08 MM.
Definition: gsm48.c:144
gsm48_mi_type_name
const char * gsm48_mi_type_name(uint8_t mi)
return string representation of Mobile Identity Type
Definition: gsm48.c:504
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:569
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:220
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:1195
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:706
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:599
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:1335
gsm48_att_tlvdef
const struct tlv_definition gsm48_att_tlvdef
TLV parser definitions for TS 04.08 CC.
Definition: gsm48.c:56
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:1245
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:468
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:45
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
Definition: gsm_04_08.h:749
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_08_08.h:0
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:24
gprs_ra_id::mnc_3_digits
bool mnc_3_digits
Definition: gsm48.h:27
gprs_ra_id::mcc
uint16_t mcc
Definition: gsm48.h:25
gprs_ra_id::lac
uint16_t lac
Definition: gsm48.h:28
gprs_ra_id::rac
uint8_t rac
Definition: gsm48.h:29
gprs_ra_id::mnc
uint16_t mnc
Definition: gsm48.h:26
gsm48_control_channel_descr
Definition: gsm_04_08.h:938
gsm48_hdr
Definition: gsm_04_08.h:901
gsm48_loc_area_id
Definition: gsm_04_08.h:858
gsm48_ra_id
Definition: gsm_04_08.h:2114
msgb
osmo_location_area_id
Definition: gsm23003.h:16
tlv_definition
Definition of All 256 IE / TLV.
Definition: tlv.h:517
tlv.h