Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 1 | /* PCU Interface codec poart in TTCN-3 |
| 2 | * (C) 2018 Harald Welte <laforge@gnumonks.org> |
| 3 | * contributions by sysmocom - s.f.m.c. GmbH |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Released under the terms of GNU General Public License, Version 2 or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 10 | */ |
| 11 | |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 12 | module PCUIF_CodecPort { |
| 13 | |
| 14 | import from Osmocom_Types all; |
| 15 | import from PCUIF_Types all; |
| 16 | import from UD_PortType all; |
| 17 | import from UD_Types all; |
Philipp Maier | 3b4abb8 | 2023-06-23 16:27:46 +0200 | [diff] [blame] | 18 | import from General_Types all; |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 19 | |
| 20 | type record PCUIF_send_data { |
| 21 | PCUIF_Message data, |
| 22 | integer id |
| 23 | }; |
| 24 | |
| 25 | private function PCUIF_to_UD(in PCUIF_send_data pin, out UD_send_data pout) { |
| 26 | pout.id := pin.id; |
Vadim Yanitskiy | 204fe62 | 2021-03-23 04:49:41 +0100 | [diff] [blame] | 27 | pout.data := enc_PCUIF_Message(pin.data); |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 28 | } with { extension "prototype(fast)" }; |
| 29 | |
Vadim Yanitskiy | 799cd3f | 2019-09-18 15:22:32 +0700 | [diff] [blame] | 30 | private function fix_padding(inout PCUIF_data data) { |
| 31 | data.data := substr(data.data, 0, data.len); |
| 32 | } |
| 33 | |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 34 | private function UD_to_PCUIF(in UD_send_data pin, out PCUIF_send_data pout) { |
| 35 | pout.id := pin.id; |
| 36 | pout.data := dec_PCUIF_Message(pin.data); |
Vadim Yanitskiy | 799cd3f | 2019-09-18 15:22:32 +0700 | [diff] [blame] | 37 | |
| 38 | /* HACK: fix padding in decoded message. Due to a bug in TITAN, we |
| 39 | * cannot just use its 'PADDING' attribute because it breaks decoding. */ |
| 40 | if (ischosen(pout.data.u.data_req)) { fix_padding(pout.data.u.data_req); } |
| 41 | if (ischosen(pout.data.u.data_cnf)) { fix_padding(pout.data.u.data_cnf); } |
| 42 | if (ischosen(pout.data.u.data_ind)) { fix_padding(pout.data.u.data_ind); } |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 43 | } with { extension "prototype(fast)" }; |
| 44 | |
| 45 | type port PCUIF_CODEC_PT message { |
| 46 | out UD_close, UD_listen, UD_shutdown, UD_connect, PCUIF_send_data; |
| 47 | in UD_listen_result, UD_connect_result, UD_connected, PCUIF_send_data; |
| 48 | } with { extension "user UD_PT |
| 49 | out ( |
| 50 | UD_close -> UD_close:simple; |
| 51 | UD_listen -> UD_listen:simple; |
| 52 | UD_shutdown -> UD_shutdown:simple; |
| 53 | UD_connect -> UD_connect:simple; |
| 54 | PCUIF_send_data -> UD_send_data: function(PCUIF_to_UD) |
| 55 | ) |
| 56 | in ( |
| 57 | UD_listen_result -> UD_listen_result:simple; |
| 58 | UD_connect_result -> UD_connect_result:simple; |
| 59 | UD_send_data -> PCUIF_send_data: function(UD_to_PCUIF); |
| 60 | UD_connected -> UD_connected:simple |
| 61 | )" |
| 62 | }; |
| 63 | |
| 64 | template PCUIF_send_data t_SD_PCUIF(integer id, template PCUIF_Message pdu) := { |
| 65 | data := pdu, |
| 66 | id := id |
| 67 | } |
| 68 | |
| 69 | template PCUIF_send_data t_SD_PCUIF_MSGT(integer id, template PCUIF_MsgType msg_type, |
| 70 | template uint8_t bts_nr := ?) := { |
| 71 | data := { |
| 72 | msg_type := msg_type, |
| 73 | bts_nr := bts_nr, |
| 74 | spare := ?, |
| 75 | u := ? |
| 76 | }, |
| 77 | id := id |
| 78 | } |
| 79 | |
| 80 | function f_pcuif_connect(PCUIF_CODEC_PT pt, charstring sock) return integer { |
| 81 | var UD_connect_result res; |
| 82 | timer T := 5.0; |
| 83 | |
| 84 | T.start; |
| 85 | pt.send(UD_connect:{sock, -1}); |
| 86 | alt { |
| 87 | [] pt.receive(UD_connect_result:?) -> value res { |
| 88 | if (ispresent(res.result) and ispresent(res.result.result_code) and |
| 89 | res.result.result_code == ERROR) { |
Pau Espin Pedrol | b1eaa6f | 2018-05-24 12:59:42 +0200 | [diff] [blame] | 90 | if (ispresent(res.result.err)) { |
Max | 68b4743 | 2019-03-14 16:30:21 +0100 | [diff] [blame] | 91 | setverdict(fail, "Error connecting to PCU socket ", sock, ": ", res.result.err); |
Pau Espin Pedrol | b1eaa6f | 2018-05-24 12:59:42 +0200 | [diff] [blame] | 92 | } else { |
Max | 68b4743 | 2019-03-14 16:30:21 +0100 | [diff] [blame] | 93 | setverdict(fail, "Error connecting to PCU socket ", sock); |
Pau Espin Pedrol | b1eaa6f | 2018-05-24 12:59:42 +0200 | [diff] [blame] | 94 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 95 | mtc.stop; |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 96 | } else { |
| 97 | return res.id; |
| 98 | } |
| 99 | } |
| 100 | [] T.timeout { |
Max | 68b4743 | 2019-03-14 16:30:21 +0100 | [diff] [blame] | 101 | setverdict(fail, "Timeout connecting to PCU socket ", sock); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 102 | mtc.stop; |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | return -23; |
| 106 | } |
| 107 | |
Harald Welte | c8effb7 | 2019-05-27 18:23:04 +0200 | [diff] [blame] | 108 | function f_pcuif_close(PCUIF_CODEC_PT pt, integer id) |
| 109 | { |
| 110 | pt.send(UD_close:{id := id}); |
| 111 | } |
| 112 | |
Harald Welte | e1fd916 | 2019-02-18 19:47:53 +0100 | [diff] [blame] | 113 | function f_pcuif_listen(PCUIF_CODEC_PT pt, charstring sock) return integer { |
| 114 | var UD_listen_result res; |
| 115 | var UD_connected udc; |
| 116 | timer T := 5.0; |
| 117 | |
| 118 | pt.send(UD_listen:{sock}); |
| 119 | T.start; |
| 120 | alt { |
| 121 | [] pt.receive(UD_listen_result:?) -> value res { |
| 122 | if (ispresent(res.result) and ispresent (res.result.result_code) and |
| 123 | res.result.result_code == ERROR) { |
| 124 | if (ispresent(res.result.err)) { |
Max | 68b4743 | 2019-03-14 16:30:21 +0100 | [diff] [blame] | 125 | setverdict(fail, "Error listening on PCU socket ", sock, ": ", res.result.err); |
Harald Welte | e1fd916 | 2019-02-18 19:47:53 +0100 | [diff] [blame] | 126 | } else { |
Max | 68b4743 | 2019-03-14 16:30:21 +0100 | [diff] [blame] | 127 | setverdict(fail, "Error listening on PCU socket ", sock); |
Harald Welte | e1fd916 | 2019-02-18 19:47:53 +0100 | [diff] [blame] | 128 | } |
| 129 | mtc.stop; |
| 130 | } else { |
| 131 | return res.id; |
| 132 | } |
| 133 | } |
| 134 | [] T.timeout { |
Max | 68b4743 | 2019-03-14 16:30:21 +0100 | [diff] [blame] | 135 | setverdict(fail, "Timeout waiting for PCU socket ", sock, " connection"); |
Harald Welte | e1fd916 | 2019-02-18 19:47:53 +0100 | [diff] [blame] | 136 | mtc.stop; |
| 137 | } |
| 138 | } |
| 139 | return -23; |
| 140 | } |
| 141 | |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 142 | function f_PCUIF_tx_imm_ass_pch(PCUIF_CODEC_PT pt, integer conn_id, octetstring imm_ass, hexstring imsi, |
Philipp Maier | 83697dd | 2023-08-08 17:23:19 +0200 | [diff] [blame] | 143 | uint8_t bts_nr := 0, boolean wait_for_cnf := true, OCT4 msg_id := '01020304'O) { |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 144 | var PCUIF_send_data sd; |
| 145 | timer T := 3.0; |
Philipp Maier | 3b4abb8 | 2023-06-23 16:27:46 +0200 | [diff] [blame] | 146 | |
| 147 | if (mp_pcuif_version < 11) { |
| 148 | /* append 3 last imsi digits so that the BTS is able to compute paging group */ |
| 149 | var hexstring last_digits := substr(imsi, lengthof(imsi)-3, 3); |
| 150 | log("3 last imsi digits: ", last_digits); |
| 151 | var octetstring prefix := ''O; |
| 152 | for (var integer i := 0; i < 3; i := i+1) { |
| 153 | prefix := prefix & int2oct(hex2int('30'H) + hex2int(last_digits[i]), 1); |
| 154 | } |
| 155 | pt.send(t_SD_PCUIF(conn_id, |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 156 | ts_PCUIF_DATA_REQ(bts_nr, 0, 0, 0, 0, PCU_IF_SAPI_PCH, prefix & imm_ass))); |
Philipp Maier | 3b4abb8 | 2023-06-23 16:27:46 +0200 | [diff] [blame] | 157 | } else { |
Philipp Maier | e683828 | 2023-08-10 15:22:43 +0200 | [diff] [blame] | 158 | var PCUIF_pch pch; |
| 159 | pch.msg_id := msg_id; |
| 160 | pch.imsi := hex2str(imsi); |
| 161 | pch.data := imm_ass; |
Philipp Maier | 0221248 | 2023-08-24 13:13:10 +0200 | [diff] [blame^] | 162 | pch.confirm := true; |
Philipp Maier | e683828 | 2023-08-10 15:22:43 +0200 | [diff] [blame] | 163 | pt.send(t_SD_PCUIF(conn_id, ts_PCUIF_DATA_REQ(bts_nr, 0, 0, 0, 0, PCU_IF_SAPI_PCH_2, enc_PCUIF_pch(pch)))); |
Philipp Maier | 3b4abb8 | 2023-06-23 16:27:46 +0200 | [diff] [blame] | 164 | } |
Philipp Maier | ca05827 | 2021-06-23 10:35:23 +0200 | [diff] [blame] | 165 | |
| 166 | /* Exit early when the caller is not interested in the confirmation message */ |
| 167 | if (wait_for_cnf == false) { |
Philipp Maier | 83697dd | 2023-08-08 17:23:19 +0200 | [diff] [blame] | 168 | return; |
Philipp Maier | ca05827 | 2021-06-23 10:35:23 +0200 | [diff] [blame] | 169 | } |
| 170 | |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 171 | T.start; |
| 172 | alt { |
Philipp Maier | 3b4abb8 | 2023-06-23 16:27:46 +0200 | [diff] [blame] | 173 | [] pt.receive(t_SD_PCUIF(conn_id, tr_PCUIF_DATA_CNF(bts_nr, 0, 0, PCU_IF_SAPI_PCH))) -> value sd { |
| 174 | if (mp_pcuif_version >= 11) { |
Philipp Maier | e683828 | 2023-08-10 15:22:43 +0200 | [diff] [blame] | 175 | setverdict(fail, "expecting tr_PCUIF_DATA_CNF_2 in PCUIF v.11 or later"); |
Philipp Maier | 3b4abb8 | 2023-06-23 16:27:46 +0200 | [diff] [blame] | 176 | mtc.stop; |
| 177 | } else { |
Philipp Maier | a4f465a | 2023-08-03 12:05:14 +0200 | [diff] [blame] | 178 | log("IMM.ASS was sent on PCH at fn ", sd.data.u.data_cnf.fn); |
Philipp Maier | 83697dd | 2023-08-08 17:23:19 +0200 | [diff] [blame] | 179 | return; |
Philipp Maier | 3b4abb8 | 2023-06-23 16:27:46 +0200 | [diff] [blame] | 180 | } |
| 181 | } |
Philipp Maier | e683828 | 2023-08-10 15:22:43 +0200 | [diff] [blame] | 182 | [] pt.receive(t_SD_PCUIF(conn_id, tr_PCUIF_DATA_CNF_2(bts_nr, PCU_IF_SAPI_PCH_2))) -> value sd { |
Philipp Maier | 3b4abb8 | 2023-06-23 16:27:46 +0200 | [diff] [blame] | 183 | if (mp_pcuif_version < 11) { |
| 184 | setverdict(fail, "expecting tr_PCUIF_DATA_CNF in PCUIF v.10 or earlier"); |
| 185 | mtc.stop; |
| 186 | } else { |
Philipp Maier | 83697dd | 2023-08-08 17:23:19 +0200 | [diff] [blame] | 187 | log("IMM.ASS was sent on PCH"); |
| 188 | return; |
Philipp Maier | 3b4abb8 | 2023-06-23 16:27:46 +0200 | [diff] [blame] | 189 | } |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 190 | } |
| 191 | [] pt.receive { repeat; } |
| 192 | [] T.timeout { |
Philipp Maier | a4f465a | 2023-08-03 12:05:14 +0200 | [diff] [blame] | 193 | setverdict(fail, "Timeout waiting for PCU DATA.cnf (PCH)"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 194 | mtc.stop; |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 195 | } |
| 196 | } |
Harald Welte | 883340c | 2018-02-28 18:59:29 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | } |