blob: b4c78032809a8a64207841c42884e44add7039a8 [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 *
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020019 */
Sylvain Munaut12ba7782014-06-16 10:13:40 +020020#pragma once
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020021
22#include "tlv.h"
Philipp Maierfa896ab2017-03-27 16:55:32 +020023#include <osmocom/gsm/protocol/gsm_08_08.h>
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +010024#include <osmocom/gsm/gsm0808_utils.h>
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010025#include <osmocom/gsm/gsm23003.h>
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +010026#include <osmocom/gsm/protocol/gsm_23_003.h>
Harald Welteebd362d2018-06-02 14:11:19 +020027#include <osmocom/core/utils.h>
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010028
Neels Hofmeyr99273c72019-02-22 04:48:56 +010029#define BSSMAP_MSG_SIZE 1024
30#define BSSMAP_MSG_HEADROOM 512
Maxf69aa9c2018-11-29 23:32:06 +010031
Harald Welte20725b92017-05-15 12:50:04 +020032struct sockaddr_storage;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020033
34struct msgb;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +010035struct gsm0808_cell_id_list2;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020036
Philipp Maierfa896ab2017-03-27 16:55:32 +020037struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc,
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +010038 uint16_t cc, int lac, uint16_t _ci)
39 OSMO_DEPRECATED("Use gsm0808_create_layer3_2() instead, to not lose leading zeros in the MNC");
Philipp Maierfa896ab2017-03-27 16:55:32 +020040struct msgb *gsm0808_create_layer3_aoip(const struct msgb *msg_l3, uint16_t nc,
41 uint16_t cc, int lac, uint16_t _ci,
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +010042 const struct gsm0808_speech_codec_list *scl)
43 OSMO_DEPRECATED("Use gsm0808_create_layer3_2() instead, to not lose leading zeros in the MNC");
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010044struct msgb *gsm0808_create_layer3_2(const struct msgb *msg_l3, const struct osmo_cell_global_id *cell,
45 const struct gsm0808_speech_codec_list *scl);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020046struct msgb *gsm0808_create_reset(void);
Harald Weltea62fe312013-06-19 15:14:37 +020047struct msgb *gsm0808_create_reset_ack(void);
Philipp Maier1a146c82018-10-30 09:36:49 +010048struct msgb *gsm0808_create_clear_command(uint8_t cause);
Philipp Maier74c4c4e2019-02-04 16:42:28 +010049struct msgb *gsm0808_create_clear_command2(uint8_t cause, bool csfb_ind);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020050struct msgb *gsm0808_create_clear_complete(void);
Philipp Maierb478dd32017-03-29 15:50:05 +020051struct msgb *gsm0808_create_cipher(const struct gsm0808_encrypt_info *ei,
52 const uint8_t *cipher_response_mode);
Neels Hofmeyr4a9756c2021-06-10 00:48:15 +020053
54struct gsm0808_cipher_mode_command {
55 struct gsm0808_encrypt_info ei;
56
57 /*! 3GPP TS 48.008 3.2.2.34 Cipher Response Mode, optional IE */
58 bool cipher_response_mode_present;
59 /*! 3GPP TS 48.008 3.2.2.34 Cipher Response Mode:
60 * 0 - IMEISV must not be included by the Mobile Station;
61 * 1 - IMEISV must be included by the Mobile Station.
62 */
63 uint8_t cipher_response_mode;
64
65 bool kc128_present;
66 uint8_t kc128[16];
67
68 /* more items are defined in the spec and may be added later */
69 bool more_items; /*< always set this to false */
70};
71struct msgb *gsm0808_create_cipher2(const struct gsm0808_cipher_mode_command *cmc);
72
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +020073struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id);
Maxaa934632018-11-07 13:16:54 +010074struct msgb *gsm0808_create_cipher_reject(enum gsm0808_cause cause);
Maxed651d22018-11-07 15:25:05 +010075struct msgb *gsm0808_create_cipher_reject_ext(enum gsm0808_cause_class class, uint8_t ext);
Neels Hofmeyr2c79d552018-09-13 05:36:32 +020076struct msgb *gsm0808_create_classmark_request();
Harald Welte07b625d2012-01-23 10:02:58 +010077struct msgb *gsm0808_create_classmark_update(const uint8_t *cm2, uint8_t cm2_len,
78 const uint8_t *cm3, uint8_t cm3_len);
Vadim Yanitskiyfa6cd882020-08-26 18:03:59 +070079struct msgb *gsm0808_create_sapi_reject_cause(uint8_t link_id, uint16_t cause);
80struct msgb *gsm0808_create_sapi_reject(uint8_t link_id)
81 OSMO_DEPRECATED("Use gsm0808_create_sapi_reject_cause() instead");
Philipp Maierc6144a22017-03-29 17:53:43 +020082struct msgb *gsm0808_create_ass(const struct gsm0808_channel_type *ct,
83 const uint16_t *cic,
84 const struct sockaddr_storage *ss,
85 const struct gsm0808_speech_codec_list *scl,
86 const uint32_t *ci);
Max52074322018-11-30 10:44:07 +010087struct msgb *gsm0808_create_ass2(const struct gsm0808_channel_type *ct,
88 const uint16_t *cic,
89 const struct sockaddr_storage *ss,
90 const struct gsm0808_speech_codec_list *scl,
91 const uint32_t *ci,
92 const uint8_t *kc, const struct osmo_lcls *lcls);
Philipp Maierfa896ab2017-03-27 16:55:32 +020093struct msgb *gsm0808_create_ass_compl(uint8_t rr_cause, uint8_t chosen_channel,
94 uint8_t encr_alg_id, uint8_t speech_mode,
95 const struct sockaddr_storage *ss,
96 const struct gsm0808_speech_codec *sc,
97 const struct gsm0808_speech_codec_list
98 *scl);
Max414c8f52019-01-08 14:44:24 +010099struct msgb *gsm0808_create_ass_compl2(uint8_t rr_cause, uint8_t chosen_channel,
100 uint8_t encr_alg_id, uint8_t speech_mode,
101 const struct sockaddr_storage *ss,
102 const struct gsm0808_speech_codec *sc,
103 const struct gsm0808_speech_codec_list *scl,
104 enum gsm0808_lcls_status lcls_bss_status);
Holger Hans Peter Freytherb60a4b32010-07-23 18:35:59 +0800105struct msgb *gsm0808_create_assignment_completed(uint8_t rr_cause,
Philipp Maierfa896ab2017-03-27 16:55:32 +0200106 uint8_t chosen_channel,
107 uint8_t encr_alg_id,
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +0200108 uint8_t speech_mode);
Philipp Maierfa896ab2017-03-27 16:55:32 +0200109struct msgb *gsm0808_create_ass_fail(uint8_t cause, const uint8_t *rr_cause,
110 const struct gsm0808_speech_codec_list
111 *scl);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200112struct msgb *gsm0808_create_assignment_failure(uint8_t cause, uint8_t *rr_cause);
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +0100113struct msgb *gsm0808_create_clear_rqst(uint8_t cause);
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100114struct msgb *gsm0808_create_paging2(const char *imsi, const uint32_t *tmsi,
115 const struct gsm0808_cell_id_list2 *cil,
116 const uint8_t *chan_needed);
Philipp Maier3d48ec02017-03-29 17:37:55 +0200117struct msgb *gsm0808_create_paging(const char *imsi, const uint32_t *tmsi,
118 const struct gsm0808_cell_id_list *cil,
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100119 const uint8_t *chan_needed)
120 OSMO_DEPRECATED("use gsm0808_create_paging2 instead");
Max45f89c92018-12-19 19:35:26 +0100121struct msgb *gsm0808_create_lcls_conn_ctrl(enum gsm0808_lcls_config config,
122 enum gsm0808_lcls_control control);
Harald Welte64e807c2018-05-29 21:00:56 +0200123struct msgb *gsm0808_create_lcls_conn_ctrl_ack(enum gsm0808_lcls_status status);
124struct msgb *gsm0808_create_lcls_notification(enum gsm0808_lcls_status status, bool break_req);
Harald Welte1bd726a2020-06-21 22:04:52 +0200125struct msgb *gsm0808_create_common_id(const char *imsi,
126 const struct osmo_plmn_id *selected_plmn_id,
127 const struct osmo_plmn_id *last_used_eutran_plnm_id);
Harald Welte64e807c2018-05-29 21:00:56 +0200128
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200129
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100130/*! 3GPP TS 48.008 ยง3.2.2.5.8 Old BSS to New BSS information */
131struct gsm0808_old_bss_to_new_bss_info {
132 bool extra_information_present;
133 struct {
134 bool prec;
135 bool lcs;
136 bool ue_prob;
137 } extra_information;
138
139 bool current_channel_type_2_present;
140 struct {
141 uint8_t mode;
142 uint8_t field;
143 } current_channel_type_2;
144
Pau Espin Pedrol1b625cb2021-04-14 21:27:31 +0200145 bool last_eutran_plmn_id_present;
146 struct osmo_plmn_id last_eutran_plmn_id;
147
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100148 /* more items are defined in the spec and may be added later */
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200149 bool more_items; /*< always set this to false */
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100150};
151
152/*! 3GPP TS 48.008 ยง3.2.1.9 HANDOVER REQUIRED */
153struct gsm0808_handover_required {
154 uint16_t cause;
155 struct gsm0808_cell_id_list2 cil;
156
157 bool current_channel_type_1_present;
158 uint8_t current_channel_type_1;
159
160 bool speech_version_used_present;
Neels Hofmeyr302aafc2019-04-10 19:23:45 +0200161 enum gsm0808_permitted_speech speech_version_used;
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100162
163 bool old_bss_to_new_bss_info_present;
164 struct gsm0808_old_bss_to_new_bss_info old_bss_to_new_bss_info;
165
166 /* more items are defined in the spec and may be added later */
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200167 bool more_items; /*< always set this to false */
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100168};
169struct msgb *gsm0808_create_handover_required(const struct gsm0808_handover_required *params);
170
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100171/*! 3GPP TS 48.008 ยง3.2.1.37 HANDOVER REQUIRED REJECT */
172struct gsm0808_handover_required_reject {
173 uint16_t cause;
174
175 /* more items are defined in the spec and may be added later */
176 bool more_items; /*< always set this to false */
177};
178struct msgb *gsm0808_create_handover_required_reject(const struct gsm0808_handover_required_reject *params);
179
180/*! 3GPP TS 48.008 ยง3.2.1.8 HANDOVER REQUEST */
181struct gsm0808_handover_request {
182 struct gsm0808_channel_type channel_type;
183 struct gsm0808_encrypt_info encryption_information;
184 struct osmo_gsm48_classmark classmark_information;
185 struct gsm0808_cell_id cell_identifier_serving;
186 struct gsm0808_cell_id cell_identifier_target;
187 enum gsm0808_cause cause;
188
189 bool current_channel_type_1_present;
190 uint8_t current_channel_type_1;
191
192 enum gsm0808_permitted_speech speech_version_used;
193
194 uint8_t chosen_encryption_algorithm_serving;
195
196 /*! Pass either old_bss_to_new_bss_info or old_bss_to_new_bss_info_raw. */
197 bool old_bss_to_new_bss_info_present;
198 struct gsm0808_old_bss_to_new_bss_info old_bss_to_new_bss_info;
199 /*! To feed the Old BSS to New BSS Information IE unchanged from the Handover Required message without having to
200 * decode it. Pass either old_bss_to_new_bss_info or old_bss_to_new_bss_info_raw. Omit the TL part. */
201 const uint8_t *old_bss_to_new_bss_info_raw;
202 uint8_t old_bss_to_new_bss_info_raw_len;
203
204 const char *imsi;
205
206 const struct sockaddr_storage *aoip_transport_layer;
207
208 const struct gsm0808_speech_codec_list *codec_list_msc_preferred;
209
210 bool call_id_present;
211 uint32_t call_id;
212
213 const uint8_t *global_call_reference;
214 uint8_t global_call_reference_len;
215
216 /* more items are defined in the spec and may be added later */
Neels Hofmeyre4378b72021-06-10 00:54:35 +0200217 bool more_items; /*!< set this to true iff any fields below are used */
218
219 bool kc128_present;
220 uint8_t kc128[16];
221
222 bool more_items2; /*!< always set this to false */
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100223};
224struct msgb *gsm0808_create_handover_request(const struct gsm0808_handover_request *params);
225
Harald Welteaa98c482019-05-06 10:31:35 +0200226struct msgb *gsm0808_create_handover_request_ack(const uint8_t *l3_info, uint8_t l3_info_len,
227 uint8_t chosen_channel, uint8_t chosen_encr_alg,
228 uint8_t chosen_speech_version);
229
Neels Hofmeyr73b943e2019-03-14 04:10:25 +0100230struct gsm0808_handover_request_ack {
231 const uint8_t *l3_info;
232 uint8_t l3_info_len;
233
234 bool chosen_channel_present;
235 uint8_t chosen_channel;
236
237 /*! 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
238 * means A5/3. Set chosen_encr_alg = 0 to omit the Chosen Encryption Algorithm IE. */
239 uint8_t chosen_encr_alg;
240
241 /* chosen_speech_version == 0 omits the IE */
242 enum gsm0808_permitted_speech chosen_speech_version;
243
244 bool speech_codec_chosen_present;
245 struct gsm0808_speech_codec speech_codec_chosen;
246
247 const struct sockaddr_storage *aoip_transport_layer;
248
Neels Hofmeyrbde89d52022-02-23 14:25:22 +0100249 bool more_items; /*!< set this to true iff any fields below are used */
250
251 struct gsm0808_speech_codec_list codec_list_bss_supported; /*< omit when .len == 0 */
252
Neels Hofmeyr73b943e2019-03-14 04:10:25 +0100253 /* more items are defined in the spec and may be added later */
Neels Hofmeyrbde89d52022-02-23 14:25:22 +0100254 bool more_items2; /*!< always set this to false */
Neels Hofmeyr73b943e2019-03-14 04:10:25 +0100255};
256struct msgb *gsm0808_create_handover_request_ack2(const struct gsm0808_handover_request_ack *params);
Neels Hofmeyrb662b362018-04-16 22:31:15 +0200257
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100258struct gsm0808_handover_command {
259 const uint8_t *l3_info;
260 uint8_t l3_info_len;
261
262 struct gsm0808_cell_id cell_identifier;
263
264 const uint8_t *new_bss_to_old_bss_info_raw;
265 size_t new_bss_to_old_bss_info_raw_len;
266
267 /* more items are defined in the spec and may be added later */
268 bool more_items; /*!< always set this to false */
269};
270struct msgb *gsm0808_create_handover_command(const struct gsm0808_handover_command *params);
271
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200272struct msgb *gsm0808_create_handover_detect();
Neels Hofmeyrf7e9c512019-03-06 04:25:38 +0100273struct msgb *gsm0808_create_handover_succeeded();
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200274
275struct gsm0808_handover_complete {
276 bool rr_cause_present;
277 uint8_t rr_cause;
278
279 bool speech_codec_chosen_present;
280 struct gsm0808_speech_codec speech_codec_chosen;
281
282 struct gsm0808_speech_codec_list codec_list_bss_supported; /*< omit when .len == 0 */
283
284 bool chosen_encr_alg_present;
285 uint8_t chosen_encr_alg;
Pau Espin Pedrol4da98cc2021-04-14 21:28:01 +0200286
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200287 bool chosen_channel_present;
288 uint8_t chosen_channel;
289
290 bool lcls_bss_status_present;
291 enum gsm0808_lcls_status lcls_bss_status;
292
293 /* more items are defined in the spec and may be added later */
294 bool more_items; /*< always set this to false */
295};
296struct msgb *gsm0808_create_handover_complete(const struct gsm0808_handover_complete *params);
297
298struct gsm0808_handover_failure {
299 uint16_t cause;
300
301 bool rr_cause_present;
302 uint8_t rr_cause;
303
304 struct gsm0808_speech_codec_list codec_list_bss_supported; /*< omit when .len == 0 */
305
306 /* more items are defined in the spec and may be added later */
307 bool more_items; /*< always set this to false */
308};
309struct msgb *gsm0808_create_handover_failure(const struct gsm0808_handover_failure *params);
310
Philipp Maier225bdf42018-10-30 14:56:59 +0100311struct gsm0808_handover_performed {
312 uint16_t cause;
313 struct gsm0808_cell_id cell_id;
314
315 bool chosen_channel_present;
316 uint8_t chosen_channel;
317
318 bool chosen_encr_alg_present;
319 uint8_t chosen_encr_alg;
320
321 bool speech_version_chosen_present;
Neels Hofmeyr302aafc2019-04-10 19:23:45 +0200322 enum gsm0808_permitted_speech speech_version_chosen;
Philipp Maier225bdf42018-10-30 14:56:59 +0100323
324 bool speech_codec_chosen_present;
325 struct gsm0808_speech_codec speech_codec_chosen;
326
327 bool lcls_bss_status_present;
328 enum gsm0808_lcls_status lcls_bss_status;
329
330 /* more items are defined in the spec and may be added later */
331 bool more_items; /*< always set this to false */
332};
333struct msgb *gsm0808_create_handover_performed(const struct gsm0808_handover_performed *params);
334
Holger Hans Peter Freytherc25c6682010-11-04 12:26:06 +0100335struct msgb *gsm0808_create_dtap(struct msgb *msg, uint8_t link_id);
Holger Hans Peter Freyther9a3dec02010-05-16 08:15:40 +0800336void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id);
337
Harald Weltef4d45ab2011-07-16 12:13:00 +0200338const struct tlv_definition *gsm0808_att_tlvdef(void);
Pau Espin Pedrolcde47792021-04-19 12:24:02 +0200339extern const struct tlv_definition gsm0808_old_bss_to_new_bss_info_att_tlvdef;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200340
Maxc0d1de32018-11-07 15:24:11 +0100341/*! Parse BSSAP TLV structure using \ref tlv_parse */
342#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 +0200343/*! Parse BSSAP TLV structure using \ref tlv_parse2 */
344#define osmo_bssap_tlv_parse2(dec, dec_multiples, buf, len) \
345 tlv_parse2(dec, dec_multiples, gsm0808_att_tlvdef(), buf, len, 0, 0)
Maxc0d1de32018-11-07 15:24:11 +0100346
Harald Welte9b837e62011-07-11 17:43:19 +0200347const char *gsm0808_bssmap_name(uint8_t msg_type);
348const char *gsm0808_bssap_name(uint8_t msg_type);
Maxaa934632018-11-07 13:16:54 +0100349const char *gsm0808_cause_name(enum gsm0808_cause cause);
350const char *gsm0808_cause_class_name(enum gsm0808_cause_class class);
Harald Welte37b61652017-10-16 18:46:03 +0200351
Alexander Chemerisfdfe25b2020-05-12 23:21:56 +0300352/*! Parse Cause TLV 3GPP TS 08.08 ยง3.2.2.5
353 * \returns Cause value */
354enum gsm0808_cause gsm0808_get_cause(const struct tlv_parsed *tp);
355
Alexander Chemeris22630e62020-05-13 00:44:04 +0300356const char *gsm0808_diagnostics_octet_location_str(uint8_t pointer);
357const char *gsm0808_diagnostics_bit_location_str(uint8_t bit_pointer);
358
Harald Welteebd362d2018-06-02 14:11:19 +0200359extern const struct value_string gsm0808_lcls_config_names[];
360extern const struct value_string gsm0808_lcls_control_names[];
361extern const struct value_string gsm0808_lcls_status_names[];
362
Maxe118ed22018-12-19 17:05:37 +0100363static inline const char *gsm0808_lcls_config_name(enum gsm0808_lcls_config val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200364 return get_value_string(gsm0808_lcls_config_names, val);
365}
Maxe118ed22018-12-19 17:05:37 +0100366static inline const char *gsm0808_lcls_control_name(enum gsm0808_lcls_control val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200367 return get_value_string(gsm0808_lcls_control_names, val);
368}
Maxe118ed22018-12-19 17:05:37 +0100369static inline const char *gsm0808_lcls_status_name(enum gsm0808_lcls_status val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200370 return get_value_string(gsm0808_lcls_status_names, val);
371}
372
Harald Welte37b61652017-10-16 18:46:03 +0200373/*! @} */