blob: 20137daf84a3c71f1654ecb7f2a53c80065bbbc2 [file] [log] [blame]
Harald Welte37b61652017-10-16 18:46:03 +02001/*! \defgroup gsm0808 GSM 08.08 / 3GPP TS 48.008 A Interface
2 * @{
3 * \file gsm0808.h */
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02004/*
5 * (C) 2009,2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +02006 * (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 Munaut12ba7782014-06-16 10:13:40 +020024#pragma once
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020025
26#include "tlv.h"
Philipp Maierfa896ab2017-03-27 16:55:32 +020027#include <osmocom/gsm/protocol/gsm_08_08.h>
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +010028#include <osmocom/gsm/gsm0808_utils.h>
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010029#include <osmocom/gsm/gsm23003.h>
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +010030#include <osmocom/gsm/protocol/gsm_23_003.h>
Harald Welteebd362d2018-06-02 14:11:19 +020031#include <osmocom/core/utils.h>
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010032
Neels Hofmeyr99273c72019-02-22 04:48:56 +010033#define BSSMAP_MSG_SIZE 1024
34#define BSSMAP_MSG_HEADROOM 512
Maxf69aa9c2018-11-29 23:32:06 +010035
Harald Welte20725b92017-05-15 12:50:04 +020036struct sockaddr_storage;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020037
38struct msgb;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +010039struct gsm0808_cell_id_list2;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020040
Philipp Maierfa896ab2017-03-27 16:55:32 +020041struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc,
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +010042 uint16_t cc, int lac, uint16_t _ci)
43 OSMO_DEPRECATED("Use gsm0808_create_layer3_2() instead, to not lose leading zeros in the MNC");
Philipp Maierfa896ab2017-03-27 16:55:32 +020044struct msgb *gsm0808_create_layer3_aoip(const struct msgb *msg_l3, uint16_t nc,
45 uint16_t cc, int lac, uint16_t _ci,
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +010046 const struct gsm0808_speech_codec_list *scl)
47 OSMO_DEPRECATED("Use gsm0808_create_layer3_2() instead, to not lose leading zeros in the MNC");
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010048struct msgb *gsm0808_create_layer3_2(const struct msgb *msg_l3, const struct osmo_cell_global_id *cell,
49 const struct gsm0808_speech_codec_list *scl);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020050struct msgb *gsm0808_create_reset(void);
Harald Weltea62fe312013-06-19 15:14:37 +020051struct msgb *gsm0808_create_reset_ack(void);
Philipp Maier1a146c82018-10-30 09:36:49 +010052struct msgb *gsm0808_create_clear_command(uint8_t cause);
Philipp Maier74c4c4e2019-02-04 16:42:28 +010053struct msgb *gsm0808_create_clear_command2(uint8_t cause, bool csfb_ind);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020054struct msgb *gsm0808_create_clear_complete(void);
Philipp Maierb478dd32017-03-29 15:50:05 +020055struct msgb *gsm0808_create_cipher(const struct gsm0808_encrypt_info *ei,
56 const uint8_t *cipher_response_mode);
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +020057struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id);
Maxaa934632018-11-07 13:16:54 +010058struct msgb *gsm0808_create_cipher_reject(enum gsm0808_cause cause);
Maxed651d22018-11-07 15:25:05 +010059struct msgb *gsm0808_create_cipher_reject_ext(enum gsm0808_cause_class class, uint8_t ext);
Neels Hofmeyr2c79d552018-09-13 05:36:32 +020060struct msgb *gsm0808_create_classmark_request();
Harald Welte07b625d2012-01-23 10:02:58 +010061struct msgb *gsm0808_create_classmark_update(const uint8_t *cm2, uint8_t cm2_len,
62 const uint8_t *cm3, uint8_t cm3_len);
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +070063struct msgb *gsm0808_create_sapi_reject_cause(uint8_t link_id, uint16_t cause);
64struct msgb *gsm0808_create_sapi_reject(uint8_t link_id)
65 OSMO_DEPRECATED("Use gsm0808_create_sapi_reject_cause() instead");
Philipp Maierc6144a22017-03-29 17:53:43 +020066struct msgb *gsm0808_create_ass(const struct gsm0808_channel_type *ct,
67 const uint16_t *cic,
68 const struct sockaddr_storage *ss,
69 const struct gsm0808_speech_codec_list *scl,
70 const uint32_t *ci);
Max52074322018-11-30 10:44:07 +010071struct msgb *gsm0808_create_ass2(const struct gsm0808_channel_type *ct,
72 const uint16_t *cic,
73 const struct sockaddr_storage *ss,
74 const struct gsm0808_speech_codec_list *scl,
75 const uint32_t *ci,
76 const uint8_t *kc, const struct osmo_lcls *lcls);
Philipp Maierfa896ab2017-03-27 16:55:32 +020077struct msgb *gsm0808_create_ass_compl(uint8_t rr_cause, uint8_t chosen_channel,
78 uint8_t encr_alg_id, uint8_t speech_mode,
79 const struct sockaddr_storage *ss,
80 const struct gsm0808_speech_codec *sc,
81 const struct gsm0808_speech_codec_list
82 *scl);
Max414c8f52019-01-08 14:44:24 +010083struct msgb *gsm0808_create_ass_compl2(uint8_t rr_cause, uint8_t chosen_channel,
84 uint8_t encr_alg_id, uint8_t speech_mode,
85 const struct sockaddr_storage *ss,
86 const struct gsm0808_speech_codec *sc,
87 const struct gsm0808_speech_codec_list *scl,
88 enum gsm0808_lcls_status lcls_bss_status);
Holger Hans Peter Freytherb60a4b32010-07-23 18:35:59 +080089struct msgb *gsm0808_create_assignment_completed(uint8_t rr_cause,
Philipp Maierfa896ab2017-03-27 16:55:32 +020090 uint8_t chosen_channel,
91 uint8_t encr_alg_id,
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +020092 uint8_t speech_mode);
Philipp Maierfa896ab2017-03-27 16:55:32 +020093struct msgb *gsm0808_create_ass_fail(uint8_t cause, const uint8_t *rr_cause,
94 const struct gsm0808_speech_codec_list
95 *scl);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020096struct msgb *gsm0808_create_assignment_failure(uint8_t cause, uint8_t *rr_cause);
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +010097struct msgb *gsm0808_create_clear_rqst(uint8_t cause);
Stefan Sperling11a4d9d2018-02-15 18:28:04 +010098struct msgb *gsm0808_create_paging2(const char *imsi, const uint32_t *tmsi,
99 const struct gsm0808_cell_id_list2 *cil,
100 const uint8_t *chan_needed);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200101struct msgb *gsm0808_create_paging(const char *imsi, const uint32_t *tmsi,
102 const struct gsm0808_cell_id_list *cil,
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100103 const uint8_t *chan_needed)
104 OSMO_DEPRECATED("use gsm0808_create_paging2 instead");
Max45f89c92018-12-19 19:35:26 +0100105struct msgb *gsm0808_create_lcls_conn_ctrl(enum gsm0808_lcls_config config,
106 enum gsm0808_lcls_control control);
Harald Welte64e807c2018-05-29 21:00:56 +0200107struct msgb *gsm0808_create_lcls_conn_ctrl_ack(enum gsm0808_lcls_status status);
108struct msgb *gsm0808_create_lcls_notification(enum gsm0808_lcls_status status, bool break_req);
Harald Welte1bd726a2020-06-21 22:04:52 +0200109struct msgb *gsm0808_create_common_id(const char *imsi,
110 const struct osmo_plmn_id *selected_plmn_id,
111 const struct osmo_plmn_id *last_used_eutran_plnm_id);
Harald Welte64e807c2018-05-29 21:00:56 +0200112
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200113
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100114/*! 3GPP TS 48.008 ยง3.2.2.5.8 Old BSS to New BSS information */
115struct gsm0808_old_bss_to_new_bss_info {
116 bool extra_information_present;
117 struct {
118 bool prec;
119 bool lcs;
120 bool ue_prob;
121 } extra_information;
122
123 bool current_channel_type_2_present;
124 struct {
125 uint8_t mode;
126 uint8_t field;
127 } current_channel_type_2;
128
129 /* more items are defined in the spec and may be added later */
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200130 bool more_items; /*< always set this to false */
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100131};
132
133/*! 3GPP TS 48.008 ยง3.2.1.9 HANDOVER REQUIRED */
134struct gsm0808_handover_required {
135 uint16_t cause;
136 struct gsm0808_cell_id_list2 cil;
137
138 bool current_channel_type_1_present;
139 uint8_t current_channel_type_1;
140
141 bool speech_version_used_present;
Neels Hofmeyr302aafc2019-04-10 19:23:45 +0200142 enum gsm0808_permitted_speech speech_version_used;
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100143
144 bool old_bss_to_new_bss_info_present;
145 struct gsm0808_old_bss_to_new_bss_info old_bss_to_new_bss_info;
146
147 /* more items are defined in the spec and may be added later */
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200148 bool more_items; /*< always set this to false */
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100149};
150struct msgb *gsm0808_create_handover_required(const struct gsm0808_handover_required *params);
151
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100152/*! 3GPP TS 48.008 ยง3.2.1.37 HANDOVER REQUIRED REJECT */
153struct gsm0808_handover_required_reject {
154 uint16_t cause;
155
156 /* more items are defined in the spec and may be added later */
157 bool more_items; /*< always set this to false */
158};
159struct msgb *gsm0808_create_handover_required_reject(const struct gsm0808_handover_required_reject *params);
160
161/*! 3GPP TS 48.008 ยง3.2.1.8 HANDOVER REQUEST */
162struct gsm0808_handover_request {
163 struct gsm0808_channel_type channel_type;
164 struct gsm0808_encrypt_info encryption_information;
165 struct osmo_gsm48_classmark classmark_information;
166 struct gsm0808_cell_id cell_identifier_serving;
167 struct gsm0808_cell_id cell_identifier_target;
168 enum gsm0808_cause cause;
169
170 bool current_channel_type_1_present;
171 uint8_t current_channel_type_1;
172
173 enum gsm0808_permitted_speech speech_version_used;
174
175 uint8_t chosen_encryption_algorithm_serving;
176
177 /*! Pass either old_bss_to_new_bss_info or old_bss_to_new_bss_info_raw. */
178 bool old_bss_to_new_bss_info_present;
179 struct gsm0808_old_bss_to_new_bss_info old_bss_to_new_bss_info;
180 /*! To feed the Old BSS to New BSS Information IE unchanged from the Handover Required message without having to
181 * decode it. Pass either old_bss_to_new_bss_info or old_bss_to_new_bss_info_raw. Omit the TL part. */
182 const uint8_t *old_bss_to_new_bss_info_raw;
183 uint8_t old_bss_to_new_bss_info_raw_len;
184
185 const char *imsi;
186
187 const struct sockaddr_storage *aoip_transport_layer;
188
189 const struct gsm0808_speech_codec_list *codec_list_msc_preferred;
190
191 bool call_id_present;
192 uint32_t call_id;
193
194 const uint8_t *global_call_reference;
195 uint8_t global_call_reference_len;
196
197 /* more items are defined in the spec and may be added later */
198 bool more_items; /*!< always set this to false */
199};
200struct msgb *gsm0808_create_handover_request(const struct gsm0808_handover_request *params);
201
Harald Welteaa98c482019-05-06 10:31:35 +0200202struct msgb *gsm0808_create_handover_request_ack(const uint8_t *l3_info, uint8_t l3_info_len,
203 uint8_t chosen_channel, uint8_t chosen_encr_alg,
204 uint8_t chosen_speech_version);
205
Neels Hofmeyr73b943e2019-03-14 04:10:25 +0100206struct gsm0808_handover_request_ack {
207 const uint8_t *l3_info;
208 uint8_t l3_info_len;
209
210 bool chosen_channel_present;
211 uint8_t chosen_channel;
212
213 /*! For A5/N set chosen_encr_alg = N+1, e.g. chosen_encr_alg = 1 means A5/0 (no encryption), 2 means A5/1, 4
214 * means A5/3. Set chosen_encr_alg = 0 to omit the Chosen Encryption Algorithm IE. */
215 uint8_t chosen_encr_alg;
216
217 /* chosen_speech_version == 0 omits the IE */
218 enum gsm0808_permitted_speech chosen_speech_version;
219
220 bool speech_codec_chosen_present;
221 struct gsm0808_speech_codec speech_codec_chosen;
222
223 const struct sockaddr_storage *aoip_transport_layer;
224
225 /* more items are defined in the spec and may be added later */
226 bool more_items; /*!< always set this to false */
227};
228struct msgb *gsm0808_create_handover_request_ack2(const struct gsm0808_handover_request_ack *params);
Neels Hofmeyrb662b362018-04-16 22:31:15 +0200229
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100230struct gsm0808_handover_command {
231 const uint8_t *l3_info;
232 uint8_t l3_info_len;
233
234 struct gsm0808_cell_id cell_identifier;
235
236 const uint8_t *new_bss_to_old_bss_info_raw;
237 size_t new_bss_to_old_bss_info_raw_len;
238
239 /* more items are defined in the spec and may be added later */
240 bool more_items; /*!< always set this to false */
241};
242struct msgb *gsm0808_create_handover_command(const struct gsm0808_handover_command *params);
243
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200244struct msgb *gsm0808_create_handover_detect();
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100245struct msgb *gsm0808_create_handover_succeeded();
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200246
247struct gsm0808_handover_complete {
248 bool rr_cause_present;
249 uint8_t rr_cause;
250
251 bool speech_codec_chosen_present;
252 struct gsm0808_speech_codec speech_codec_chosen;
253
254 struct gsm0808_speech_codec_list codec_list_bss_supported; /*< omit when .len == 0 */
255
256 bool chosen_encr_alg_present;
257 uint8_t chosen_encr_alg;
258
259 bool chosen_channel_present;
260 uint8_t chosen_channel;
261
262 bool lcls_bss_status_present;
263 enum gsm0808_lcls_status lcls_bss_status;
264
265 /* more items are defined in the spec and may be added later */
266 bool more_items; /*< always set this to false */
267};
268struct msgb *gsm0808_create_handover_complete(const struct gsm0808_handover_complete *params);
269
270struct gsm0808_handover_failure {
271 uint16_t cause;
272
273 bool rr_cause_present;
274 uint8_t rr_cause;
275
276 struct gsm0808_speech_codec_list codec_list_bss_supported; /*< omit when .len == 0 */
277
278 /* more items are defined in the spec and may be added later */
279 bool more_items; /*< always set this to false */
280};
281struct msgb *gsm0808_create_handover_failure(const struct gsm0808_handover_failure *params);
282
Philipp Maier225bdf42018-10-30 14:56:59 +0100283struct gsm0808_handover_performed {
284 uint16_t cause;
285 struct gsm0808_cell_id cell_id;
286
287 bool chosen_channel_present;
288 uint8_t chosen_channel;
289
290 bool chosen_encr_alg_present;
291 uint8_t chosen_encr_alg;
292
293 bool speech_version_chosen_present;
Neels Hofmeyr302aafc2019-04-10 19:23:45 +0200294 enum gsm0808_permitted_speech speech_version_chosen;
Philipp Maier225bdf42018-10-30 14:56:59 +0100295
296 bool speech_codec_chosen_present;
297 struct gsm0808_speech_codec speech_codec_chosen;
298
299 bool lcls_bss_status_present;
300 enum gsm0808_lcls_status lcls_bss_status;
301
302 /* more items are defined in the spec and may be added later */
303 bool more_items; /*< always set this to false */
304};
305struct msgb *gsm0808_create_handover_performed(const struct gsm0808_handover_performed *params);
306
Holger Hans Peter Freytherc25c6682010-11-04 12:26:06 +0100307struct msgb *gsm0808_create_dtap(struct msgb *msg, uint8_t link_id);
Holger Hans Peter Freyther9a3dec02010-05-16 08:15:40 +0800308void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id);
309
Harald Weltef4d45ab2011-07-16 12:13:00 +0200310const struct tlv_definition *gsm0808_att_tlvdef(void);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200311
Maxc0d1de32018-11-07 15:24:11 +0100312/*! Parse BSSAP TLV structure using \ref tlv_parse */
313#define osmo_bssap_tlv_parse(dec, buf, len) tlv_parse(dec, gsm0808_att_tlvdef(), buf, len, 0, 0)
Neels Hofmeyrd7913272019-04-03 18:07:27 +0200314/*! Parse BSSAP TLV structure using \ref tlv_parse2 */
315#define osmo_bssap_tlv_parse2(dec, dec_multiples, buf, len) \
316 tlv_parse2(dec, dec_multiples, gsm0808_att_tlvdef(), buf, len, 0, 0)
Maxc0d1de32018-11-07 15:24:11 +0100317
Harald Welte9b837e62011-07-11 17:43:19 +0200318const char *gsm0808_bssmap_name(uint8_t msg_type);
319const char *gsm0808_bssap_name(uint8_t msg_type);
Maxaa934632018-11-07 13:16:54 +0100320const char *gsm0808_cause_name(enum gsm0808_cause cause);
321const char *gsm0808_cause_class_name(enum gsm0808_cause_class class);
Harald Welte37b61652017-10-16 18:46:03 +0200322
Alexander Chemerisfdfe25b2020-05-12 23:21:56 +0300323/*! Parse Cause TLV 3GPP TS 08.08 ยง3.2.2.5
324 * \returns Cause value */
325enum gsm0808_cause gsm0808_get_cause(const struct tlv_parsed *tp);
326
Alexander Chemeris22630e62020-05-13 00:44:04 +0300327const char *gsm0808_diagnostics_octet_location_str(uint8_t pointer);
328const char *gsm0808_diagnostics_bit_location_str(uint8_t bit_pointer);
329
Harald Welteebd362d2018-06-02 14:11:19 +0200330extern const struct value_string gsm0808_lcls_config_names[];
331extern const struct value_string gsm0808_lcls_control_names[];
332extern const struct value_string gsm0808_lcls_status_names[];
333
Maxe118ed22018-12-19 17:05:37 +0100334static inline const char *gsm0808_lcls_config_name(enum gsm0808_lcls_config val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200335 return get_value_string(gsm0808_lcls_config_names, val);
336}
Maxe118ed22018-12-19 17:05:37 +0100337static inline const char *gsm0808_lcls_control_name(enum gsm0808_lcls_control val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200338 return get_value_string(gsm0808_lcls_control_names, val);
339}
Maxe118ed22018-12-19 17:05:37 +0100340static inline const char *gsm0808_lcls_status_name(enum gsm0808_lcls_status val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200341 return get_value_string(gsm0808_lcls_status_names, val);
342}
343
Harald Welte37b61652017-10-16 18:46:03 +0200344/*! @} */