libosmogsm  0.11.0-dirty
Osmocom GSM library
include/osmocom/gsm/gsm0808_utils.h
Go to the documentation of this file.
00001 
00004 /*
00005  * (C) 2016 by sysmocom - s.f.m.c. GmbH, Author: Philipp Maier
00006  * All Rights Reserved
00007  *
00008  * SPDX-License-Identifier: GPL-2.0+
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00022  *
00023  */
00024 #pragma once
00025 
00026 struct sockaddr_storage;
00027 
00028 #include <osmocom/gsm/protocol/gsm_08_08.h>
00029 #include <osmocom/gsm/protocol/gsm_04_08.h>
00030 #include <osmocom/gsm/gsm23003.h>
00031 #include <osmocom/gsm/gsm_utils.h>
00032 
00034 #define GSM0808_CELL_ID_LIST2_MAXLEN            127
00035 
00039 union gsm0808_cell_id_u {
00040         struct osmo_cell_global_id              global;
00041         struct osmo_lac_and_ci_id               lac_and_ci;
00042         uint16_t                                ci;
00043         struct osmo_location_area_id            lai_and_lac;
00044         uint16_t                                lac;
00045 };
00046 
00048 struct gsm0808_cell_id {
00049         enum CELL_IDENT id_discr;
00050         union gsm0808_cell_id_u id;
00051 };
00052 
00054 struct gsm0808_cell_id_list2 {
00055         enum CELL_IDENT id_discr;
00056         union gsm0808_cell_id_u id_list[GSM0808_CELL_ID_LIST2_MAXLEN];
00057         unsigned int id_list_len;
00058 };
00059 
00060 extern const struct value_string gsm0808_cell_id_discr_names[];
00061 static inline const char *gsm0808_cell_id_discr_name(enum CELL_IDENT id_discr)
00062 { return get_value_string(gsm0808_cell_id_discr_names, id_discr); }
00063 
00064 const char *gsm0808_cell_id_name(const struct gsm0808_cell_id *cid);
00065 const char *gsm0808_cell_id_name2(const struct gsm0808_cell_id *cid);
00066 const char *gsm0808_cell_id_list_name(const struct gsm0808_cell_id_list2 *cil);
00067 int gsm0808_cell_id_list_name_buf(char *buf, size_t buflen, const struct gsm0808_cell_id_list2 *cil);
00068 int gsm0808_cell_id_u_name(char *buf, size_t buflen,
00069                            enum CELL_IDENT id_discr, const union gsm0808_cell_id_u *u);
00070 
00071 uint8_t gsm0808_enc_aoip_trasp_addr(struct msgb *msg,
00072                                     const struct sockaddr_storage *ss);
00073 int gsm0808_dec_aoip_trasp_addr(struct sockaddr_storage *ss,
00074                                 const uint8_t *elem, uint8_t len);
00075 uint8_t gsm0808_enc_speech_codec(struct msgb *msg,
00076                                  const struct gsm0808_speech_codec *sc);
00077 int gsm0808_dec_speech_codec(struct gsm0808_speech_codec *sc,
00078                              const uint8_t *elem, uint8_t len);
00079 uint8_t gsm0808_enc_speech_codec_list(struct msgb *msg,
00080                                       const struct gsm0808_speech_codec_list
00081                                       *scl);
00082 int gsm0808_dec_speech_codec_list(struct gsm0808_speech_codec_list *scl,
00083                                   const uint8_t *elem, uint8_t len);
00084 uint8_t gsm0808_enc_channel_type(struct msgb *msg,
00085                                  const struct gsm0808_channel_type *ct);
00086 int gsm0808_dec_channel_type(struct gsm0808_channel_type *ct,
00087                              const uint8_t *elem, uint8_t len);
00088 uint8_t gsm0808_enc_encrypt_info(struct msgb *msg,
00089                                  const struct gsm0808_encrypt_info *ei);
00090 int gsm0808_dec_encrypt_info(struct gsm0808_encrypt_info *ei,
00091                              const uint8_t *elem, uint8_t len);
00092 uint8_t gsm0808_enc_cell_id_list2(struct msgb *msg, const struct gsm0808_cell_id_list2 *cil);
00093 uint8_t gsm0808_enc_cell_id_list(struct msgb *msg,
00094                                  const struct gsm0808_cell_id_list *cil)
00095                                  OSMO_DEPRECATED("use gsm0808_enc_cell_id_list2 instead");
00096 int gsm0808_dec_cell_id_list2(struct gsm0808_cell_id_list2 *cil, const uint8_t *elem, uint8_t len);
00097 int gsm0808_dec_cell_id_list(struct gsm0808_cell_id_list *cil,
00098                              const uint8_t *elem, uint8_t len)
00099                              OSMO_DEPRECATED("use gsm0808_dec_cell_id_list2 instead");
00100 int gsm0808_cell_id_list_add(struct gsm0808_cell_id_list2 *dst, const struct gsm0808_cell_id_list2 *src);
00101 uint8_t gsm0808_enc_cell_id(struct msgb *msg, const struct gsm0808_cell_id *ci);
00102 int gsm0808_dec_cell_id(struct gsm0808_cell_id *ci, const uint8_t *elem, uint8_t len);
00103 int gsm0808_chan_type_to_speech_codec(uint8_t perm_spch);
00104 int gsm0808_speech_codec_from_chan_type(struct gsm0808_speech_codec *sc,
00105                                         uint8_t perm_spch);
00106 
00108 static inline uint8_t gsm0808_current_channel_type_1(enum gsm_chan_t type)
00109 {
00110         switch (type) {
00111         default:
00112                 return 0;
00113         case GSM_LCHAN_SDCCH:
00114                 return 0x01;
00115         case GSM_LCHAN_TCH_F:
00116                 return 0x18;
00117         case GSM_LCHAN_TCH_H:
00118                 return 0x19;
00119         }
00120 }
00121 
00124 static inline enum gsm0808_permitted_speech gsm0808_permitted_speech(enum gsm_chan_t type,
00125                                                                      enum gsm48_chan_mode mode)
00126 {
00127         switch (mode) {
00128         case GSM48_CMODE_SPEECH_V1:
00129                 switch (type) {
00130                 case GSM_LCHAN_TCH_F:
00131                         return GSM0808_PERM_FR1;
00132                 case GSM_LCHAN_TCH_H:
00133                         return GSM0808_PERM_HR1;
00134                 default:
00135                         return 0;
00136                 }
00137         case GSM48_CMODE_SPEECH_EFR:
00138                 switch (type) {
00139                 case GSM_LCHAN_TCH_F:
00140                         return GSM0808_PERM_FR2;
00141                 case GSM_LCHAN_TCH_H:
00142                         return GSM0808_PERM_HR2;
00143                 default:
00144                         return 0;
00145                 }
00146         case GSM48_CMODE_SPEECH_AMR:
00147                 switch (type) {
00148                 case GSM_LCHAN_TCH_F:
00149                         return GSM0808_PERM_HR3;
00150                 case GSM_LCHAN_TCH_H:
00151                         return GSM0808_PERM_HR3;
00152                 default:
00153                         return 0;
00154                 }
00155         default:
00156                 return 0;
00157         }
00158 }
00159 
00161 static inline uint8_t gsm0808_chosen_channel(enum gsm_chan_t type, enum gsm48_chan_mode mode)
00162 {
00163         uint8_t channel_mode = 0, channel = 0;
00164 
00165         switch (mode) {
00166         case GSM48_CMODE_SPEECH_V1:
00167         case GSM48_CMODE_SPEECH_EFR:
00168         case GSM48_CMODE_SPEECH_AMR:
00169                 channel_mode = 0x9;
00170                 break;
00171         case GSM48_CMODE_SIGN:
00172                 channel_mode = 0x8;
00173                 break;
00174         case GSM48_CMODE_DATA_14k5:
00175                 channel_mode = 0xe;
00176                 break;
00177         case GSM48_CMODE_DATA_12k0:
00178                 channel_mode = 0xb;
00179                 break;
00180         case GSM48_CMODE_DATA_6k0:
00181                 channel_mode = 0xc;
00182                 break;
00183         case GSM48_CMODE_DATA_3k6:
00184                 channel_mode = 0xd;
00185                 break;
00186         default:
00187                 return 0;
00188         }
00189 
00190         switch (type) {
00191         case GSM_LCHAN_NONE:
00192                 channel = 0x0;
00193                 break;
00194         case GSM_LCHAN_SDCCH:
00195                 channel = 0x1;
00196                 break;
00197         case GSM_LCHAN_TCH_F:
00198                 channel = 0x8;
00199                 break;
00200         case GSM_LCHAN_TCH_H:
00201                 channel = 0x9;
00202                 break;
00203         default:
00204                 return 0;
00205         }
00206 
00207         return channel_mode << 4 | channel;
00208 }
00209 
00210 const char *gsm0808_channel_type_name(const struct gsm0808_channel_type *ct);
00211 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines