Harald Welte | 37b6165 | 2017-10-16 18:46:03 +0200 | [diff] [blame] | 1 | /*! \defgroup gsm0808 GSM 08.08 / 3GPP TS 48.008 A Interface |
| 2 | * @{ |
| 3 | * \file gsm0808.h */ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 4 | /* |
| 5 | * (C) 2009,2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 6 | * (C) 2009,2010 by On-Waves |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | * |
| 23 | */ |
Sylvain Munaut | 12ba778 | 2014-06-16 10:13:40 +0200 | [diff] [blame] | 24 | #pragma once |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 25 | |
| 26 | #include "tlv.h" |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 27 | #include <osmocom/gsm/protocol/gsm_08_08.h> |
Neels Hofmeyr | 70aba3f | 2018-03-13 03:40:53 +0100 | [diff] [blame] | 28 | #include <osmocom/gsm/gsm0808_utils.h> |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 29 | #include <osmocom/gsm/gsm23003.h> |
Harald Welte | ebd362d | 2018-06-02 14:11:19 +0200 | [diff] [blame] | 30 | #include <osmocom/core/utils.h> |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 31 | |
Max | f69aa9c | 2018-11-29 23:32:06 +0100 | [diff] [blame] | 32 | #define BSSMAP_MSG_SIZE 512 |
| 33 | #define BSSMAP_MSG_HEADROOM 128 |
| 34 | |
Harald Welte | 20725b9 | 2017-05-15 12:50:04 +0200 | [diff] [blame] | 35 | struct sockaddr_storage; |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 36 | |
| 37 | struct msgb; |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 38 | struct gsm0808_cell_id_list2; |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 39 | |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 40 | struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc, |
Neels Hofmeyr | bd6c8b5 | 2018-03-22 14:05:21 +0100 | [diff] [blame] | 41 | uint16_t cc, int lac, uint16_t _ci) |
| 42 | OSMO_DEPRECATED("Use gsm0808_create_layer3_2() instead, to not lose leading zeros in the MNC"); |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 43 | struct msgb *gsm0808_create_layer3_aoip(const struct msgb *msg_l3, uint16_t nc, |
| 44 | uint16_t cc, int lac, uint16_t _ci, |
Neels Hofmeyr | bd6c8b5 | 2018-03-22 14:05:21 +0100 | [diff] [blame] | 45 | const struct gsm0808_speech_codec_list *scl) |
| 46 | OSMO_DEPRECATED("Use gsm0808_create_layer3_2() instead, to not lose leading zeros in the MNC"); |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 47 | struct msgb *gsm0808_create_layer3_2(const struct msgb *msg_l3, const struct osmo_cell_global_id *cell, |
| 48 | const struct gsm0808_speech_codec_list *scl); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 49 | struct msgb *gsm0808_create_reset(void); |
Harald Welte | a62fe31 | 2013-06-19 15:14:37 +0200 | [diff] [blame] | 50 | struct msgb *gsm0808_create_reset_ack(void); |
Philipp Maier | 1a146c8 | 2018-10-30 09:36:49 +0100 | [diff] [blame] | 51 | struct msgb *gsm0808_create_clear_command(uint8_t cause); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 52 | struct msgb *gsm0808_create_clear_complete(void); |
Philipp Maier | b478dd3 | 2017-03-29 15:50:05 +0200 | [diff] [blame] | 53 | struct msgb *gsm0808_create_cipher(const struct gsm0808_encrypt_info *ei, |
| 54 | const uint8_t *cipher_response_mode); |
Holger Hans Peter Freyther | 81716d5 | 2010-04-17 06:16:35 +0200 | [diff] [blame] | 55 | struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id); |
Max | aa93463 | 2018-11-07 13:16:54 +0100 | [diff] [blame] | 56 | struct msgb *gsm0808_create_cipher_reject(enum gsm0808_cause cause); |
Max | ed651d2 | 2018-11-07 15:25:05 +0100 | [diff] [blame] | 57 | struct msgb *gsm0808_create_cipher_reject_ext(enum gsm0808_cause_class class, uint8_t ext); |
Neels Hofmeyr | 2c79d55 | 2018-09-13 05:36:32 +0200 | [diff] [blame] | 58 | struct msgb *gsm0808_create_classmark_request(); |
Harald Welte | 07b625d | 2012-01-23 10:02:58 +0100 | [diff] [blame] | 59 | struct msgb *gsm0808_create_classmark_update(const uint8_t *cm2, uint8_t cm2_len, |
| 60 | const uint8_t *cm3, uint8_t cm3_len); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 61 | struct msgb *gsm0808_create_sapi_reject(uint8_t link_id); |
Philipp Maier | c6144a2 | 2017-03-29 17:53:43 +0200 | [diff] [blame] | 62 | struct msgb *gsm0808_create_ass(const struct gsm0808_channel_type *ct, |
| 63 | const uint16_t *cic, |
| 64 | const struct sockaddr_storage *ss, |
| 65 | const struct gsm0808_speech_codec_list *scl, |
| 66 | const uint32_t *ci); |
Max | 5207432 | 2018-11-30 10:44:07 +0100 | [diff] [blame] | 67 | struct msgb *gsm0808_create_ass2(const struct gsm0808_channel_type *ct, |
| 68 | const uint16_t *cic, |
| 69 | const struct sockaddr_storage *ss, |
| 70 | const struct gsm0808_speech_codec_list *scl, |
| 71 | const uint32_t *ci, |
| 72 | const uint8_t *kc, const struct osmo_lcls *lcls); |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 73 | struct msgb *gsm0808_create_ass_compl(uint8_t rr_cause, uint8_t chosen_channel, |
| 74 | uint8_t encr_alg_id, uint8_t speech_mode, |
| 75 | const struct sockaddr_storage *ss, |
| 76 | const struct gsm0808_speech_codec *sc, |
| 77 | const struct gsm0808_speech_codec_list |
| 78 | *scl); |
Holger Hans Peter Freyther | b60a4b3 | 2010-07-23 18:35:59 +0800 | [diff] [blame] | 79 | struct msgb *gsm0808_create_assignment_completed(uint8_t rr_cause, |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 80 | uint8_t chosen_channel, |
| 81 | uint8_t encr_alg_id, |
Holger Hans Peter Freyther | ba6172a | 2010-04-17 06:21:49 +0200 | [diff] [blame] | 82 | uint8_t speech_mode); |
Philipp Maier | fa896ab | 2017-03-27 16:55:32 +0200 | [diff] [blame] | 83 | struct msgb *gsm0808_create_ass_fail(uint8_t cause, const uint8_t *rr_cause, |
| 84 | const struct gsm0808_speech_codec_list |
| 85 | *scl); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 86 | struct msgb *gsm0808_create_assignment_failure(uint8_t cause, uint8_t *rr_cause); |
Holger Hans Peter Freyther | af270a4 | 2010-11-04 12:42:50 +0100 | [diff] [blame] | 87 | struct msgb *gsm0808_create_clear_rqst(uint8_t cause); |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 88 | struct msgb *gsm0808_create_paging2(const char *imsi, const uint32_t *tmsi, |
| 89 | const struct gsm0808_cell_id_list2 *cil, |
| 90 | const uint8_t *chan_needed); |
Philipp Maier | 3d48ec0 | 2017-03-29 17:37:55 +0200 | [diff] [blame] | 91 | struct msgb *gsm0808_create_paging(const char *imsi, const uint32_t *tmsi, |
| 92 | const struct gsm0808_cell_id_list *cil, |
Stefan Sperling | 11a4d9d | 2018-02-15 18:28:04 +0100 | [diff] [blame] | 93 | const uint8_t *chan_needed) |
| 94 | OSMO_DEPRECATED("use gsm0808_create_paging2 instead"); |
Max | 45f89c9 | 2018-12-19 19:35:26 +0100 | [diff] [blame] | 95 | struct msgb *gsm0808_create_lcls_conn_ctrl(enum gsm0808_lcls_config config, |
| 96 | enum gsm0808_lcls_control control); |
Harald Welte | 64e807c | 2018-05-29 21:00:56 +0200 | [diff] [blame] | 97 | struct msgb *gsm0808_create_lcls_conn_ctrl_ack(enum gsm0808_lcls_status status); |
| 98 | struct msgb *gsm0808_create_lcls_notification(enum gsm0808_lcls_status status, bool break_req); |
| 99 | |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 100 | |
Neels Hofmeyr | 70aba3f | 2018-03-13 03:40:53 +0100 | [diff] [blame] | 101 | /*! 3GPP TS 48.008 §3.2.2.5.8 Old BSS to New BSS information */ |
| 102 | struct gsm0808_old_bss_to_new_bss_info { |
| 103 | bool extra_information_present; |
| 104 | struct { |
| 105 | bool prec; |
| 106 | bool lcs; |
| 107 | bool ue_prob; |
| 108 | } extra_information; |
| 109 | |
| 110 | bool current_channel_type_2_present; |
| 111 | struct { |
| 112 | uint8_t mode; |
| 113 | uint8_t field; |
| 114 | } current_channel_type_2; |
| 115 | |
| 116 | /* more items are defined in the spec and may be added later */ |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 117 | bool more_items; /*< always set this to false */ |
Neels Hofmeyr | 70aba3f | 2018-03-13 03:40:53 +0100 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | /*! 3GPP TS 48.008 §3.2.1.9 HANDOVER REQUIRED */ |
| 121 | struct gsm0808_handover_required { |
| 122 | uint16_t cause; |
| 123 | struct gsm0808_cell_id_list2 cil; |
| 124 | |
| 125 | bool current_channel_type_1_present; |
| 126 | uint8_t current_channel_type_1; |
| 127 | |
| 128 | bool speech_version_used_present; |
| 129 | uint8_t speech_version_used; |
| 130 | |
| 131 | bool old_bss_to_new_bss_info_present; |
| 132 | struct gsm0808_old_bss_to_new_bss_info old_bss_to_new_bss_info; |
| 133 | |
| 134 | /* more items are defined in the spec and may be added later */ |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 135 | bool more_items; /*< always set this to false */ |
Neels Hofmeyr | 70aba3f | 2018-03-13 03:40:53 +0100 | [diff] [blame] | 136 | }; |
| 137 | struct msgb *gsm0808_create_handover_required(const struct gsm0808_handover_required *params); |
| 138 | |
Neels Hofmeyr | b662b36 | 2018-04-16 22:31:15 +0200 | [diff] [blame] | 139 | struct msgb *gsm0808_create_handover_request_ack(const uint8_t *l3_info, uint8_t l3_info_len, |
| 140 | uint8_t chosen_channel, uint8_t chosen_encr_alg, |
| 141 | uint8_t chosen_speech_version); |
| 142 | |
Neels Hofmeyr | 60f3153 | 2018-04-16 22:42:09 +0200 | [diff] [blame] | 143 | struct msgb *gsm0808_create_handover_detect(); |
| 144 | |
| 145 | struct gsm0808_handover_complete { |
| 146 | bool rr_cause_present; |
| 147 | uint8_t rr_cause; |
| 148 | |
| 149 | bool speech_codec_chosen_present; |
| 150 | struct gsm0808_speech_codec speech_codec_chosen; |
| 151 | |
| 152 | struct gsm0808_speech_codec_list codec_list_bss_supported; /*< omit when .len == 0 */ |
| 153 | |
| 154 | bool chosen_encr_alg_present; |
| 155 | uint8_t chosen_encr_alg; |
| 156 | |
| 157 | bool chosen_channel_present; |
| 158 | uint8_t chosen_channel; |
| 159 | |
| 160 | bool lcls_bss_status_present; |
| 161 | enum gsm0808_lcls_status lcls_bss_status; |
| 162 | |
| 163 | /* more items are defined in the spec and may be added later */ |
| 164 | bool more_items; /*< always set this to false */ |
| 165 | }; |
| 166 | struct msgb *gsm0808_create_handover_complete(const struct gsm0808_handover_complete *params); |
| 167 | |
| 168 | struct gsm0808_handover_failure { |
| 169 | uint16_t cause; |
| 170 | |
| 171 | bool rr_cause_present; |
| 172 | uint8_t rr_cause; |
| 173 | |
| 174 | struct gsm0808_speech_codec_list codec_list_bss_supported; /*< omit when .len == 0 */ |
| 175 | |
| 176 | /* more items are defined in the spec and may be added later */ |
| 177 | bool more_items; /*< always set this to false */ |
| 178 | }; |
| 179 | struct msgb *gsm0808_create_handover_failure(const struct gsm0808_handover_failure *params); |
| 180 | |
Philipp Maier | 225bdf4 | 2018-10-30 14:56:59 +0100 | [diff] [blame] | 181 | struct gsm0808_handover_performed { |
| 182 | uint16_t cause; |
| 183 | struct gsm0808_cell_id cell_id; |
| 184 | |
| 185 | bool chosen_channel_present; |
| 186 | uint8_t chosen_channel; |
| 187 | |
| 188 | bool chosen_encr_alg_present; |
| 189 | uint8_t chosen_encr_alg; |
| 190 | |
| 191 | bool speech_version_chosen_present; |
| 192 | uint8_t speech_version_chosen; |
| 193 | |
| 194 | bool speech_codec_chosen_present; |
| 195 | struct gsm0808_speech_codec speech_codec_chosen; |
| 196 | |
| 197 | bool lcls_bss_status_present; |
| 198 | enum gsm0808_lcls_status lcls_bss_status; |
| 199 | |
| 200 | /* more items are defined in the spec and may be added later */ |
| 201 | bool more_items; /*< always set this to false */ |
| 202 | }; |
| 203 | struct msgb *gsm0808_create_handover_performed(const struct gsm0808_handover_performed *params); |
| 204 | |
Holger Hans Peter Freyther | c25c668 | 2010-11-04 12:26:06 +0100 | [diff] [blame] | 205 | struct msgb *gsm0808_create_dtap(struct msgb *msg, uint8_t link_id); |
Holger Hans Peter Freyther | 9a3dec0 | 2010-05-16 08:15:40 +0800 | [diff] [blame] | 206 | void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id); |
| 207 | |
Harald Welte | f4d45ab | 2011-07-16 12:13:00 +0200 | [diff] [blame] | 208 | const struct tlv_definition *gsm0808_att_tlvdef(void); |
Holger Hans Peter Freyther | 280cd51 | 2010-04-15 10:10:39 +0200 | [diff] [blame] | 209 | |
Max | c0d1de3 | 2018-11-07 15:24:11 +0100 | [diff] [blame] | 210 | /*! Parse BSSAP TLV structure using \ref tlv_parse */ |
| 211 | #define osmo_bssap_tlv_parse(dec, buf, len) tlv_parse(dec, gsm0808_att_tlvdef(), buf, len, 0, 0) |
| 212 | |
Harald Welte | 9b837e6 | 2011-07-11 17:43:19 +0200 | [diff] [blame] | 213 | const char *gsm0808_bssmap_name(uint8_t msg_type); |
| 214 | const char *gsm0808_bssap_name(uint8_t msg_type); |
Max | aa93463 | 2018-11-07 13:16:54 +0100 | [diff] [blame] | 215 | const char *gsm0808_cause_name(enum gsm0808_cause cause); |
| 216 | const char *gsm0808_cause_class_name(enum gsm0808_cause_class class); |
Harald Welte | 37b6165 | 2017-10-16 18:46:03 +0200 | [diff] [blame] | 217 | |
Harald Welte | ebd362d | 2018-06-02 14:11:19 +0200 | [diff] [blame] | 218 | extern const struct value_string gsm0808_lcls_config_names[]; |
| 219 | extern const struct value_string gsm0808_lcls_control_names[]; |
| 220 | extern const struct value_string gsm0808_lcls_status_names[]; |
| 221 | |
| 222 | static inline const char *gsm0808_lcls_config_name(uint8_t val) { |
| 223 | return get_value_string(gsm0808_lcls_config_names, val); |
| 224 | } |
| 225 | static inline const char *gsm0808_lcls_control_name(uint8_t val) { |
| 226 | return get_value_string(gsm0808_lcls_control_names, val); |
| 227 | } |
| 228 | static inline const char *gsm0808_lcls_status_name(uint8_t val) { |
| 229 | return get_value_string(gsm0808_lcls_status_names, val); |
| 230 | } |
| 231 | |
Harald Welte | 37b6165 | 2017-10-16 18:46:03 +0200 | [diff] [blame] | 232 | /*! @} */ |