blob: 3e394601b507e4d8d206ffd6dfbd6d05ab28cfd9 [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);
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +020057
58struct gsm0808_cipher_mode_command {
59 struct gsm0808_encrypt_info ei;
60
61 /*! 3GPP TS 48.008 3.2.2.34 Cipher Response Mode, optional IE */
62 bool cipher_response_mode_present;
63 /*! 3GPP TS 48.008 3.2.2.34 Cipher Response Mode:
64 * 0 - IMEISV must not be included by the Mobile Station;
65 * 1 - IMEISV must be included by the Mobile Station.
66 */
67 uint8_t cipher_response_mode;
68
69 bool kc128_present;
70 uint8_t kc128[16];
71
72 /* more items are defined in the spec and may be added later */
73 bool more_items; /*< always set this to false */
74};
75struct msgb *gsm0808_create_cipher2(const struct gsm0808_cipher_mode_command *cmc);
76
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +020077struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id);
Maxaa934632018-11-07 13:16:54 +010078struct msgb *gsm0808_create_cipher_reject(enum gsm0808_cause cause);
Maxed651d22018-11-07 15:25:05 +010079struct msgb *gsm0808_create_cipher_reject_ext(enum gsm0808_cause_class class, uint8_t ext);
Neels Hofmeyr2c79d552018-09-13 05:36:32 +020080struct msgb *gsm0808_create_classmark_request();
Harald Welte07b625d2012-01-23 10:02:58 +010081struct msgb *gsm0808_create_classmark_update(const uint8_t *cm2, uint8_t cm2_len,
82 const uint8_t *cm3, uint8_t cm3_len);
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +070083struct msgb *gsm0808_create_sapi_reject_cause(uint8_t link_id, uint16_t cause);
84struct msgb *gsm0808_create_sapi_reject(uint8_t link_id)
85 OSMO_DEPRECATED("Use gsm0808_create_sapi_reject_cause() instead");
Philipp Maierc6144a22017-03-29 17:53:43 +020086struct msgb *gsm0808_create_ass(const struct gsm0808_channel_type *ct,
87 const uint16_t *cic,
88 const struct sockaddr_storage *ss,
89 const struct gsm0808_speech_codec_list *scl,
90 const uint32_t *ci);
Max52074322018-11-30 10:44:07 +010091struct msgb *gsm0808_create_ass2(const struct gsm0808_channel_type *ct,
92 const uint16_t *cic,
93 const struct sockaddr_storage *ss,
94 const struct gsm0808_speech_codec_list *scl,
95 const uint32_t *ci,
96 const uint8_t *kc, const struct osmo_lcls *lcls);
Philipp Maierfa896ab2017-03-27 16:55:32 +020097struct msgb *gsm0808_create_ass_compl(uint8_t rr_cause, uint8_t chosen_channel,
98 uint8_t encr_alg_id, uint8_t speech_mode,
99 const struct sockaddr_storage *ss,
100 const struct gsm0808_speech_codec *sc,
101 const struct gsm0808_speech_codec_list
102 *scl);
Max414c8f52019-01-08 14:44:24 +0100103struct msgb *gsm0808_create_ass_compl2(uint8_t rr_cause, uint8_t chosen_channel,
104 uint8_t encr_alg_id, uint8_t speech_mode,
105 const struct sockaddr_storage *ss,
106 const struct gsm0808_speech_codec *sc,
107 const struct gsm0808_speech_codec_list *scl,
108 enum gsm0808_lcls_status lcls_bss_status);
Holger Hans Peter Freytherb60a4b32010-07-23 18:35:59 +0800109struct msgb *gsm0808_create_assignment_completed(uint8_t rr_cause,
Philipp Maierfa896ab2017-03-27 16:55:32 +0200110 uint8_t chosen_channel,
111 uint8_t encr_alg_id,
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200112 uint8_t speech_mode);
Philipp Maierfa896ab2017-03-27 16:55:32 +0200113struct msgb *gsm0808_create_ass_fail(uint8_t cause, const uint8_t *rr_cause,
114 const struct gsm0808_speech_codec_list
115 *scl);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200116struct msgb *gsm0808_create_assignment_failure(uint8_t cause, uint8_t *rr_cause);
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +0100117struct msgb *gsm0808_create_clear_rqst(uint8_t cause);
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100118struct msgb *gsm0808_create_paging2(const char *imsi, const uint32_t *tmsi,
119 const struct gsm0808_cell_id_list2 *cil,
120 const uint8_t *chan_needed);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200121struct msgb *gsm0808_create_paging(const char *imsi, const uint32_t *tmsi,
122 const struct gsm0808_cell_id_list *cil,
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100123 const uint8_t *chan_needed)
124 OSMO_DEPRECATED("use gsm0808_create_paging2 instead");
Max45f89c92018-12-19 19:35:26 +0100125struct msgb *gsm0808_create_lcls_conn_ctrl(enum gsm0808_lcls_config config,
126 enum gsm0808_lcls_control control);
Harald Welte64e807c2018-05-29 21:00:56 +0200127struct msgb *gsm0808_create_lcls_conn_ctrl_ack(enum gsm0808_lcls_status status);
128struct msgb *gsm0808_create_lcls_notification(enum gsm0808_lcls_status status, bool break_req);
Harald Welte1bd726a2020-06-21 22:04:52 +0200129struct msgb *gsm0808_create_common_id(const char *imsi,
130 const struct osmo_plmn_id *selected_plmn_id,
131 const struct osmo_plmn_id *last_used_eutran_plnm_id);
Harald Welte64e807c2018-05-29 21:00:56 +0200132
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200133
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100134/*! 3GPP TS 48.008 ยง3.2.2.5.8 Old BSS to New BSS information */
135struct gsm0808_old_bss_to_new_bss_info {
136 bool extra_information_present;
137 struct {
138 bool prec;
139 bool lcs;
140 bool ue_prob;
141 } extra_information;
142
143 bool current_channel_type_2_present;
144 struct {
145 uint8_t mode;
146 uint8_t field;
147 } current_channel_type_2;
148
Pau Espin Pedrol1b625cb2021-04-14 21:27:31 +0200149 bool last_eutran_plmn_id_present;
150 struct osmo_plmn_id last_eutran_plmn_id;
151
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100152 /* more items are defined in the spec and may be added later */
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200153 bool more_items; /*< always set this to false */
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100154};
155
156/*! 3GPP TS 48.008 ยง3.2.1.9 HANDOVER REQUIRED */
157struct gsm0808_handover_required {
158 uint16_t cause;
159 struct gsm0808_cell_id_list2 cil;
160
161 bool current_channel_type_1_present;
162 uint8_t current_channel_type_1;
163
164 bool speech_version_used_present;
Neels Hofmeyr302aafc2019-04-10 19:23:45 +0200165 enum gsm0808_permitted_speech speech_version_used;
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100166
167 bool old_bss_to_new_bss_info_present;
168 struct gsm0808_old_bss_to_new_bss_info old_bss_to_new_bss_info;
169
170 /* more items are defined in the spec and may be added later */
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200171 bool more_items; /*< always set this to false */
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100172};
173struct msgb *gsm0808_create_handover_required(const struct gsm0808_handover_required *params);
174
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100175/*! 3GPP TS 48.008 ยง3.2.1.37 HANDOVER REQUIRED REJECT */
176struct gsm0808_handover_required_reject {
177 uint16_t cause;
178
179 /* more items are defined in the spec and may be added later */
180 bool more_items; /*< always set this to false */
181};
182struct msgb *gsm0808_create_handover_required_reject(const struct gsm0808_handover_required_reject *params);
183
184/*! 3GPP TS 48.008 ยง3.2.1.8 HANDOVER REQUEST */
185struct gsm0808_handover_request {
186 struct gsm0808_channel_type channel_type;
187 struct gsm0808_encrypt_info encryption_information;
188 struct osmo_gsm48_classmark classmark_information;
189 struct gsm0808_cell_id cell_identifier_serving;
190 struct gsm0808_cell_id cell_identifier_target;
191 enum gsm0808_cause cause;
192
193 bool current_channel_type_1_present;
194 uint8_t current_channel_type_1;
195
196 enum gsm0808_permitted_speech speech_version_used;
197
198 uint8_t chosen_encryption_algorithm_serving;
199
200 /*! Pass either old_bss_to_new_bss_info or old_bss_to_new_bss_info_raw. */
201 bool old_bss_to_new_bss_info_present;
202 struct gsm0808_old_bss_to_new_bss_info old_bss_to_new_bss_info;
203 /*! To feed the Old BSS to New BSS Information IE unchanged from the Handover Required message without having to
204 * decode it. Pass either old_bss_to_new_bss_info or old_bss_to_new_bss_info_raw. Omit the TL part. */
205 const uint8_t *old_bss_to_new_bss_info_raw;
206 uint8_t old_bss_to_new_bss_info_raw_len;
207
208 const char *imsi;
209
210 const struct sockaddr_storage *aoip_transport_layer;
211
212 const struct gsm0808_speech_codec_list *codec_list_msc_preferred;
213
214 bool call_id_present;
215 uint32_t call_id;
216
217 const uint8_t *global_call_reference;
218 uint8_t global_call_reference_len;
219
220 /* more items are defined in the spec and may be added later */
221 bool more_items; /*!< always set this to false */
222};
223struct msgb *gsm0808_create_handover_request(const struct gsm0808_handover_request *params);
224
Harald Welteaa98c482019-05-06 10:31:35 +0200225struct msgb *gsm0808_create_handover_request_ack(const uint8_t *l3_info, uint8_t l3_info_len,
226 uint8_t chosen_channel, uint8_t chosen_encr_alg,
227 uint8_t chosen_speech_version);
228
Neels Hofmeyr73b943e2019-03-14 04:10:25 +0100229struct gsm0808_handover_request_ack {
230 const uint8_t *l3_info;
231 uint8_t l3_info_len;
232
233 bool chosen_channel_present;
234 uint8_t chosen_channel;
235
236 /*! 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
237 * means A5/3. Set chosen_encr_alg = 0 to omit the Chosen Encryption Algorithm IE. */
238 uint8_t chosen_encr_alg;
239
240 /* chosen_speech_version == 0 omits the IE */
241 enum gsm0808_permitted_speech chosen_speech_version;
242
243 bool speech_codec_chosen_present;
244 struct gsm0808_speech_codec speech_codec_chosen;
245
246 const struct sockaddr_storage *aoip_transport_layer;
247
248 /* more items are defined in the spec and may be added later */
249 bool more_items; /*!< always set this to false */
250};
251struct msgb *gsm0808_create_handover_request_ack2(const struct gsm0808_handover_request_ack *params);
Neels Hofmeyrb662b362018-04-16 22:31:15 +0200252
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100253struct gsm0808_handover_command {
254 const uint8_t *l3_info;
255 uint8_t l3_info_len;
256
257 struct gsm0808_cell_id cell_identifier;
258
259 const uint8_t *new_bss_to_old_bss_info_raw;
260 size_t new_bss_to_old_bss_info_raw_len;
261
262 /* more items are defined in the spec and may be added later */
263 bool more_items; /*!< always set this to false */
264};
265struct msgb *gsm0808_create_handover_command(const struct gsm0808_handover_command *params);
266
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200267struct msgb *gsm0808_create_handover_detect();
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100268struct msgb *gsm0808_create_handover_succeeded();
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200269
270struct gsm0808_handover_complete {
271 bool rr_cause_present;
272 uint8_t rr_cause;
273
274 bool speech_codec_chosen_present;
275 struct gsm0808_speech_codec speech_codec_chosen;
276
277 struct gsm0808_speech_codec_list codec_list_bss_supported; /*< omit when .len == 0 */
278
279 bool chosen_encr_alg_present;
280 uint8_t chosen_encr_alg;
Pau Espin Pedrol4da98cc2021-04-14 21:28:01 +0200281
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200282 bool chosen_channel_present;
283 uint8_t chosen_channel;
284
285 bool lcls_bss_status_present;
286 enum gsm0808_lcls_status lcls_bss_status;
287
288 /* more items are defined in the spec and may be added later */
289 bool more_items; /*< always set this to false */
290};
291struct msgb *gsm0808_create_handover_complete(const struct gsm0808_handover_complete *params);
292
293struct gsm0808_handover_failure {
294 uint16_t cause;
295
296 bool rr_cause_present;
297 uint8_t rr_cause;
298
299 struct gsm0808_speech_codec_list codec_list_bss_supported; /*< omit when .len == 0 */
300
301 /* more items are defined in the spec and may be added later */
302 bool more_items; /*< always set this to false */
303};
304struct msgb *gsm0808_create_handover_failure(const struct gsm0808_handover_failure *params);
305
Philipp Maier225bdf42018-10-30 14:56:59 +0100306struct gsm0808_handover_performed {
307 uint16_t cause;
308 struct gsm0808_cell_id cell_id;
309
310 bool chosen_channel_present;
311 uint8_t chosen_channel;
312
313 bool chosen_encr_alg_present;
314 uint8_t chosen_encr_alg;
315
316 bool speech_version_chosen_present;
Neels Hofmeyr302aafc2019-04-10 19:23:45 +0200317 enum gsm0808_permitted_speech speech_version_chosen;
Philipp Maier225bdf42018-10-30 14:56:59 +0100318
319 bool speech_codec_chosen_present;
320 struct gsm0808_speech_codec speech_codec_chosen;
321
322 bool lcls_bss_status_present;
323 enum gsm0808_lcls_status lcls_bss_status;
324
325 /* more items are defined in the spec and may be added later */
326 bool more_items; /*< always set this to false */
327};
328struct msgb *gsm0808_create_handover_performed(const struct gsm0808_handover_performed *params);
329
Holger Hans Peter Freytherc25c6682010-11-04 12:26:06 +0100330struct msgb *gsm0808_create_dtap(struct msgb *msg, uint8_t link_id);
Holger Hans Peter Freyther9a3dec02010-05-16 08:15:40 +0800331void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id);
332
Harald Weltef4d45ab2011-07-16 12:13:00 +0200333const struct tlv_definition *gsm0808_att_tlvdef(void);
Pau Espin Pedrolcde47792021-04-19 12:24:02 +0200334extern const struct tlv_definition gsm0808_old_bss_to_new_bss_info_att_tlvdef;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200335
Maxc0d1de32018-11-07 15:24:11 +0100336/*! Parse BSSAP TLV structure using \ref tlv_parse */
337#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 +0200338/*! Parse BSSAP TLV structure using \ref tlv_parse2 */
339#define osmo_bssap_tlv_parse2(dec, dec_multiples, buf, len) \
340 tlv_parse2(dec, dec_multiples, gsm0808_att_tlvdef(), buf, len, 0, 0)
Maxc0d1de32018-11-07 15:24:11 +0100341
Harald Welte9b837e62011-07-11 17:43:19 +0200342const char *gsm0808_bssmap_name(uint8_t msg_type);
343const char *gsm0808_bssap_name(uint8_t msg_type);
Maxaa934632018-11-07 13:16:54 +0100344const char *gsm0808_cause_name(enum gsm0808_cause cause);
345const char *gsm0808_cause_class_name(enum gsm0808_cause_class class);
Harald Welte37b61652017-10-16 18:46:03 +0200346
Alexander Chemerisfdfe25b2020-05-12 23:21:56 +0300347/*! Parse Cause TLV 3GPP TS 08.08 ยง3.2.2.5
348 * \returns Cause value */
349enum gsm0808_cause gsm0808_get_cause(const struct tlv_parsed *tp);
350
Alexander Chemeris22630e62020-05-13 00:44:04 +0300351const char *gsm0808_diagnostics_octet_location_str(uint8_t pointer);
352const char *gsm0808_diagnostics_bit_location_str(uint8_t bit_pointer);
353
Harald Welteebd362d2018-06-02 14:11:19 +0200354extern const struct value_string gsm0808_lcls_config_names[];
355extern const struct value_string gsm0808_lcls_control_names[];
356extern const struct value_string gsm0808_lcls_status_names[];
357
Maxe118ed22018-12-19 17:05:37 +0100358static inline const char *gsm0808_lcls_config_name(enum gsm0808_lcls_config val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200359 return get_value_string(gsm0808_lcls_config_names, val);
360}
Maxe118ed22018-12-19 17:05:37 +0100361static inline const char *gsm0808_lcls_control_name(enum gsm0808_lcls_control val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200362 return get_value_string(gsm0808_lcls_control_names, val);
363}
Maxe118ed22018-12-19 17:05:37 +0100364static inline const char *gsm0808_lcls_status_name(enum gsm0808_lcls_status val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200365 return get_value_string(gsm0808_lcls_status_names, val);
366}
367
Harald Welte37b61652017-10-16 18:46:03 +0200368/*! @} */