blob: 35e7a8e30070068d1a572cdacef9ef8853a85418 [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>
Harald Welteebd362d2018-06-02 14:11:19 +020030#include <osmocom/core/utils.h>
Neels Hofmeyrc4fce142018-02-20 13:47:08 +010031
Maxf69aa9c2018-11-29 23:32:06 +010032#define BSSMAP_MSG_SIZE 512
33#define BSSMAP_MSG_HEADROOM 128
34
Harald Welte20725b92017-05-15 12:50:04 +020035struct sockaddr_storage;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020036
37struct msgb;
Stefan Sperling11a4d9d2018-02-15 18:28:04 +010038struct gsm0808_cell_id_list2;
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020039
Philipp Maierfa896ab2017-03-27 16:55:32 +020040struct msgb *gsm0808_create_layer3(struct msgb *msg_l3, uint16_t nc,
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +010041 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 Maierfa896ab2017-03-27 16:55:32 +020043struct msgb *gsm0808_create_layer3_aoip(const struct msgb *msg_l3, uint16_t nc,
44 uint16_t cc, int lac, uint16_t _ci,
Neels Hofmeyrbd6c8b52018-03-22 14:05:21 +010045 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 Hofmeyrc4fce142018-02-20 13:47:08 +010047struct 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 Freyther280cd512010-04-15 10:10:39 +020049struct msgb *gsm0808_create_reset(void);
Harald Weltea62fe312013-06-19 15:14:37 +020050struct msgb *gsm0808_create_reset_ack(void);
Philipp Maier1a146c82018-10-30 09:36:49 +010051struct msgb *gsm0808_create_clear_command(uint8_t cause);
Philipp Maier74c4c4e2019-02-04 16:42:28 +010052struct msgb *gsm0808_create_clear_command2(uint8_t cause, bool csfb_ind);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020053struct msgb *gsm0808_create_clear_complete(void);
Philipp Maierb478dd32017-03-29 15:50:05 +020054struct msgb *gsm0808_create_cipher(const struct gsm0808_encrypt_info *ei,
55 const uint8_t *cipher_response_mode);
Holger Hans Peter Freyther81716d52010-04-17 06:16:35 +020056struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id);
Maxaa934632018-11-07 13:16:54 +010057struct msgb *gsm0808_create_cipher_reject(enum gsm0808_cause cause);
Maxed651d22018-11-07 15:25:05 +010058struct msgb *gsm0808_create_cipher_reject_ext(enum gsm0808_cause_class class, uint8_t ext);
Neels Hofmeyr2c79d552018-09-13 05:36:32 +020059struct msgb *gsm0808_create_classmark_request();
Harald Welte07b625d2012-01-23 10:02:58 +010060struct msgb *gsm0808_create_classmark_update(const uint8_t *cm2, uint8_t cm2_len,
61 const uint8_t *cm3, uint8_t cm3_len);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020062struct msgb *gsm0808_create_sapi_reject(uint8_t link_id);
Philipp Maierc6144a22017-03-29 17:53:43 +020063struct msgb *gsm0808_create_ass(const struct gsm0808_channel_type *ct,
64 const uint16_t *cic,
65 const struct sockaddr_storage *ss,
66 const struct gsm0808_speech_codec_list *scl,
67 const uint32_t *ci);
Max52074322018-11-30 10:44:07 +010068struct msgb *gsm0808_create_ass2(const struct gsm0808_channel_type *ct,
69 const uint16_t *cic,
70 const struct sockaddr_storage *ss,
71 const struct gsm0808_speech_codec_list *scl,
72 const uint32_t *ci,
73 const uint8_t *kc, const struct osmo_lcls *lcls);
Philipp Maierfa896ab2017-03-27 16:55:32 +020074struct msgb *gsm0808_create_ass_compl(uint8_t rr_cause, uint8_t chosen_channel,
75 uint8_t encr_alg_id, uint8_t speech_mode,
76 const struct sockaddr_storage *ss,
77 const struct gsm0808_speech_codec *sc,
78 const struct gsm0808_speech_codec_list
79 *scl);
Max414c8f52019-01-08 14:44:24 +010080struct msgb *gsm0808_create_ass_compl2(uint8_t rr_cause, uint8_t chosen_channel,
81 uint8_t encr_alg_id, uint8_t speech_mode,
82 const struct sockaddr_storage *ss,
83 const struct gsm0808_speech_codec *sc,
84 const struct gsm0808_speech_codec_list *scl,
85 enum gsm0808_lcls_status lcls_bss_status);
Holger Hans Peter Freytherb60a4b32010-07-23 18:35:59 +080086struct msgb *gsm0808_create_assignment_completed(uint8_t rr_cause,
Philipp Maierfa896ab2017-03-27 16:55:32 +020087 uint8_t chosen_channel,
88 uint8_t encr_alg_id,
Holger Hans Peter Freytherba6172a2010-04-17 06:21:49 +020089 uint8_t speech_mode);
Philipp Maierfa896ab2017-03-27 16:55:32 +020090struct msgb *gsm0808_create_ass_fail(uint8_t cause, const uint8_t *rr_cause,
91 const struct gsm0808_speech_codec_list
92 *scl);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +020093struct msgb *gsm0808_create_assignment_failure(uint8_t cause, uint8_t *rr_cause);
Holger Hans Peter Freytheraf270a42010-11-04 12:42:50 +010094struct msgb *gsm0808_create_clear_rqst(uint8_t cause);
Stefan Sperling11a4d9d2018-02-15 18:28:04 +010095struct msgb *gsm0808_create_paging2(const char *imsi, const uint32_t *tmsi,
96 const struct gsm0808_cell_id_list2 *cil,
97 const uint8_t *chan_needed);
Philipp Maier3d48ec02017-03-29 17:37:55 +020098struct msgb *gsm0808_create_paging(const char *imsi, const uint32_t *tmsi,
99 const struct gsm0808_cell_id_list *cil,
Stefan Sperling11a4d9d2018-02-15 18:28:04 +0100100 const uint8_t *chan_needed)
101 OSMO_DEPRECATED("use gsm0808_create_paging2 instead");
Max45f89c92018-12-19 19:35:26 +0100102struct msgb *gsm0808_create_lcls_conn_ctrl(enum gsm0808_lcls_config config,
103 enum gsm0808_lcls_control control);
Harald Welte64e807c2018-05-29 21:00:56 +0200104struct msgb *gsm0808_create_lcls_conn_ctrl_ack(enum gsm0808_lcls_status status);
105struct msgb *gsm0808_create_lcls_notification(enum gsm0808_lcls_status status, bool break_req);
106
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200107
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100108/*! 3GPP TS 48.008 §3.2.2.5.8 Old BSS to New BSS information */
109struct gsm0808_old_bss_to_new_bss_info {
110 bool extra_information_present;
111 struct {
112 bool prec;
113 bool lcs;
114 bool ue_prob;
115 } extra_information;
116
117 bool current_channel_type_2_present;
118 struct {
119 uint8_t mode;
120 uint8_t field;
121 } current_channel_type_2;
122
123 /* more items are defined in the spec and may be added later */
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200124 bool more_items; /*< always set this to false */
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100125};
126
127/*! 3GPP TS 48.008 §3.2.1.9 HANDOVER REQUIRED */
128struct gsm0808_handover_required {
129 uint16_t cause;
130 struct gsm0808_cell_id_list2 cil;
131
132 bool current_channel_type_1_present;
133 uint8_t current_channel_type_1;
134
135 bool speech_version_used_present;
136 uint8_t speech_version_used;
137
138 bool old_bss_to_new_bss_info_present;
139 struct gsm0808_old_bss_to_new_bss_info old_bss_to_new_bss_info;
140
141 /* more items are defined in the spec and may be added later */
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200142 bool more_items; /*< always set this to false */
Neels Hofmeyr70aba3f2018-03-13 03:40:53 +0100143};
144struct msgb *gsm0808_create_handover_required(const struct gsm0808_handover_required *params);
145
Neels Hofmeyrb662b362018-04-16 22:31:15 +0200146struct msgb *gsm0808_create_handover_request_ack(const uint8_t *l3_info, uint8_t l3_info_len,
147 uint8_t chosen_channel, uint8_t chosen_encr_alg,
148 uint8_t chosen_speech_version);
149
Neels Hofmeyr60f31532018-04-16 22:42:09 +0200150struct msgb *gsm0808_create_handover_detect();
151
152struct gsm0808_handover_complete {
153 bool rr_cause_present;
154 uint8_t rr_cause;
155
156 bool speech_codec_chosen_present;
157 struct gsm0808_speech_codec speech_codec_chosen;
158
159 struct gsm0808_speech_codec_list codec_list_bss_supported; /*< omit when .len == 0 */
160
161 bool chosen_encr_alg_present;
162 uint8_t chosen_encr_alg;
163
164 bool chosen_channel_present;
165 uint8_t chosen_channel;
166
167 bool lcls_bss_status_present;
168 enum gsm0808_lcls_status lcls_bss_status;
169
170 /* more items are defined in the spec and may be added later */
171 bool more_items; /*< always set this to false */
172};
173struct msgb *gsm0808_create_handover_complete(const struct gsm0808_handover_complete *params);
174
175struct gsm0808_handover_failure {
176 uint16_t cause;
177
178 bool rr_cause_present;
179 uint8_t rr_cause;
180
181 struct gsm0808_speech_codec_list codec_list_bss_supported; /*< omit when .len == 0 */
182
183 /* more items are defined in the spec and may be added later */
184 bool more_items; /*< always set this to false */
185};
186struct msgb *gsm0808_create_handover_failure(const struct gsm0808_handover_failure *params);
187
Philipp Maier225bdf42018-10-30 14:56:59 +0100188struct gsm0808_handover_performed {
189 uint16_t cause;
190 struct gsm0808_cell_id cell_id;
191
192 bool chosen_channel_present;
193 uint8_t chosen_channel;
194
195 bool chosen_encr_alg_present;
196 uint8_t chosen_encr_alg;
197
198 bool speech_version_chosen_present;
199 uint8_t speech_version_chosen;
200
201 bool speech_codec_chosen_present;
202 struct gsm0808_speech_codec speech_codec_chosen;
203
204 bool lcls_bss_status_present;
205 enum gsm0808_lcls_status lcls_bss_status;
206
207 /* more items are defined in the spec and may be added later */
208 bool more_items; /*< always set this to false */
209};
210struct msgb *gsm0808_create_handover_performed(const struct gsm0808_handover_performed *params);
211
Holger Hans Peter Freytherc25c6682010-11-04 12:26:06 +0100212struct msgb *gsm0808_create_dtap(struct msgb *msg, uint8_t link_id);
Holger Hans Peter Freyther9a3dec02010-05-16 08:15:40 +0800213void gsm0808_prepend_dtap_header(struct msgb *msg, uint8_t link_id);
214
Harald Weltef4d45ab2011-07-16 12:13:00 +0200215const struct tlv_definition *gsm0808_att_tlvdef(void);
Holger Hans Peter Freyther280cd512010-04-15 10:10:39 +0200216
Maxc0d1de32018-11-07 15:24:11 +0100217/*! Parse BSSAP TLV structure using \ref tlv_parse */
218#define osmo_bssap_tlv_parse(dec, buf, len) tlv_parse(dec, gsm0808_att_tlvdef(), buf, len, 0, 0)
219
Harald Welte9b837e62011-07-11 17:43:19 +0200220const char *gsm0808_bssmap_name(uint8_t msg_type);
221const char *gsm0808_bssap_name(uint8_t msg_type);
Maxaa934632018-11-07 13:16:54 +0100222const char *gsm0808_cause_name(enum gsm0808_cause cause);
223const char *gsm0808_cause_class_name(enum gsm0808_cause_class class);
Harald Welte37b61652017-10-16 18:46:03 +0200224
Harald Welteebd362d2018-06-02 14:11:19 +0200225extern const struct value_string gsm0808_lcls_config_names[];
226extern const struct value_string gsm0808_lcls_control_names[];
227extern const struct value_string gsm0808_lcls_status_names[];
228
Maxe118ed22018-12-19 17:05:37 +0100229static inline const char *gsm0808_lcls_config_name(enum gsm0808_lcls_config val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200230 return get_value_string(gsm0808_lcls_config_names, val);
231}
Maxe118ed22018-12-19 17:05:37 +0100232static inline const char *gsm0808_lcls_control_name(enum gsm0808_lcls_control val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200233 return get_value_string(gsm0808_lcls_control_names, val);
234}
Maxe118ed22018-12-19 17:05:37 +0100235static inline const char *gsm0808_lcls_status_name(enum gsm0808_lcls_status val) {
Harald Welteebd362d2018-06-02 14:11:19 +0200236 return get_value_string(gsm0808_lcls_status_names, val);
237}
238
Harald Welte37b61652017-10-16 18:46:03 +0200239/*! @} */