gsm0808_utils.h
Go to the documentation of this file.
/*
* (C) 2016 by sysmocom - s.f.m.c. GmbH, Author: Philipp Maier
* All Rights Reserved
*
* SPDX-License-Identifier: GPL-2.0+
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
struct sockaddr_storage;
#include <osmocom/gsm/protocol/gsm_08_08.h>
#include <osmocom/gsm/protocol/gsm_04_08.h>
#include <osmocom/gsm/gsm23003.h>
#include <osmocom/gsm/gsm_utils.h>
#define GSM0808_CELL_ID_LIST2_MAXLEN 127
union gsm0808_cell_id_u {
struct osmo_cell_global_id global;
struct osmo_lac_and_ci_id lac_and_ci;
uint16_t ci;
struct osmo_location_area_id lai_and_lac;
uint16_t lac;
};
struct gsm0808_cell_id {
enum CELL_IDENT id_discr;
union gsm0808_cell_id_u id;
};
struct gsm0808_cell_id_list2 {
enum CELL_IDENT id_discr;
union gsm0808_cell_id_u id_list[GSM0808_CELL_ID_LIST2_MAXLEN];
unsigned int id_list_len;
};
extern const struct value_string gsm0808_cell_id_discr_names[];
static inline const char *gsm0808_cell_id_discr_name(enum CELL_IDENT id_discr)
{ return get_value_string(gsm0808_cell_id_discr_names, id_discr); }
const char *gsm0808_cell_id_name(const struct gsm0808_cell_id *cid);
const char *gsm0808_cell_id_name2(const struct gsm0808_cell_id *cid);
const char *gsm0808_cell_id_list_name(const struct gsm0808_cell_id_list2 *cil);
int gsm0808_cell_id_list_name_buf(char *buf, size_t buflen, const struct gsm0808_cell_id_list2 *cil);
int gsm0808_cell_id_u_name(char *buf, size_t buflen,
enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u);
uint8_t gsm0808_enc_aoip_trasp_addr(struct msgb *msg,
const struct sockaddr_storage *ss);
int gsm0808_dec_aoip_trasp_addr(struct sockaddr_storage *ss,
const uint8_t *elem, uint8_t len);
uint8_t gsm0808_enc_speech_codec(struct msgb *msg,
const struct gsm0808_speech_codec *sc);
int gsm0808_dec_speech_codec(struct gsm0808_speech_codec *sc,
const uint8_t *elem, uint8_t len);
uint8_t gsm0808_enc_speech_codec_list(struct msgb *msg,
const struct gsm0808_speech_codec_list
*scl);
int gsm0808_dec_speech_codec_list(struct gsm0808_speech_codec_list *scl,
const uint8_t *elem, uint8_t len);
uint8_t gsm0808_enc_channel_type(struct msgb *msg,
const struct gsm0808_channel_type *ct);
int gsm0808_dec_channel_type(struct gsm0808_channel_type *ct,
const uint8_t *elem, uint8_t len);
uint8_t gsm0808_enc_encrypt_info(struct msgb *msg,
const struct gsm0808_encrypt_info *ei);
int gsm0808_dec_encrypt_info(struct gsm0808_encrypt_info *ei,
const uint8_t *elem, uint8_t len);
uint8_t gsm0808_enc_cell_id_list2(struct msgb *msg, const struct gsm0808_cell_id_list2 *cil);
uint8_t gsm0808_enc_cell_id_list(struct msgb *msg,
const struct gsm0808_cell_id_list *cil)
OSMO_DEPRECATED("use gsm0808_enc_cell_id_list2 instead");
int gsm0808_dec_cell_id_list2(struct gsm0808_cell_id_list2 *cil, const uint8_t *elem, uint8_t len);
int gsm0808_dec_cell_id_list(struct gsm0808_cell_id_list *cil,
const uint8_t *elem, uint8_t len)
OSMO_DEPRECATED("use gsm0808_dec_cell_id_list2 instead");
int gsm0808_cell_id_list_add(struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id_list2 *src);
void gsm0808_cell_id_to_list(struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id *src);
uint8_t gsm0808_enc_cell_id(struct msgb *msg, const struct gsm0808_cell_id *ci);
int gsm0808_dec_cell_id(struct gsm0808_cell_id *ci, const uint8_t *elem, uint8_t len);
int gsm0808_chan_type_to_speech_codec(uint8_t perm_spch);
int gsm0808_speech_codec_from_chan_type(struct gsm0808_speech_codec *sc,
uint8_t perm_spch);
static inline uint8_t gsm0808_current_channel_type_1(enum gsm_chan_t type)
{
switch (type) {
default:
return 0;
case GSM_LCHAN_SDCCH:
return 0x01;
case GSM_LCHAN_TCH_F:
return 0x18;
case GSM_LCHAN_TCH_H:
return 0x19;
}
}
static inline enum gsm0808_permitted_speech gsm0808_permitted_speech(enum gsm_chan_t type,
enum gsm48_chan_mode mode)
{
switch (mode) {
case GSM48_CMODE_SPEECH_V1:
switch (type) {
case GSM_LCHAN_TCH_F:
return GSM0808_PERM_FR1;
case GSM_LCHAN_TCH_H:
return GSM0808_PERM_HR1;
default:
return 0;
}
case GSM48_CMODE_SPEECH_EFR:
switch (type) {
case GSM_LCHAN_TCH_F:
return GSM0808_PERM_FR2;
case GSM_LCHAN_TCH_H:
return GSM0808_PERM_HR2;
default:
return 0;
}
case GSM48_CMODE_SPEECH_AMR:
switch (type) {
case GSM_LCHAN_TCH_F:
return GSM0808_PERM_FR3;
case GSM_LCHAN_TCH_H:
return GSM0808_PERM_HR3;
default:
return 0;
}
default:
return 0;
}
}
static inline uint8_t gsm0808_chosen_channel(enum gsm_chan_t type, enum gsm48_chan_mode mode)
{
uint8_t channel_mode = 0, channel = 0;
switch (mode) {
case GSM48_CMODE_SPEECH_V1:
case GSM48_CMODE_SPEECH_EFR:
case GSM48_CMODE_SPEECH_AMR:
channel_mode = 0x9;
break;
case GSM48_CMODE_SIGN:
channel_mode = 0x8;
break;
case GSM48_CMODE_DATA_14k5:
channel_mode = 0xe;
break;
case GSM48_CMODE_DATA_12k0:
channel_mode = 0xb;
break;
case GSM48_CMODE_DATA_6k0:
channel_mode = 0xc;
break;
case GSM48_CMODE_DATA_3k6:
channel_mode = 0xd;
break;
default:
return 0;
}
switch (type) {
case GSM_LCHAN_NONE:
channel = 0x0;
break;
case GSM_LCHAN_SDCCH:
channel = 0x1;
break;
case GSM_LCHAN_TCH_F:
channel = 0x8;
break;
case GSM_LCHAN_TCH_H:
channel = 0x9;
break;
default:
return 0;
}
return channel_mode << 4 | channel;
}
const char *gsm0808_channel_type_name(const struct gsm0808_channel_type *ct);
gsm0808_cell_id_u::lac_and_ci
struct osmo_lac_and_ci_id lac_and_ci
Definition: gsm0808_utils.h:41
len
uint8_t len
Definition: gsm_04_11.h:2
gsm0808_enc_aoip_trasp_addr
uint8_t gsm0808_enc_aoip_trasp_addr(struct msgb *msg, const struct sockaddr_storage *ss)
gsm_chan_t
gsm_chan_t
Definition: gsm_utils.h:218
osmo_location_area_id
Definition: gsm23003.h:16
gsm0808_enc_cell_id
uint8_t gsm0808_enc_cell_id(struct msgb *msg, const struct gsm0808_cell_id *ci)
Encode Cell Identifier IE (3GPP TS 48.008 3.2.2.17).
Definition: gsm0808_utils.c:1026
gsm0808_current_channel_type_1
static uint8_t gsm0808_current_channel_type_1(enum gsm_chan_t type)
Return 3GPP TS 48.008 3.2.2.49 Current Channel Type 1 from enum gsm_chan_t.
Definition: gsm0808_utils.h:109
gsm0808_dec_cell_id_list2
int gsm0808_dec_cell_id_list2(struct gsm0808_cell_id_list2 *cil, const uint8_t *elem, uint8_t len)
Decode Cell Identifier List IE.
Definition: gsm0808_utils.c:809
gsm0808_permitted_speech
gsm0808_permitted_speech
GSM 08.08 3.2.2.11 Channel Type (see also 3GPP TS 48.008, section 3.2.2.11)
Definition: gsm_08_08.h:420
GSM48_CMODE_DATA_12k0
@ GSM48_CMODE_DATA_12k0
Definition: gsm_04_08.h:701
gsm0808_cell_id::id_discr
enum CELL_IDENT id_discr
Definition: gsm0808_utils.h:49
osmo_cell_global_id
Definition: gsm23003.h:28
gsm0808_cell_id_list2::id_list
union gsm0808_cell_id_u id_list[GSM0808_CELL_ID_LIST2_MAXLEN]
Definition: gsm0808_utils.h:56
GSM0808_PERM_FR2
@ GSM0808_PERM_FR2
GSM EFR.
Definition: gsm_08_08.h:422
gsm0808_dec_channel_type
int gsm0808_dec_channel_type(struct gsm0808_channel_type *ct, const uint8_t *elem, uint8_t len)
Decode TS 08.08 Channel Type IE.
Definition: gsm0808_utils.c:462
gsm0808_enc_cell_id_list
uint8_t gsm0808_enc_cell_id_list(struct msgb *msg, const struct gsm0808_cell_id_list *cil) OSMO_DEPRECATED("use gsm0808_enc_cell_id_list2 instead")
DEPRECATED: Use gsm0808_enc_cell_id_list2 instead.
Definition: gsm0808_utils.c:645
gsm0808_speech_codec_from_chan_type
int gsm0808_speech_codec_from_chan_type(struct gsm0808_speech_codec *sc, uint8_t perm_spch)
Extrapolate a speech codec field from a given permitted speech parameter (channel type).
Definition: gsm0808_utils.c:1116
gsm0808_enc_channel_type
uint8_t gsm0808_enc_channel_type(struct msgb *msg, const struct gsm0808_channel_type *ct)
Encode TS 08.08 Channel Type IE.
Definition: gsm0808_utils.c:419
GSM_LCHAN_TCH_H
@ GSM_LCHAN_TCH_H
Definition: gsm_utils.h:222
gsm0808_dec_speech_codec_list
int gsm0808_dec_speech_codec_list(struct gsm0808_speech_codec_list *scl, const uint8_t *elem, uint8_t len)
Decode TS 08.08 Speech Codec list IE.
Definition: gsm0808_utils.c:375
gsm0808_channel_type
Definition: gsm_08_08.h:515
GSM48_CMODE_DATA_6k0
@ GSM48_CMODE_DATA_6k0
Definition: gsm_04_08.h:702
gsm0808_dec_speech_codec
int gsm0808_dec_speech_codec(struct gsm0808_speech_codec *sc, const uint8_t *elem, uint8_t len)
Decode TS 08.08 Speech Codec IE.
Definition: gsm0808_utils.c:259
gsm0808_cell_id_u::ci
uint16_t ci
Definition: gsm0808_utils.h:42
gsm0808_chosen_channel
static uint8_t gsm0808_chosen_channel(enum gsm_chan_t type, enum gsm48_chan_mode mode)
Return 3GPP TS 48.008 3.2.2.33 Chosen Channel.
Definition: gsm0808_utils.h:162
gsm0808_speech_codec_list
Definition: gsm_08_08.h:508
GSM_LCHAN_TCH_F
@ GSM_LCHAN_TCH_F
Definition: gsm_utils.h:221
mode
uint8_t mode
Definition: gsm_04_08.h:633
gsm0808_speech_codec
Definition: gsm_08_08.h:476
sc
uint8_t sc
Definition: gsm_04_08.h:717
CELL_IDENT
CELL_IDENT
Definition: gsm_08_08.h:16
gsm0808_enc_cell_id_list2
uint8_t gsm0808_enc_cell_id_list2(struct msgb *msg, const struct gsm0808_cell_id_list2 *cil)
Encode TS 08.08 Cell Identifier List IE.
Definition: gsm0808_utils.c:576
gsm0808_chan_type_to_speech_codec
int gsm0808_chan_type_to_speech_codec(uint8_t perm_spch)
Convert the representation of the permitted speech codec identifier that is used in struct gsm0808_ch...
Definition: gsm0808_utils.c:1078
gsm0808_cell_id_list_name_buf
int gsm0808_cell_id_list_name_buf(char *buf, size_t buflen, const struct gsm0808_cell_id_list2 *cil)
Return a human readable representation of the Cell Identifier List, like "LAC[2]:{123,...
Definition: gsm0808_utils.c:1266
gsm0808_cell_id_u::lac
uint16_t lac
Definition: gsm0808_utils.h:44
GSM48_CMODE_DATA_3k6
@ GSM48_CMODE_DATA_3k6
Definition: gsm_04_08.h:703
GSM_LCHAN_NONE
@ GSM_LCHAN_NONE
Definition: gsm_utils.h:219
GSM0808_PERM_HR2
@ GSM0808_PERM_HR2
(deprecated)
Definition: gsm_08_08.h:427
GSM48_CMODE_SPEECH_EFR
@ GSM48_CMODE_SPEECH_EFR
Definition: gsm_04_08.h:698
gsm_utils.h
type
uint8_t type
Definition: gsm_04_08.h:713
gsm0808_enc_speech_codec_list
uint8_t gsm0808_enc_speech_codec_list(struct msgb *msg, const struct gsm0808_speech_codec_list *scl)
Encode TS 08.08 Speech Codec list.
Definition: gsm0808_utils.c:339
gsm0808_channel_type_name
const char * gsm0808_channel_type_name(const struct gsm0808_channel_type *ct)
Definition: gsm0808_utils.c:1307
gsm0808_cell_id::id
union gsm0808_cell_id_u id
Definition: gsm0808_utils.h:50
gsm0808_cell_id_list
DEPRECATED: This definition of the cell identifier list is insufficient.
Definition: gsm_08_08.h:539
gsm0808_cell_id_list2
Parsed representation of a Cell Identifier List IE (3GPP TS 48.008 3.2.2.27).
Definition: gsm0808_utils.h:54
GSM48_CMODE_SPEECH_V1
@ GSM48_CMODE_SPEECH_V1
Definition: gsm_04_08.h:697
gsm0808_enc_speech_codec
uint8_t gsm0808_enc_speech_codec(struct msgb *msg, const struct gsm0808_speech_codec *sc)
Encode TS 08.08 Speech Codec IE.
Definition: gsm0808_utils.c:234
gsm_04_08.h
GSM48_CMODE_DATA_14k5
@ GSM48_CMODE_DATA_14k5
Definition: gsm_04_08.h:700
gsm0808_cell_id_u_name
int gsm0808_cell_id_u_name(char *buf, size_t buflen, enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u)
Print a human readable name of the cell identifier to the char buffer.
Definition: gsm0808_utils.c:1174
GSM_LCHAN_SDCCH
@ GSM_LCHAN_SDCCH
Definition: gsm_utils.h:220
gsm0808_cell_id_name
const char * gsm0808_cell_id_name(const struct gsm0808_cell_id *cid)
Return a human readable representation of a Cell Identifier, like "LAC:123" or "CGI:001-01-42-23".
Definition: gsm0808_utils.c:1238
gsm0808_cell_id
Parsed representation of Cell Identifier IE (3GPP TS 48.008 3.2.2.17)
Definition: gsm0808_utils.h:48
gsm0808_dec_cell_id_list
int gsm0808_dec_cell_id_list(struct gsm0808_cell_id_list *cil, const uint8_t *elem, uint8_t len) OSMO_DEPRECATED("use gsm0808_dec_cell_id_list2 instead")
DEPRECATED: Use gsm0808_dec_cell_id_list2 instead.
Definition: gsm0808_utils.c:871
gsm0808_cell_id_list_name
const char * gsm0808_cell_id_list_name(const struct gsm0808_cell_id_list2 *cil)
Return a human-readable representation of cil in a static buffer.
Definition: gsm0808_utils.c:1297
gsm23003.h
GSM0808_PERM_FR3
@ GSM0808_PERM_FR3
FR AMR.
Definition: gsm_08_08.h:423
GSM48_CMODE_SIGN
@ GSM48_CMODE_SIGN
Definition: gsm_04_08.h:696
gsm0808_permitted_speech
static enum gsm0808_permitted_speech gsm0808_permitted_speech(enum gsm_chan_t type, enum gsm48_chan_mode mode)
Return 3GPP TS 48.008 3.2.2.51 Speech Version aka permitted speech version indication in 3....
Definition: gsm0808_utils.h:125
GSM0808_PERM_HR1
@ GSM0808_PERM_HR1
GSM HR.
Definition: gsm_08_08.h:426
gsm0808_cell_id_name2
const char * gsm0808_cell_id_name2(const struct gsm0808_cell_id *cid)
Like gsm0808_cell_id_name() but uses a different static buffer.
Definition: gsm0808_utils.c:1248
gsm0808_dec_cell_id
int gsm0808_dec_cell_id(struct gsm0808_cell_id *ci, const uint8_t *elem, uint8_t len)
Decode Cell Identifier IE (3GPP TS 48.008 3.2.2.17).
Definition: gsm0808_utils.c:1054
GSM48_CMODE_SPEECH_AMR
@ GSM48_CMODE_SPEECH_AMR
Definition: gsm_04_08.h:699
gsm_08_08.h
gsm0808_encrypt_info
Definition: gsm_08_08.h:525
gsm0808_cell_id_list_add
int gsm0808_cell_id_list_add(struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id_list2 *src)
Append entries from one Cell Identifier List to another.
Definition: gsm0808_utils.c:958
GSM0808_PERM_HR3
@ GSM0808_PERM_HR3
HR AMR.
Definition: gsm_08_08.h:428
GSM0808_CELL_ID_LIST2_MAXLEN
#define GSM0808_CELL_ID_LIST2_MAXLEN
(225-1)/2 is the maximum number of elements in a cell identifier list.
Definition: gsm0808_utils.h:34
gsm0808_cell_id_discr_name
static const char * gsm0808_cell_id_discr_name(enum CELL_IDENT id_discr)
Definition: gsm0808_utils.h:61
gsm0808_cell_id_u::lai_and_lac
struct osmo_location_area_id lai_and_lac
Definition: gsm0808_utils.h:43
gsm0808_enc_encrypt_info
uint8_t gsm0808_enc_encrypt_info(struct msgb *msg, const struct gsm0808_encrypt_info *ei)
Encode TS 08.08 Encryption Information IE.
Definition: gsm0808_utils.c:499
gsm0808_cell_id_list2::id_list_len
unsigned int id_list_len
Definition: gsm0808_utils.h:57
GSM0808_PERM_FR1
@ GSM0808_PERM_FR1
GSM FR.
Definition: gsm_08_08.h:421
gsm0808_dec_encrypt_info
int gsm0808_dec_encrypt_info(struct gsm0808_encrypt_info *ei, const uint8_t *elem, uint8_t len)
Decode TS 08.08 Encryption Information IE.
Definition: gsm0808_utils.c:538
gsm0808_cell_id_u::global
struct osmo_cell_global_id global
Definition: gsm0808_utils.h:40
gsm0808_dec_aoip_trasp_addr
int gsm0808_dec_aoip_trasp_addr(struct sockaddr_storage *ss, const uint8_t *elem, uint8_t len)
gsm0808_cell_id_discr_names
const struct value_string gsm0808_cell_id_discr_names[]
value_string[] for enum CELL_IDENT.
Definition: gsm0808_utils.c:1196
gsm48_chan_mode
gsm48_chan_mode
Definition: gsm_04_08.h:695
osmo_lac_and_ci_id
Definition: gsm23003.h:35
gsm0808_cell_id_list2::id_discr
enum CELL_IDENT id_discr
Definition: gsm0808_utils.h:55
gsm0808_cell_id_u
Instead of this, use either struct gsm0808_cell_id or gsm0808_cell_id_list2.
Definition: gsm0808_utils.h:39
gsm0808_cell_id_to_list
void gsm0808_cell_id_to_list(struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id *src)
Convert a single Cell Identifier to a Cell Identifier List with one entry.
Definition: gsm0808_utils.c:995