Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1 | /* GSM Mobile Radio Interface Layer 3 messages on the A-bis interface |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 2 | * 3GPP TS 04.08 version 7.21.0 Release 1998 / ETSI TS 100 940 V7.21.0 */ |
| 3 | |
| 4 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
| 5 | * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 18 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #ifndef _MNCC_H |
| 25 | #define _MNCC_H |
| 26 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 27 | #include <osmocom/core/linuxlist.h> |
| 28 | #include <osmocom/gsm/mncc.h> |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 29 | |
Holger Hans Peter Freyther | 59234a3 | 2011-01-06 14:42:15 +0100 | [diff] [blame] | 30 | #include <stdint.h> |
Pau Espin Pedrol | eeda9e1 | 2020-09-03 22:11:03 +0200 | [diff] [blame] | 31 | #include <netinet/in.h> |
Holger Hans Peter Freyther | 59234a3 | 2011-01-06 14:42:15 +0100 | [diff] [blame] | 32 | |
Sylvain Munaut | 98b53cb | 2010-12-01 22:38:51 +0100 | [diff] [blame] | 33 | struct gsm_network; |
Harald Welte | 29b64e9 | 2010-12-23 01:07:46 +0100 | [diff] [blame] | 34 | struct msgb; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 35 | struct gsm0808_channel_type; |
Sylvain Munaut | 98b53cb | 2010-12-01 22:38:51 +0100 | [diff] [blame] | 36 | |
| 37 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 38 | /* One end of a call */ |
| 39 | struct gsm_call { |
| 40 | struct llist_head entry; |
| 41 | |
| 42 | /* network handle */ |
Max | 6b3cef0 | 2019-01-15 13:43:45 +0100 | [diff] [blame] | 43 | struct gsm_network *net; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 44 | |
| 45 | /* the 'local' transaction */ |
Holger Hans Peter Freyther | 59234a3 | 2011-01-06 14:42:15 +0100 | [diff] [blame] | 46 | uint32_t callref; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 47 | /* the 'remote' transaction */ |
Holger Hans Peter Freyther | 59234a3 | 2011-01-06 14:42:15 +0100 | [diff] [blame] | 48 | uint32_t remote_ref; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | #define MNCC_SETUP_REQ 0x0101 |
| 52 | #define MNCC_SETUP_IND 0x0102 |
| 53 | #define MNCC_SETUP_RSP 0x0103 |
| 54 | #define MNCC_SETUP_CNF 0x0104 |
| 55 | #define MNCC_SETUP_COMPL_REQ 0x0105 |
| 56 | #define MNCC_SETUP_COMPL_IND 0x0106 |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 57 | /* MNCC_REJ_* is performed via MNCC_REL_* */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 58 | #define MNCC_CALL_CONF_IND 0x0107 |
| 59 | #define MNCC_CALL_PROC_REQ 0x0108 |
| 60 | #define MNCC_PROGRESS_REQ 0x0109 |
| 61 | #define MNCC_ALERT_REQ 0x010a |
| 62 | #define MNCC_ALERT_IND 0x010b |
| 63 | #define MNCC_NOTIFY_REQ 0x010c |
| 64 | #define MNCC_NOTIFY_IND 0x010d |
| 65 | #define MNCC_DISC_REQ 0x010e |
| 66 | #define MNCC_DISC_IND 0x010f |
| 67 | #define MNCC_REL_REQ 0x0110 |
| 68 | #define MNCC_REL_IND 0x0111 |
| 69 | #define MNCC_REL_CNF 0x0112 |
| 70 | #define MNCC_FACILITY_REQ 0x0113 |
| 71 | #define MNCC_FACILITY_IND 0x0114 |
| 72 | #define MNCC_START_DTMF_IND 0x0115 |
| 73 | #define MNCC_START_DTMF_RSP 0x0116 |
| 74 | #define MNCC_START_DTMF_REJ 0x0117 |
| 75 | #define MNCC_STOP_DTMF_IND 0x0118 |
| 76 | #define MNCC_STOP_DTMF_RSP 0x0119 |
| 77 | #define MNCC_MODIFY_REQ 0x011a |
| 78 | #define MNCC_MODIFY_IND 0x011b |
| 79 | #define MNCC_MODIFY_RSP 0x011c |
| 80 | #define MNCC_MODIFY_CNF 0x011d |
| 81 | #define MNCC_MODIFY_REJ 0x011e |
| 82 | #define MNCC_HOLD_IND 0x011f |
| 83 | #define MNCC_HOLD_CNF 0x0120 |
| 84 | #define MNCC_HOLD_REJ 0x0121 |
| 85 | #define MNCC_RETRIEVE_IND 0x0122 |
| 86 | #define MNCC_RETRIEVE_CNF 0x0123 |
| 87 | #define MNCC_RETRIEVE_REJ 0x0124 |
| 88 | #define MNCC_USERINFO_REQ 0x0125 |
| 89 | #define MNCC_USERINFO_IND 0x0126 |
| 90 | #define MNCC_REJ_REQ 0x0127 |
| 91 | #define MNCC_REJ_IND 0x0128 |
| 92 | |
| 93 | #define MNCC_BRIDGE 0x0200 |
| 94 | #define MNCC_FRAME_RECV 0x0201 |
| 95 | #define MNCC_FRAME_DROP 0x0202 |
| 96 | #define MNCC_LCHAN_MODIFY 0x0203 |
Holger Hans Peter Freyther | ffbf45e | 2015-07-14 16:03:41 +0200 | [diff] [blame] | 97 | #define MNCC_RTP_CREATE 0x0204 |
| 98 | #define MNCC_RTP_CONNECT 0x0205 |
| 99 | #define MNCC_RTP_FREE 0x0206 |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 100 | |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 101 | #define GSM_TCHF_FRAME 0x0300 |
Harald Welte | aca8f15 | 2009-12-19 23:06:41 +0100 | [diff] [blame] | 102 | #define GSM_TCHF_FRAME_EFR 0x0301 |
Andreas Eversberg | f78fc4e | 2014-01-31 09:02:01 +0100 | [diff] [blame] | 103 | #define GSM_TCHH_FRAME 0x0302 |
| 104 | #define GSM_TCH_FRAME_AMR 0x0303 |
| 105 | #define GSM_BAD_FRAME 0x03ff |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 106 | |
Holger Hans Peter Freyther | 347e7ba | 2011-10-21 14:12:46 +0200 | [diff] [blame] | 107 | #define MNCC_SOCKET_HELLO 0x0400 |
| 108 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 109 | #define GSM_MAX_FACILITY 128 |
| 110 | #define GSM_MAX_SSVERSION 128 |
| 111 | #define GSM_MAX_USERUSER 128 |
| 112 | |
| 113 | #define MNCC_F_BEARER_CAP 0x0001 |
| 114 | #define MNCC_F_CALLED 0x0002 |
| 115 | #define MNCC_F_CALLING 0x0004 |
| 116 | #define MNCC_F_REDIRECTING 0x0008 |
| 117 | #define MNCC_F_CONNECTED 0x0010 |
| 118 | #define MNCC_F_CAUSE 0x0020 |
| 119 | #define MNCC_F_USERUSER 0x0040 |
| 120 | #define MNCC_F_PROGRESS 0x0080 |
| 121 | #define MNCC_F_EMERGENCY 0x0100 |
| 122 | #define MNCC_F_FACILITY 0x0200 |
| 123 | #define MNCC_F_SSVERSION 0x0400 |
| 124 | #define MNCC_F_CCCAP 0x0800 |
| 125 | #define MNCC_F_KEYPAD 0x1000 |
| 126 | #define MNCC_F_SIGNAL 0x2000 |
Vadim Yanitskiy | c6921e5 | 2021-10-27 17:05:55 +0300 | [diff] [blame] | 127 | #define MNCC_F_GCR 0x4000 |
Andreas Eversberg | 934f43b | 2023-12-19 12:56:20 +0100 | [diff] [blame] | 128 | #define MNCC_F_HIGHL_COMPAT 0x8000 |
| 129 | #define MNCC_F_LOWL_COMPAT 0x10000 |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 130 | |
Vadim Yanitskiy | 8e15c79 | 2022-10-03 15:41:15 +0700 | [diff] [blame] | 131 | /* UPDATEME when adding new MNCC_F_* entries above */ |
Andreas Eversberg | 934f43b | 2023-12-19 12:56:20 +0100 | [diff] [blame] | 132 | #define MNCC_F_ALL 0x1ffff |
| 133 | |
| 134 | #define GSM_MAX_LOWL_COMPAT 16 /* (18 with TLV) */ |
| 135 | #define GSM_MAX_HIGHL_COMPAT 3 /* (5 with TLV) */ |
Vadim Yanitskiy | 8e15c79 | 2022-10-03 15:41:15 +0700 | [diff] [blame] | 136 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 137 | struct gsm_mncc { |
| 138 | /* context based information */ |
Holger Hans Peter Freyther | 59234a3 | 2011-01-06 14:42:15 +0100 | [diff] [blame] | 139 | uint32_t msg_type; |
| 140 | uint32_t callref; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 141 | |
| 142 | /* which fields are present */ |
Holger Hans Peter Freyther | 59234a3 | 2011-01-06 14:42:15 +0100 | [diff] [blame] | 143 | uint32_t fields; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 144 | |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 145 | /* data derived information (MNCC_F_ based) */ |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 146 | struct gsm_mncc_bearer_cap bearer_cap; |
| 147 | struct gsm_mncc_number called; |
| 148 | struct gsm_mncc_number calling; |
| 149 | struct gsm_mncc_number redirecting; |
| 150 | struct gsm_mncc_number connected; |
| 151 | struct gsm_mncc_cause cause; |
| 152 | struct gsm_mncc_progress progress; |
| 153 | struct gsm_mncc_useruser useruser; |
| 154 | struct gsm_mncc_facility facility; |
| 155 | struct gsm_mncc_cccap cccap; |
| 156 | struct gsm_mncc_ssversion ssversion; |
| 157 | struct { |
| 158 | int sup; |
| 159 | int inv; |
| 160 | } clir; |
| 161 | int signal; |
| 162 | |
| 163 | /* data derived information, not MNCC_F based */ |
| 164 | int keypad; |
| 165 | int more; |
| 166 | int notify; /* 0..127 */ |
| 167 | int emergency; |
Andreas Eversberg | c079be4 | 2009-06-15 23:22:09 +0200 | [diff] [blame] | 168 | char imsi[16]; |
Philipp Maier | fe6acd6 | 2017-12-05 13:02:37 +0100 | [diff] [blame] | 169 | |
| 170 | unsigned char lchan_type; |
| 171 | unsigned char lchan_mode; |
Vadim Yanitskiy | c6921e5 | 2021-10-27 17:05:55 +0300 | [diff] [blame] | 172 | |
| 173 | /* Global Call Reference (encoded as per 3GPP TS 29.205) */ |
| 174 | uint8_t gcr[16]; |
| 175 | |
Neels Hofmeyr | b455205 | 2019-10-21 03:00:26 +0200 | [diff] [blame] | 176 | /* A buffer to contain SDP ('\0' terminated) */ |
| 177 | char sdp[1024]; |
Andreas Eversberg | 934f43b | 2023-12-19 12:56:20 +0100 | [diff] [blame] | 178 | |
| 179 | /* Additional information that extends current socket interface version. */ |
| 180 | |
| 181 | /* The content requals of Low Layer compatibility IE, described in 3GPP TS 24.008 §10.5.4.18. */ |
| 182 | struct gsm_mncc_lowl_compat { |
| 183 | uint8_t len; |
| 184 | uint8_t compat[GSM_MAX_LOWL_COMPAT]; |
| 185 | } llc; |
| 186 | |
| 187 | /* The content requals of High Layer compatibility IE, described in 3GPP TS 24.008 §10.5.4.16. */ |
| 188 | struct gsm_mncc_highl_compat { |
| 189 | uint8_t len; |
| 190 | uint8_t compat[GSM_MAX_HIGHL_COMPAT]; |
| 191 | } hlc; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 192 | }; |
| 193 | |
Harald Welte | da7ab74 | 2009-12-19 22:23:05 +0100 | [diff] [blame] | 194 | struct gsm_data_frame { |
Holger Hans Peter Freyther | 59234a3 | 2011-01-06 14:42:15 +0100 | [diff] [blame] | 195 | uint32_t msg_type; |
| 196 | uint32_t callref; |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 197 | unsigned char data[0]; |
| 198 | }; |
| 199 | |
Keith Whyte | a1a70be | 2021-05-16 02:59:52 +0200 | [diff] [blame] | 200 | #define MNCC_SOCK_VERSION 8 |
Holger Hans Peter Freyther | 347e7ba | 2011-10-21 14:12:46 +0200 | [diff] [blame] | 201 | struct gsm_mncc_hello { |
| 202 | uint32_t msg_type; |
| 203 | uint32_t version; |
Holger Hans Peter Freyther | 9e7837a | 2012-01-15 00:38:35 +0100 | [diff] [blame] | 204 | |
| 205 | /* send the sizes of the structs */ |
| 206 | uint32_t mncc_size; |
| 207 | uint32_t data_frame_size; |
| 208 | |
| 209 | /* send some offsets */ |
| 210 | uint32_t called_offset; |
| 211 | uint32_t signal_offset; |
| 212 | uint32_t emergency_offset; |
Philipp Maier | fe6acd6 | 2017-12-05 13:02:37 +0100 | [diff] [blame] | 213 | uint32_t lchan_type_offset; |
Holger Hans Peter Freyther | 347e7ba | 2011-10-21 14:12:46 +0200 | [diff] [blame] | 214 | }; |
| 215 | |
Holger Hans Peter Freyther | ffbf45e | 2015-07-14 16:03:41 +0200 | [diff] [blame] | 216 | struct gsm_mncc_rtp { |
| 217 | uint32_t msg_type; |
| 218 | uint32_t callref; |
Pau Espin Pedrol | eeda9e1 | 2020-09-03 22:11:03 +0200 | [diff] [blame] | 219 | struct sockaddr_storage addr; |
Holger Hans Peter Freyther | ffbf45e | 2015-07-14 16:03:41 +0200 | [diff] [blame] | 220 | uint32_t payload_type; |
| 221 | uint32_t payload_msg_type; |
Neels Hofmeyr | b455205 | 2019-10-21 03:00:26 +0200 | [diff] [blame] | 222 | char sdp[1024]; |
Holger Hans Peter Freyther | ffbf45e | 2015-07-14 16:03:41 +0200 | [diff] [blame] | 223 | }; |
| 224 | |
Harald Welte | 53d51f5 | 2015-12-03 14:59:04 +0100 | [diff] [blame] | 225 | struct gsm_mncc_bridge { |
| 226 | uint32_t msg_type; |
| 227 | uint32_t callref[2]; |
| 228 | }; |
| 229 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 230 | union mncc_msg { |
| 231 | uint32_t msg_type; |
| 232 | struct gsm_mncc signal; |
| 233 | struct gsm_mncc_hello hello; |
| 234 | struct gsm_data_frame data_frame; |
| 235 | struct gsm_mncc_rtp rtp; |
| 236 | struct gsm_mncc_bridge bridge; |
| 237 | }; |
| 238 | |
Harald Welte | da8a19f | 2015-12-03 14:35:05 +0100 | [diff] [blame] | 239 | const char *get_mncc_name(int value); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 240 | void mncc_set_cause(struct gsm_mncc *data, int loc, int val); |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 241 | |
Harald Welte | ea057d9 | 2010-12-23 01:26:29 +0100 | [diff] [blame] | 242 | /* input from CC code into mncc_builtin */ |
| 243 | int int_mncc_recv(struct gsm_network *net, struct msgb *msg); |
| 244 | |
| 245 | /* input from CC code into mncc_sock */ |
Holger Hans Peter Freyther | 1cc7184 | 2011-01-06 14:13:44 +0100 | [diff] [blame] | 246 | int mncc_sock_from_cc(struct gsm_network *net, struct msgb *msg); |
Harald Welte | ea057d9 | 2010-12-23 01:26:29 +0100 | [diff] [blame] | 247 | |
Neels Hofmeyr | 0ade632 | 2016-02-23 14:55:17 +0100 | [diff] [blame] | 248 | int mncc_sock_init(struct gsm_network *net, const char *sock_path); |
Harald Welte | 4d54d0b | 2011-02-19 16:48:17 +0100 | [diff] [blame] | 249 | |
Andreas Eversberg | 9acbe4c | 2013-03-11 08:12:43 +0100 | [diff] [blame] | 250 | #define mncc_is_data_frame(msg_type) \ |
| 251 | (msg_type == GSM_TCHF_FRAME \ |
| 252 | || msg_type == GSM_TCHF_FRAME_EFR \ |
| 253 | || msg_type == GSM_TCHH_FRAME \ |
| 254 | || msg_type == GSM_TCH_FRAME_AMR \ |
| 255 | || msg_type == GSM_BAD_FRAME) |
| 256 | |
Harald Welte | 5718429 | 2018-01-22 01:49:02 +0100 | [diff] [blame] | 257 | int mncc_prim_check(const struct gsm_mncc *mncc_prim, unsigned int len); |
Neels Hofmeyr | b455205 | 2019-10-21 03:00:26 +0200 | [diff] [blame] | 258 | int mncc_check_sdp_termination(const char *label, const struct gsm_mncc *mncc, unsigned int len, const char *sdp); |
Andreas Eversberg | 9acbe4c | 2013-03-11 08:12:43 +0100 | [diff] [blame] | 259 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 260 | int mncc_bearer_cap_to_channel_type(struct gsm0808_channel_type *ct, const struct gsm_mncc_bearer_cap *bc); |
| 261 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 262 | #endif |