libosmogsm  0.12.0.47-7c74
Osmocom GSM library
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/gsm23003.h>
31 #include <osmocom/gsm/gsm_utils.h>
32 
34 #define GSM0808_CELL_ID_LIST2_MAXLEN 127
35 
42  uint16_t ci;
44  uint16_t lac;
45 };
46 
49  enum CELL_IDENT id_discr;
51 };
52 
55  enum CELL_IDENT id_discr;
57  unsigned int id_list_len;
58 };
59 
60 extern const struct value_string gsm0808_cell_id_discr_names[];
61 static inline const char *gsm0808_cell_id_discr_name(enum CELL_IDENT id_discr)
62 { return get_value_string(gsm0808_cell_id_discr_names, id_discr); }
63 
64 const char *gsm0808_cell_id_name(const struct gsm0808_cell_id *cid);
65 const char *gsm0808_cell_id_name2(const struct gsm0808_cell_id *cid);
66 const char *gsm0808_cell_id_list_name(const struct gsm0808_cell_id_list2 *cil);
67 int gsm0808_cell_id_list_name_buf(char *buf, size_t buflen, const struct gsm0808_cell_id_list2 *cil);
68 int gsm0808_cell_id_u_name(char *buf, size_t buflen,
69  enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u);
70 
71 uint8_t gsm0808_enc_aoip_trasp_addr(struct msgb *msg,
72  const struct sockaddr_storage *ss);
73 int gsm0808_dec_aoip_trasp_addr(struct sockaddr_storage *ss,
74  const uint8_t *elem, uint8_t len);
75 uint8_t gsm0808_enc_speech_codec(struct msgb *msg,
76  const struct gsm0808_speech_codec *sc);
78  const uint8_t *elem, uint8_t len);
79 uint8_t gsm0808_enc_speech_codec_list(struct msgb *msg,
80  const struct gsm0808_speech_codec_list
81  *scl);
83  const uint8_t *elem, uint8_t len);
84 uint8_t gsm0808_enc_channel_type(struct msgb *msg,
85  const struct gsm0808_channel_type *ct);
87  const uint8_t *elem, uint8_t len);
88 uint8_t gsm0808_enc_encrypt_info(struct msgb *msg,
89  const struct gsm0808_encrypt_info *ei);
91  const uint8_t *elem, uint8_t len);
92 uint8_t gsm0808_enc_cell_id_list2(struct msgb *msg, const struct gsm0808_cell_id_list2 *cil);
93 uint8_t gsm0808_enc_cell_id_list(struct msgb *msg,
94  const struct gsm0808_cell_id_list *cil)
95  OSMO_DEPRECATED("use gsm0808_enc_cell_id_list2 instead");
96 int gsm0808_dec_cell_id_list2(struct gsm0808_cell_id_list2 *cil, const uint8_t *elem, uint8_t len);
98  const uint8_t *elem, uint8_t len)
99  OSMO_DEPRECATED("use gsm0808_dec_cell_id_list2 instead");
100 int gsm0808_cell_id_list_add(struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id_list2 *src);
101 void gsm0808_cell_id_to_list(struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id *src);
102 uint8_t gsm0808_enc_cell_id(struct msgb *msg, const struct gsm0808_cell_id *ci);
103 int gsm0808_dec_cell_id(struct gsm0808_cell_id *ci, const uint8_t *elem, uint8_t len);
104 int gsm0808_chan_type_to_speech_codec(uint8_t perm_spch);
106  uint8_t perm_spch);
107 
109 static inline uint8_t gsm0808_current_channel_type_1(enum gsm_chan_t type)
110 {
111  switch (type) {
112  default:
113  return 0;
114  case GSM_LCHAN_SDCCH:
115  return 0x01;
116  case GSM_LCHAN_TCH_F:
117  return 0x18;
118  case GSM_LCHAN_TCH_H:
119  return 0x19;
120  }
121 }
122 
126  enum gsm48_chan_mode mode)
127 {
128  switch (mode) {
130  switch (type) {
131  case GSM_LCHAN_TCH_F:
132  return GSM0808_PERM_FR1;
133  case GSM_LCHAN_TCH_H:
134  return GSM0808_PERM_HR1;
135  default:
136  return 0;
137  }
139  switch (type) {
140  case GSM_LCHAN_TCH_F:
141  return GSM0808_PERM_FR2;
142  case GSM_LCHAN_TCH_H:
143  return GSM0808_PERM_HR2;
144  default:
145  return 0;
146  }
148  switch (type) {
149  case GSM_LCHAN_TCH_F:
150  return GSM0808_PERM_FR3;
151  case GSM_LCHAN_TCH_H:
152  return GSM0808_PERM_HR3;
153  default:
154  return 0;
155  }
156  default:
157  return 0;
158  }
159 }
160 
162 static inline uint8_t gsm0808_chosen_channel(enum gsm_chan_t type, enum gsm48_chan_mode mode)
163 {
164  uint8_t channel_mode = 0, channel = 0;
165 
166  switch (mode) {
170  channel_mode = 0x9;
171  break;
172  case GSM48_CMODE_SIGN:
173  channel_mode = 0x8;
174  break;
176  channel_mode = 0xe;
177  break;
179  channel_mode = 0xb;
180  break;
182  channel_mode = 0xc;
183  break;
185  channel_mode = 0xd;
186  break;
187  default:
188  return 0;
189  }
190 
191  switch (type) {
192  case GSM_LCHAN_NONE:
193  channel = 0x0;
194  break;
195  case GSM_LCHAN_SDCCH:
196  channel = 0x1;
197  break;
198  case GSM_LCHAN_TCH_F:
199  channel = 0x8;
200  break;
201  case GSM_LCHAN_TCH_H:
202  channel = 0x9;
203  break;
204  default:
205  return 0;
206  }
207 
208  return channel_mode << 4 | channel;
209 }
210 
211 const char *gsm0808_channel_type_name(const struct gsm0808_channel_type *ct);
212 
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
Definition: gsm_04_08.h:546
uint16_t lac
Definition: gsm0808_utils.h:44
unsigned int id_list_len
Definition: gsm0808_utils.h:57
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
#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:125
gsm48_chan_mode
Definition: gsm_04_08.h:544
Definition: gsm_04_08.h:552
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:54
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
Definition: gsm_04_08.h:545
GSM FR.
Definition: gsm_08_08.h:421
Definition: gsm_04_08.h:550
(deprecated)
Definition: gsm_08_08.h:427
HR AMR.
Definition: gsm_08_08.h:428
GSM EFR.
Definition: gsm_08_08.h:422
struct osmo_location_area_id lai_and_lac
Definition: gsm0808_utils.h:43
static const char * gsm0808_cell_id_discr_name(enum CELL_IDENT id_discr)
Definition: gsm0808_utils.h:61
#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
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
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
Definition: gsm_utils.h:221
uint8_t type
Definition: gsm_04_08.h:557
Instead of this, use either struct gsm0808_cell_id or gsm0808_cell_id_list2.
Definition: gsm0808_utils.h:39
struct osmo_lac_and_ci_id lac_and_ci
Definition: gsm0808_utils.h:41
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
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
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
Definition: gsm23003.h:35
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
Definition: gsm_04_08.h:551
Definition: gsm_utils.h:222
GSM TS 04.08 definitions.
GSM HR.
Definition: gsm_08_08.h:426
Definition: gsm_08_08.h:508
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
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:1248
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
Definition: gsm_utils.h:220
struct osmo_cell_global_id global
Definition: gsm0808_utils.h:40
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
uint8_t sc
Definition: gsm_04_08.h:557
const struct value_string gsm0808_cell_id_discr_names[]
value_string[] for enum CELL_IDENT.
Definition: gsm0808_utils.c:1196
Definition: gsm23003.h:28
FR AMR.
Definition: gsm_08_08.h:423
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
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:1116
Definition: gsm23003.h:16
uint8_t len
Definition: gsm_04_11.h:434
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:1266
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
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
uint8_t mode
Definition: gsm_04_08.h:503
Definition: gsm_04_08.h:549
Definition: gsm_08_08.h:515
Definition: gsm_04_08.h:548
Definition: gsm_utils.h:219
CELL_IDENT
Definition: gsm_08_08.h:16
gsm_chan_t
Definition: gsm_utils.h:218
Definition: gsm_08_08.h:525
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
Parsed representation of Cell Identifier IE (3GPP TS 48.008 3.2.2.17)
Definition: gsm0808_utils.h:48
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
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
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
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
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
const char * gsm0808_channel_type_name(const struct gsm0808_channel_type *ct)
Definition: gsm0808_utils.c:1307
Definition: gsm_04_08.h:547
uint16_t ci
Definition: gsm0808_utils.h:42
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 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:1078
DEPRECATED: This definition of the cell identifier list is insufficient.
Definition: gsm_08_08.h:539
Definition: gsm_08_08.h:476