libosmogsm  1.0.1
Osmocom GSM library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gsm0808_utils.h
Go to the documentation of this file.
1 
4 /*
5  * (C) 2016 by sysmocom - s.f.m.c. GmbH, Author: Philipp Maier
6  * All Rights Reserved
7  *
8  * SPDX-License-Identifier: GPL-2.0+
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24 #pragma once
25 
26 struct sockaddr_storage;
27 
30 #include <osmocom/gsm/gsm29205.h>
31 #include <osmocom/gsm/gsm23003.h>
32 #include <osmocom/gsm/gsm_utils.h>
33 #include <osmocom/gsm/tlv.h>
34 
36 #define GSM0808_CELL_ID_LIST2_MAXLEN 127
37 
44  uint16_t ci;
46  uint16_t lac;
47 };
48 
53 };
54 
59  unsigned int id_list_len;
60 };
61 
63 struct osmo_lcls {
68  bool corr_needed;
69 };
70 
71 extern const struct value_string gsm0808_cell_id_discr_names[];
72 static inline const char *gsm0808_cell_id_discr_name(enum CELL_IDENT id_discr)
73 { return get_value_string(gsm0808_cell_id_discr_names, id_discr); }
74 
75 const char *gsm0808_cell_id_name(const struct gsm0808_cell_id *cid);
76 const char *gsm0808_cell_id_name2(const struct gsm0808_cell_id *cid);
77 const char *gsm0808_cell_id_list_name(const struct gsm0808_cell_id_list2 *cil);
78 int gsm0808_cell_id_list_name_buf(char *buf, size_t buflen, const struct gsm0808_cell_id_list2 *cil);
79 int gsm0808_cell_id_u_name(char *buf, size_t buflen,
80  enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u);
81 
82 uint8_t gsm0808_enc_cause(struct msgb *msg, uint16_t cause);
83 uint8_t gsm0808_enc_aoip_trasp_addr(struct msgb *msg,
84  const struct sockaddr_storage *ss);
85 int gsm0808_dec_aoip_trasp_addr(struct sockaddr_storage *ss,
86  const uint8_t *elem, uint8_t len);
87 
88 uint8_t gsm0808_enc_lcls(struct msgb *msg, const struct osmo_lcls *lcls);
89 int gsm0808_dec_lcls(struct osmo_lcls *lcls, const struct tlv_parsed *tp);
90 
91 uint8_t gsm0808_enc_speech_codec(struct msgb *msg,
92  const struct gsm0808_speech_codec *sc);
94  const uint8_t *elem, uint8_t len);
95 uint8_t gsm0808_enc_speech_codec_list(struct msgb *msg,
96  const struct gsm0808_speech_codec_list
97  *scl);
99  const uint8_t *elem, uint8_t len);
100 uint8_t gsm0808_enc_channel_type(struct msgb *msg,
101  const struct gsm0808_channel_type *ct);
103  const uint8_t *elem, uint8_t len);
104 uint8_t gsm0808_enc_encrypt_info(struct msgb *msg,
105  const struct gsm0808_encrypt_info *ei);
107  const uint8_t *elem, uint8_t len);
108 uint8_t gsm0808_enc_cell_id_list2(struct msgb *msg, const struct gsm0808_cell_id_list2 *cil);
109 uint8_t gsm0808_enc_cell_id_list(struct msgb *msg,
110  const struct gsm0808_cell_id_list *cil)
111  OSMO_DEPRECATED("use gsm0808_enc_cell_id_list2 instead");
112 int gsm0808_dec_cell_id_list2(struct gsm0808_cell_id_list2 *cil, const uint8_t *elem, uint8_t len);
114  const uint8_t *elem, uint8_t len)
115  OSMO_DEPRECATED("use gsm0808_dec_cell_id_list2 instead");
116 int gsm0808_cell_id_list_add(struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id_list2 *src);
117 void gsm0808_cell_id_to_list(struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id *src);
118 uint8_t gsm0808_enc_cell_id(struct msgb *msg, const struct gsm0808_cell_id *ci);
119 int gsm0808_dec_cell_id(struct gsm0808_cell_id *ci, const uint8_t *elem, uint8_t len);
120 int gsm0808_chan_type_to_speech_codec(uint8_t perm_spch);
122  uint8_t perm_spch);
123 uint16_t gsm0808_sc_cfg_from_gsm48_mr_cfg(const struct gsm48_multi_rate_conf *cfg, bool fr);
124 void gsm48_mr_cfg_from_gsm0808_sc_cfg(struct gsm48_multi_rate_conf *cfg, uint16_t s15_s0);
125 
128 {
129  return (cause << 1) >> 4;
130 }
131 
133 static inline bool gsm0808_cause_ext(enum gsm0808_cause cause)
134 {
135  /* check that cause looks like 1XXX0000 where XXX represent class */
136  return (cause & 0x80) && !(cause & 0x0F);
137 }
138 
139 int gsm0808_get_cipher_reject_cause(const struct tlv_parsed *tp);
140 
142 static inline uint8_t gsm0808_current_channel_type_1(enum gsm_chan_t type)
143 {
144  switch (type) {
145  default:
146  return 0;
147  case GSM_LCHAN_SDCCH:
148  return 0x01;
149  case GSM_LCHAN_TCH_F:
150  return 0x18;
151  case GSM_LCHAN_TCH_H:
152  return 0x19;
153  }
154 }
155 
159  enum gsm48_chan_mode mode)
160 {
161  switch (mode) {
163  switch (type) {
164  case GSM_LCHAN_TCH_F:
165  return GSM0808_PERM_FR1;
166  case GSM_LCHAN_TCH_H:
167  return GSM0808_PERM_HR1;
168  default:
169  return 0;
170  }
172  switch (type) {
173  case GSM_LCHAN_TCH_F:
174  return GSM0808_PERM_FR2;
175  case GSM_LCHAN_TCH_H:
176  return GSM0808_PERM_HR2;
177  default:
178  return 0;
179  }
181  switch (type) {
182  case GSM_LCHAN_TCH_F:
183  return GSM0808_PERM_FR3;
184  case GSM_LCHAN_TCH_H:
185  return GSM0808_PERM_HR3;
186  default:
187  return 0;
188  }
189  default:
190  return 0;
191  }
192 }
193 
195 static inline uint8_t gsm0808_chosen_channel(enum gsm_chan_t type, enum gsm48_chan_mode mode)
196 {
197  uint8_t channel_mode = 0, channel = 0;
198 
199  switch (mode) {
203  channel_mode = 0x9;
204  break;
205  case GSM48_CMODE_SIGN:
206  channel_mode = 0x8;
207  break;
209  channel_mode = 0xe;
210  break;
212  channel_mode = 0xb;
213  break;
215  channel_mode = 0xc;
216  break;
218  channel_mode = 0xd;
219  break;
220  default:
221  return 0;
222  }
223 
224  switch (type) {
225  case GSM_LCHAN_NONE:
226  channel = 0x0;
227  break;
228  case GSM_LCHAN_SDCCH:
229  channel = 0x1;
230  break;
231  case GSM_LCHAN_TCH_F:
232  channel = 0x8;
233  break;
234  case GSM_LCHAN_TCH_H:
235  channel = 0x9;
236  break;
237  default:
238  return 0;
239  }
240 
241  return channel_mode << 4 | channel;
242 }
243 
244 const char *gsm0808_channel_type_name(const struct gsm0808_channel_type *ct);
245 
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:365
Definition: gsm_04_08.h:794
uint16_t lac
Definition: gsm0808_utils.h:46
enum gsm0808_lcls_config config
§3.2.2.116 Configuration.
Definition: gsm0808_utils.h:64
uint8_t type
Definition: gsm_08_08.h:469
unsigned int id_list_len
Definition: gsm0808_utils.h:59
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:675
#define OSMO_DEPRECATED(text)
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:158
gsm48_chan_mode
Definition: gsm_04_08.h:792
Definition: gsm_04_08.h:800
const char * get_value_string(const struct value_string *vs, uint32_t val)
Parsed representation of a Cell Identifier List IE (3GPP TS 48.008 3.2.2.27).
Definition: gsm0808_utils.h:56
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:598
Definition: gsm_04_08.h:793
GSM FR.
Definition: gsm_08_08.h:438
gsm0808_cause_class
Definition: gsm_08_08.h:393
Definition: gsm_04_08.h:798
(deprecated)
Definition: gsm_08_08.h:444
void gsm48_mr_cfg_from_gsm0808_sc_cfg(struct gsm48_multi_rate_conf *cfg, uint16_t s15_s0)
Determine a GSM 04.08 AMR configuration struct from a set of speech codec configuration bits (S0-S15)...
Definition: gsm0808_utils.c:1310
LCLS-related parameters from 3GPP TS 48.008.
Definition: gsm0808_utils.h:63
HR AMR.
Definition: gsm_08_08.h:445
GSM EFR.
Definition: gsm_08_08.h:439
struct osmo_location_area_id lai_and_lac
Definition: gsm0808_utils.h:45
static const char * gsm0808_cell_id_discr_name(enum CELL_IDENT id_discr)
Definition: gsm0808_utils.h:72
gsm0808_lcls_control
Definition: gsm_08_08.h:588
#define GSM0808_CELL_ID_LIST2_MAXLEN
(225-1)/2 is the maximum number of elements in a cell identifier list.
Definition: gsm0808_utils.h:36
union gsm0808_cell_id_u id_list[GSM0808_CELL_ID_LIST2_MAXLEN]
Definition: gsm0808_utils.h:58
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:1057
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:970
Definition: gsm_utils.h:222
int gsm0808_get_cipher_reject_cause(const struct tlv_parsed *tp)
Definition: gsm0808_utils.c:1347
Instead of this, use either struct gsm0808_cell_id or gsm0808_cell_id_list2.
Definition: gsm0808_utils.h:41
int gsm0808_dec_lcls(struct osmo_lcls *lcls, const struct tlv_parsed *tp)
Decode LCLS parameters to a given msgb, 3GPP TS 48.008 §3.2.2.115 - 3.2.2.120.
Definition: gsm0808_utils.c:582
uint8_t cause
Definition: gsm_04_08.h:807
struct osmo_lac_and_ci_id lac_and_ci
Definition: gsm0808_utils.h:43
uint16_t gsm0808_sc_cfg_from_gsm48_mr_cfg(const struct gsm48_multi_rate_conf *cfg, bool fr)
Determine a set of AMR speech codec configuration bits (S0-S15) from a given GSM 04.08 AMR configuration struct.
Definition: gsm0808_utils.c:1268
uint8_t gsm0808_enc_lcls(struct msgb *msg, const struct osmo_lcls *lcls)
Add LCLS parameters to a given msgb, 3GPP TS 48.008 §3.2.2.115 - 3.2.2.120.
Definition: gsm0808_utils.c:549
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:1437
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:637
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:1153
Definition: gsm23003.h:35
enum CELL_IDENT id_discr
Definition: gsm0808_utils.h:57
static enum gsm0808_cause_class gsm0808_cause_class(enum gsm0808_cause cause)
Definition: gsm0808_utils.h:127
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:1094
Definition: gsm_04_08.h:799
uint8_t gsm0808_enc_cause(struct msgb *msg, uint16_t cause)
Definition: gsm_utils.h:223
GSM TS 04.08 definitions.
GSM HR.
Definition: gsm_08_08.h:443
Definition: gsm_08_08.h:539
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:437
uint8_t gsm0808_enc_aoip_trasp_addr(struct msgb *msg, const struct sockaddr_storage *ss)
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:1447
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:1125
Definition: gsm_utils.h:221
enum CELL_IDENT id_discr
Definition: gsm0808_utils.h:51
static bool gsm0808_cause_ext(enum gsm0808_cause cause)
Definition: gsm0808_utils.h:133
struct osmo_cell_global_id global
Definition: gsm0808_utils.h:42
union gsm0808_cell_id_u id
Definition: gsm0808_utils.h:52
static uint8_t gsm0808_current_channel_type_1(enum gsm_chan_t type)
Definition: gsm0808_utils.h:142
gsm0808_cause
Definition: gsm_08_08.h:326
const struct value_string gsm0808_cell_id_discr_names[]
value_string[] for enum CELL_IDENT.
Definition: gsm0808_utils.c:1395
Definition: gsm23003.h:28
FR AMR.
Definition: gsm_08_08.h:440
Parsed representation of Global Call Reference, 3GPP TS 29.205 Table B 2.1.9.1.
Definition: gsm29205.h:33
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:744
int gsm0808_dec_aoip_trasp_addr(struct sockaddr_storage *ss, const uint8_t *elem, uint8_t len)
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:1215
Definition: gsm23003.h:16
uint8_t len
Definition: gsm_04_11.h:465
bool gcr_available
Definition: gsm0808_utils.h:67
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, 456}".
Definition: gsm0808_utils.c:1465
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:435
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:195
uint8_t mode
Definition: gsm_04_08.h:733
Definition: gsm_04_08.h:797
Definition: gsm_08_08.h:546
Definition: gsm_04_08.h:796
Definition: gsm_utils.h:220
result of the TLV parser
Definition: tlv.h:442
CELL_IDENT
Definition: gsm_08_08.h:16
gsm_chan_t
Definition: gsm_utils.h:219
Definition: gsm_08_08.h:556
Definition: gsm_04_08.h:646
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:285
Parsed representation of Cell Identifier IE (3GPP TS 48.008 3.2.2.17)
Definition: gsm0808_utils.h:50
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:1496
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:398
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:908
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:478
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:260
gsm0808_lcls_config
Definition: gsm_08_08.h:577
const char * gsm0808_channel_type_name(const struct gsm0808_channel_type *ct)
Definition: gsm0808_utils.c:1506
Definition: gsm_04_08.h:795
uint16_t ci
Definition: gsm0808_utils.h:44
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:1373
enum gsm0808_lcls_control control
§3.2.2.117 Connection Status Control.
Definition: gsm0808_utils.h:65
GSM utility functions, e.g.
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:1177
bool corr_needed
§3.2.2.118 Correlation-Not-Needed.
Definition: gsm0808_utils.h:68
DEPRECATED: This definition of the cell identifier list is insufficient.
Definition: gsm_08_08.h:570
Definition: gsm_08_08.h:493
struct osmo_gcr_parsed gcr
§3.2.2.115 Global Call Reference.
Definition: gsm0808_utils.h:66