Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 1 | module BSSGP_Emulation { |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 2 | |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 3 | /* BSSGP Emulation in TTCN-3 |
Harald Welte | f536524 | 2021-01-17 13:46:57 +0100 | [diff] [blame] | 4 | * (C) 2018-2021 Harald Welte <laforge@gnumonks.org> |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 5 | * All rights reserved. |
| 6 | * |
| 7 | * Released under the terms of GNU General Public License, Version 2 or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0-or-later |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 11 | * |
| 12 | * This code implements BSSGP asa hierarchy of components: |
| 13 | * - the main BSSGP_CT which runs on top of a NSE (NS Entity). |
| 14 | * - demultiplex based on BVCI. BVCI=0 is handled to a user port |
| 15 | * - a per-BVC BSSGP_BVC_CT which runs on top of BSSGP_CT, it handles |
| 16 | * one PTP BVCI (i.e. one cell) |
| 17 | * - demultiplex based on TLLI |
| 18 | * - a per-TLLI BSSGP_Client_CT which runs on top of BSSGP_BVC_CT |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 21 | import from General_Types all; |
| 22 | import from Osmocom_Types all; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 23 | import from NS_Types all; |
| 24 | import from NS_Emulation all; |
| 25 | import from BSSGP_Types all; |
| 26 | import from Osmocom_Gb_Types all; |
| 27 | import from IPL4asp_Types all; |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 28 | |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 29 | #ifdef BSSGP_EM_L3 |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 30 | import from MobileL3_GMM_SM_Types all; |
| 31 | import from MobileL3_Types all; |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 32 | #endif |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 33 | |
| 34 | import from LLC_Types all; |
| 35 | import from LLC_Templates all; |
| 36 | |
Harald Welte | a2526a8 | 2018-02-18 19:03:36 +0100 | [diff] [blame] | 37 | import from SNDCP_Types all; |
| 38 | |
Harald Welte | 12d19b8 | 2020-10-09 11:41:06 +0200 | [diff] [blame] | 39 | |
| 40 | modulepar { |
| 41 | /* tolerate CellID absence/presence in BVC-RESET in violation to spec */ |
| 42 | boolean mp_tolerate_bvc_reset_cellid := false; |
| 43 | } |
| 44 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 45 | /*********************************************************************** |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 46 | * Communication between Client Components and per-BVC component |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 47 | ***********************************************************************/ |
| 48 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 49 | type record BssgpStatusIndication { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 50 | Nsei nsei optional, |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 51 | BssgpBvci bvci, |
| 52 | BvcState state |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | type record BssgpResetIndication { |
| 56 | BssgpBvci bvci |
| 57 | }; |
| 58 | |
| 59 | template (value) BssgpStatusIndication |
| 60 | ts_BssgpStsInd(template (omit) Nsei nsei, template (value) BssgpBvci bvci, |
| 61 | template (value) BvcState state) := { |
| 62 | nsei := nsei, |
| 63 | bvci := bvci, |
| 64 | state := state |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 67 | template (present) BssgpStatusIndication |
| 68 | tr_BssgpStsInd(template Nsei nsei, template (present) BssgpBvci bvci, |
| 69 | template (present) BvcState state) := { |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 70 | nsei := nsei, |
| 71 | bvci := bvci, |
| 72 | state := state |
| 73 | } |
| 74 | |
| 75 | type enumerated BvcState { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 76 | /* SGSN role: waiting to be reset by the peer */ |
| 77 | BVC_S_WAIT_RESET, |
| 78 | /* PCU role: waiting for NS_ALIVE_UNBLOCKED */ |
| 79 | BVC_S_WAIT_NS_ALIVE_UNBLOCKED, |
| 80 | /* BVC-BLOCKED state */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 81 | BVC_S_BLOCKED, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 82 | /* BVC-UNBLOCKED state */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 83 | BVC_S_UNBLOCKED |
| 84 | }; |
| 85 | |
| 86 | /* port from our (internal) point of view */ |
| 87 | type port BSSGP_SP_PT message { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 88 | in PDU_BSSGP, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 89 | PDU_LLC |
| 90 | #ifdef BSSGP_EM_L3 |
| 91 | , |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 92 | PDU_L3_MS_SGSN, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 93 | PDU_L3_SGSN_MS |
| 94 | #endif |
| 95 | ; |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 96 | out PDU_BSSGP, |
| 97 | PDU_LLC, |
| 98 | PDU_SN, |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 99 | NsStatusIndication, |
| 100 | BssgpStatusIndication, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 101 | ASP_Event |
| 102 | #ifdef BSSGP_EM_L3 |
| 103 | , |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 104 | PDU_L3_MS_SGSN, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 105 | PDU_L3_SGSN_MS |
| 106 | #endif |
| 107 | ; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 108 | } with { extension "internal" }; |
| 109 | |
| 110 | /* port from the user point of view */ |
| 111 | type port BSSGP_PT message { |
| 112 | in ASP_Event, |
| 113 | NsStatusIndication, |
| 114 | BssgpStatusIndication, |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 115 | PDU_BSSGP, |
| 116 | PDU_LLC, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 117 | PDU_SN |
| 118 | #ifdef BSSGP_EM_L3 |
| 119 | , |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 120 | PDU_L3_MS_SGSN, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 121 | PDU_L3_SGSN_MS |
| 122 | #endif |
| 123 | ; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 124 | out PDU_BSSGP, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 125 | PDU_LLC |
| 126 | #ifdef BSSGP_EM_L3 |
| 127 | , |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 128 | PDU_L3_SGSN_MS, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 129 | PDU_L3_MS_SGSN |
| 130 | #endif |
| 131 | ; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 132 | } with { extension "internal" }; |
| 133 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 134 | signature BSSGP_register_client(hexstring imsi, OCT4 tlli); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 135 | signature BSSGP_unregister_client(hexstring imsi); |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 136 | signature BSSGP_llgmm_assign(OCT4 tlli_old, OCT4 tlli); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 137 | |
| 138 | type port BSSGP_PROC_PT procedure { |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 139 | inout BSSGP_register_client, BSSGP_unregister_client, BSSGP_llgmm_assign; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 140 | } with { extension "internal" }; |
| 141 | |
| 142 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 143 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 144 | /*********************************************************************** |
| 145 | * Client Component for a single MS/TLLI |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 146 | *********************************************************************** |
| 147 | * This is what most users will want to derive their test cases from. It |
| 148 | * provides a set of three different ports (PTP, signaling, procedure) |
| 149 | * for (currently up to 3) different Cells. Those ports are all connected |
| 150 | * to one or multiple different per-BVC compoennts, depending on whether |
| 151 | * they share the same BSS or not. |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 152 | ***********************************************************************/ |
| 153 | |
| 154 | type component BSSGP_Client_CT { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 155 | /* one port array for each client; allows talking to up to 3 BVC/Cell (handover, ...) */ |
| 156 | port BSSGP_PT BSSGP[3]; /* PTP-BVC */ |
| 157 | port BSSGP_PT BSSGP_SIG[3]; /* Signaling BVC */ |
Harald Welte | 9b461a9 | 2020-12-10 23:41:14 +0100 | [diff] [blame] | 158 | port BSSGP_PT BSSGP_GLOBAL[3]; /* Signaling BVC */ |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 159 | port BSSGP_PROC_PT BSSGP_PROC[3]; /* registration / deregistration */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 160 | }; |
| 161 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 162 | function f_bssgp_client_register(hexstring imsi, OCT4 tlli, BSSGP_PROC_PT PT := BSSGP_PROC[0]) |
| 163 | runs on BSSGP_Client_CT { |
| 164 | PT.call(BSSGP_register_client:{imsi, tlli}) { |
| 165 | [] PT.getreply(BSSGP_register_client:{imsi, tlli}) {}; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | function f_bssgp_client_unregister(hexstring imsi, BSSGP_PROC_PT PT := BSSGP_PROC[0]) |
| 170 | runs on BSSGP_Client_CT { |
| 171 | PT.call(BSSGP_unregister_client:{imsi}) { |
| 172 | [] PT.getreply(BSSGP_unregister_client:{imsi}) {}; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | /* TS 44.064 7.2.1.1 LLGMM-ASSIGN */ |
| 177 | function f_bssgp_client_llgmm_assign(OCT4 tlli_old, OCT4 tlli_new, BSSGP_PROC_PT PT := BSSGP_PROC[0]) |
| 178 | runs on BSSGP_Client_CT { |
| 179 | PT.call(BSSGP_llgmm_assign:{tlli_old, tlli_new}) { |
| 180 | [] PT.getreply(BSSGP_llgmm_assign:{tlli_old, tlli_new}) {}; |
| 181 | } |
| 182 | } |
| 183 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 184 | /*********************************************************************** |
| 185 | * Main Component |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 186 | *********************************************************************** |
| 187 | * This component exists once, and it runs on to of the NS_Emulation. |
| 188 | * It handles the BVC-RESET for the signaling BVCI, and dispatches messages |
| 189 | * to the per-BVC components running above it. Messages are routed by: |
| 190 | * - PTP BVCI in NS header (if non-0) |
| 191 | * - BVCI IE in messages on BVCI=0 in NS header |
| 192 | * Messages for which no unique BVC can be identified (like paging without |
| 193 | * a BVCI IE set) are broadcast to all BVC components. |
| 194 | * We also broadcast state changes (BssgpStatusIndication) and reset events |
| 195 | * (BssgpResetIndication) of the signaling BVC to all per-BVC components. |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 196 | ***********************************************************************/ |
| 197 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 198 | function BssgpStart(BssgpConfig cfg, charstring id) runs on BSSGP_CT { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 199 | g_cfg := cfg; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 200 | |
| 201 | /* create the per-BVC components based on the configuration */ |
| 202 | for (var integer i := 0; i < lengthof(g_cfg.bvc); i := i+1) { |
| 203 | var BssgpBvcConfig bvc_cfg := g_cfg.bvc[i]; |
| 204 | var charstring bvc_id := id & "-BVCI" & int2str(bvc_cfg.bvci); |
| 205 | /* create, connect and start the BVC component */ |
| 206 | var BSSGP_BVC_CT bvc_ct := BSSGP_BVC_CT.create(bvc_id); |
| 207 | connect(bvc_ct:BVC, self:BVC); |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 208 | bvc_ct.start(f_bssgp_bvc_main(bvc_cfg, g_cfg.sgsn_role, g_cfg.nsei, bvc_id)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 209 | /* populate the BVC state table */ |
| 210 | BvcTable[i] := { |
| 211 | bvci := bvc_cfg.bvci, |
| 212 | cell_id := bvc_cfg.cell_id, |
| 213 | comp_ref := bvc_ct |
| 214 | }; |
| 215 | } |
| 216 | |
| 217 | if (g_cfg.sgsn_role) { |
| 218 | /* The SGSN side waits for an inbound BVC-RESET on the signaling BVC */ |
| 219 | f_sign_change_state(BVC_S_WAIT_RESET); |
| 220 | } else { |
| 221 | /* The BSS/PCU side waits for an inbound NsStatusIndication to Tx BVC-RESET */ |
| 222 | f_sign_change_state(BVC_S_WAIT_NS_ALIVE_UNBLOCKED); |
| 223 | } |
| 224 | |
| 225 | /* main loop */ |
| 226 | f_bssgp_ScanEvents(); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 227 | } |
| 228 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 229 | /* master component, exists once per BSSGP instance (NSE) */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 230 | type component BSSGP_CT { |
Stefan Sperling | f82bbb6 | 2018-05-03 19:14:28 +0200 | [diff] [blame] | 231 | /* UDP ports towards the bottom (IUT) */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 232 | port NS_PT BSCP; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 233 | |
| 234 | /* control by the user */ |
| 235 | port BSSGP_CT_PROC_PT PROC; |
| 236 | |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 237 | /* global port for procedures without any relation to a BVC |
| 238 | * (currently only) SUSPEND/RESUME */ |
| 239 | port BSSGP_SP_PT GLOBAL; |
| 240 | |
Harald Welte | 0083ea6 | 2020-12-02 21:30:44 +0100 | [diff] [blame] | 241 | /* RAN INFORMATION MGMT */ |
| 242 | port BSSGP_SP_PT RIM; |
| 243 | |
Harald Welte | bdf96d8 | 2020-11-27 18:58:46 +0100 | [diff] [blame] | 244 | /* port to a management instance */ |
| 245 | port BSSGP_BVC_MGMT_SP_PT MGMT; |
| 246 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 247 | var BssgpConfig g_cfg; |
| 248 | |
| 249 | /* Signaling BVC (BVCI=0) */ |
| 250 | var BvcState g_sign_bvc_state := BVC_S_WAIT_RESET; |
| 251 | timer g_T2 := 60.0; |
| 252 | |
| 253 | /* port to per-BVC components */ |
| 254 | port BSSGP_BVC_SP_PT BVC; |
| 255 | /* per-BVC state table */ |
Harald Welte | 633805b | 2021-02-03 17:47:18 +0100 | [diff] [blame] | 256 | var BvcEntity BvcTable[64]; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 257 | }; |
| 258 | |
| 259 | /* one element in the per-BVC state table */ |
| 260 | type record BvcEntity { |
| 261 | /* PTP BVCI of this BVC/Cell */ |
| 262 | BssgpBvci bvci, |
| 263 | /* Cell Identity of this cell */ |
| 264 | BssgpCellId cell_id, |
| 265 | /* reference to the per-BVC/cell component */ |
| 266 | BSSGP_BVC_CT comp_ref |
| 267 | }; |
| 268 | |
| 269 | /* find the per-BVC component for a given BVCI */ |
| 270 | private function f_comp_for_bvci(BssgpBvci bvci) runs on BSSGP_CT return BSSGP_BVC_CT { |
| 271 | var integer i; |
| 272 | |
| 273 | for (i := 0; i < lengthof(BvcTable); i := i+1) { |
| 274 | if (BvcTable[i].bvci == bvci) { |
| 275 | return BvcTable[i].comp_ref; |
| 276 | } |
| 277 | } |
| 278 | return null; |
| 279 | } |
| 280 | |
| 281 | /* We are in BVC_S_WAIT_RSET state (only happens in SGSN role) */ |
| 282 | altstep as_sig_wait_reset() runs on BSSGP_CT { |
| 283 | var NsUnitdataIndication udi; |
| 284 | |
| 285 | /* Respond to RESET for signalling BVCI 0 */ |
| 286 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi { |
| 287 | log("Rx BVC-RESET for Signaling BVCI=0"); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 288 | f_sign_change_state(BVC_S_UNBLOCKED); |
Harald Welte | bdf96d8 | 2020-11-27 18:58:46 +0100 | [diff] [blame] | 289 | if (MGMT.checkstate("Connected")) { |
| 290 | MGMT.send(BssgpResetIndication:{0}); |
| 291 | } |
| 292 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* work-around for old, buggy libosmogb before Change-Id Ie87820537d6d616da4fd4bbf73eab06e28fda5e1 */ |
| 296 | [mp_tolerate_bvc_reset_cellid] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, g_cfg.bvc[0].cell_id), 0)) -> value udi { |
| 297 | log("Rx BVC-RESET for Signaling BVCI=0"); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 298 | f_sign_change_state(BVC_S_UNBLOCKED); |
Harald Welte | bdf96d8 | 2020-11-27 18:58:46 +0100 | [diff] [blame] | 299 | if (MGMT.checkstate("Connected")) { |
| 300 | MGMT.send(BssgpResetIndication:{0}); |
| 301 | } |
| 302 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
Harald Welte | 27a70cc | 2020-12-09 11:57:41 +0100 | [diff] [blame] | 306 | private template PDU_BSSGP tr_GLOBAL_SIG := ( |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 307 | {pDU_BSSGP_SUSPEND:=?}, {pDU_BSSGP_SUSPEND_ACK:=?}, {pDU_BSSGP_SUSPEND_NACK:=?}, |
Harald Welte | f8e5c5d | 2020-11-27 22:37:23 +0100 | [diff] [blame] | 308 | {pDU_BSSGP_RESUME:=?}, {pDU_BSSGP_RESUME_ACK:=?}, {pDU_BSSGP_RESUME_NACK:=?}, |
Harald Welte | f536524 | 2021-01-17 13:46:57 +0100 | [diff] [blame] | 309 | {pDU_BSSGP_SGSN_INVOKE_TRACE:=?}, {pDU_BSSGP_OVERLOAD:=?}, {pDU_BSSGP_STATUS:=?} |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 310 | ); |
| 311 | |
Harald Welte | 0083ea6 | 2020-12-02 21:30:44 +0100 | [diff] [blame] | 312 | /* BSSGP messages that should arrive on the RIM port */ |
| 313 | private template PDU_BSSGP tr_RIM := ( |
| 314 | {pDU_BSSGP_RAN_INFORMATION:=?}, {pDU_BSSGP_RAN_INFORMATION_REQUEST:=?}, |
| 315 | {pDU_BSSGP_RAN_INFORMATION_ACK:=?}, {pDU_BSSGP_RAN_INFORMATION_ERROR:=?}, |
| 316 | {pDU_BSSGP_RAN_INFORMATION_APPLICATION_ERROR:=?} |
| 317 | ); |
| 318 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 319 | /* We are in BVC_S_UNBLOCKED state */ |
| 320 | altstep as_sig_unblocked() runs on BSSGP_CT { |
| 321 | var BSSGP_BVC_CT bvc_comp_ref; |
| 322 | var BSSGP_Client_CT vc_conn; |
| 323 | var NsUnitdataIndication udi; |
| 324 | var NsUnitdataRequest udr; |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 325 | var PDU_BSSGP bssgp; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 326 | |
| 327 | /* Messages PTP BVCI in BVCI field of NS: dispatch by that */ |
| 328 | [] BSCP.receive(f_BnsUdInd(?, (2..65535))) -> value udi { |
| 329 | bvc_comp_ref := f_comp_for_bvci(valueof(udi.bvci)); |
| 330 | if (isbound(bvc_comp_ref) and bvc_comp_ref != null) { |
| 331 | /* dispatch to BVC component */ |
| 332 | BVC.send(udi) to bvc_comp_ref; |
| 333 | } else { |
| 334 | setverdict(fail, "Rx BSSGP for unknown PTP BVCI ", udi.bvci, ": ", udi.bssgp); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 335 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), udi.bvci, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
| 339 | /* Messages with BVCI = 0 (Signaling) in BVCI field of NS */ |
Harald Welte | 27a70cc | 2020-12-09 11:57:41 +0100 | [diff] [blame] | 340 | [] BSCP.receive(f_BnsUdInd(tr_GLOBAL_SIG, 0)) -> value udi { |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 341 | GLOBAL.send(udi.bssgp); |
| 342 | } |
Harald Welte | 0083ea6 | 2020-12-02 21:30:44 +0100 | [diff] [blame] | 343 | [] BSCP.receive(f_BnsUdInd(tr_RIM, 0)) -> value udi { |
| 344 | if (RIM.checkstate("Connected")) { |
| 345 | RIM.send(udi.bssgp); |
| 346 | } |
| 347 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 348 | |
| 349 | /* Route based on PTP BVCI in payload/IE of signaling PDU */ |
| 350 | [] BSCP.receive(f_BnsUdInd(?, 0)) -> value udi { |
| 351 | var template (omit) BssgpBvci ptp_bvci := f_BSSGP_BVCI_get(udi.bssgp); |
| 352 | if (istemplatekind(ptp_bvci, "omit")) { |
| 353 | log("Rx on SIG BVCI without PTP BVCI: broadcasting"); |
| 354 | for (var integer i := 0; i < lengthof(BvcTable); i := i+1) { |
| 355 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 356 | BVC.send(udi) to BvcTable[i].comp_ref; |
| 357 | } |
| 358 | } |
| 359 | } else { |
| 360 | bvc_comp_ref := f_comp_for_bvci(valueof(ptp_bvci)); |
| 361 | if (isbound(bvc_comp_ref) and bvc_comp_ref != null) { |
| 362 | /* dispatch to BVC component */ |
| 363 | BVC.send(udi) to bvc_comp_ref; |
| 364 | } else { |
| 365 | setverdict(fail, "Rx SIG BSSGP for unknown PTP BVCI ", ptp_bvci, ": ", udi.bssgp); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 366 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | /* Handle PS-PAGING on SIGN BVCI with no conditional BVCI IE */ |
| 372 | [] BSCP.receive(f_BnsUdInd(PDU_BSSGP:{pDU_BSSGP_PAGING_PS:=?}, 0)) -> value udi { |
| 373 | /* FIXME: use LA, RA or BSS Area to dispatch instead of broadcast */ |
| 374 | for (var integer i := 0; i < lengthof(BvcTable); i := i+1) { |
| 375 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 376 | BVC.send(udi) to BvcTable[i].comp_ref; |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | /* Handle CS-PAGING on SIGN BVCI with no conditional BVCI IE */ |
| 381 | [] BSCP.receive(f_BnsUdInd(PDU_BSSGP:{pDU_BSSGP_PAGING_CS:=?}, 0)) -> value udi { |
| 382 | /* FIXME: use LA, RA or BSS Area to dispatch instead of broadcast */ |
| 383 | for (var integer i := 0; i < lengthof(BvcTable); i := i+1) { |
| 384 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 385 | BVC.send(udi) to BvcTable[i].comp_ref; |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | /* per-BVC component sends us something; forward to NS without any validation */ |
| 391 | [] BVC.receive(NsUnitdataRequest:?) -> value udr { |
| 392 | /* patch in the NSEI, as the per-BVC components have no idea about it */ |
| 393 | udr.nsei := g_cfg.nsei; |
| 394 | BSCP.send(udr); |
| 395 | } |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 396 | |
Harald Welte | 27a70cc | 2020-12-09 11:57:41 +0100 | [diff] [blame] | 397 | [] GLOBAL.receive(tr_GLOBAL_SIG) -> value bssgp { |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 398 | BSCP.send(f_BnsUdReq(bssgp, 0, 0)); |
| 399 | } |
Harald Welte | 0083ea6 | 2020-12-02 21:30:44 +0100 | [diff] [blame] | 400 | |
| 401 | [] RIM.receive(tr_RIM) -> value bssgp { |
| 402 | BSCP.send(f_BnsUdReq(bssgp, 0, 0)); |
| 403 | } |
| 404 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /* We are in BVC_S_WAIT_NS_ALIVE_UNBLOCKED (only happens in BSS role) */ |
| 408 | altstep as_sig_wait_ns_alive_unblocked() runs on BSSGP_CT { |
| 409 | var NsStatusIndication nsi; |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 410 | [] BSCP.receive(NsStatusIndication:{g_cfg.nsei,?, complement (NSVC_S_ALIVE_UNBLOCKED), NSVC_S_ALIVE_UNBLOCKED, true}) -> value nsi { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 411 | /* if we just became NS-unblocked, send a BCC-RESET */ |
| 412 | if (g_cfg.sgsn_role == false) { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 413 | BSCP.send(f_BnsUdReq(ts_BVC_RESET(BSSGP_CAUSE_OM_INTERVENTION, 0, omit), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 414 | g_T2.start; |
| 415 | /* The BVC_RESET_ACK is handled in the as_sig_allstate() below */ |
| 416 | } |
| 417 | /* Idea: We could send BVC-UNBLOCK here like some SGSN do */ |
| 418 | } |
| 419 | |
| 420 | } |
| 421 | |
Harald Welte | e588792 | 2020-11-27 19:04:46 +0100 | [diff] [blame] | 422 | /* handling of events irrespective of BVC state (before state-specific handling) */ |
| 423 | altstep as_sig_allstate_pre() runs on BSSGP_CT { |
| 424 | var NsUnitdataIndication udi; |
| 425 | |
| 426 | /* Respond to RESET for signalling BVCI 0 */ |
| 427 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi { |
| 428 | log("Rx BVC-RESET for Signaling BVCI=0"); |
| 429 | if (MGMT.checkstate("Connected")) { |
| 430 | MGMT.send(BssgpResetIndication:{0}); |
| 431 | } |
| 432 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0)); |
| 433 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 434 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 435 | BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref; |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | /* any BLOCK or UNBLOCK for the SIGNALING BVCI are illegal */ |
| 441 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(0, ?), 0)) -> value udi { |
| 442 | setverdict(fail, "Rx BVC-BLOCK illegal for BVCI=0: ", udi); |
| 443 | } |
| 444 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK(0), 0)) -> value udi { |
| 445 | setverdict(fail, "Rx BVC-UNBLOCK illegal for BVCI=0: ", udi); |
| 446 | } |
| 447 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK_ACK(0), 0)) -> value udi { |
| 448 | setverdict(fail, "Rx BVC-BLOCK-ACK illegal for BVCI=0: ", udi); |
| 449 | } |
| 450 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK_ACK(0), 0)) -> value udi { |
| 451 | setverdict(fail, "Rx BVC-UNBLOCK-ACK illegal for BVCI=0: ", udi); |
| 452 | } |
| 453 | |
| 454 | /* BVC-RESET-ACK for BVCI=0 while T2 is running: Answer to a BVC-RESET we sent earlier */ |
| 455 | [g_T2.running] BSCP.receive(f_BnsUdInd(tr_BVC_RESET_ACK(0, omit), 0)) -> value udi { |
| 456 | log("BVCI(0) Rx BVC-RESET-ACK"); |
| 457 | g_T2.stop; |
| 458 | f_sign_change_state(BVC_S_UNBLOCKED); |
| 459 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 460 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 461 | BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref; |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | [] g_T2.timeout { |
| 466 | setverdict(fail, "Timeout waiting for BVC-RESET-ACK on BVCI=0"); |
| 467 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0)); |
| 468 | g_T2.start; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | /* handling of events irrespective of BVC state (after state-specific handling) */ |
| 473 | altstep as_sig_allstate_post() runs on BSSGP_CT { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 474 | var BSSGP_Client_CT vc_conn; |
| 475 | var NsUnitdataIndication udi; |
| 476 | var NsStatusIndication nsi; |
| 477 | var ASP_Event evt; |
| 478 | var BSSGP_BVC_CT bvc_comp_ref; |
| 479 | var BssgpBvci bvci; |
Harald Welte | e588792 | 2020-11-27 19:04:46 +0100 | [diff] [blame] | 480 | var BssgpResetRequest brr; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 481 | |
| 482 | /* Respond to RESET for signalling BVCI 0 */ |
| 483 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi { |
| 484 | log("Rx BVC-RESET for Signaling BVCI=0"); |
Harald Welte | bdf96d8 | 2020-11-27 18:58:46 +0100 | [diff] [blame] | 485 | if (MGMT.checkstate("Connected")) { |
| 486 | MGMT.send(BssgpResetIndication:{0}); |
| 487 | } |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 488 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 489 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 490 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 491 | BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref; |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | /* any BLOCK or UNBLOCK for the SIGNALING BVCI are illegal */ |
| 497 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(0, ?), 0)) -> value udi { |
| 498 | setverdict(fail, "Rx BVC-BLOCK illegal for BVCI=0: ", udi); |
| 499 | } |
| 500 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK(0), 0)) -> value udi { |
| 501 | setverdict(fail, "Rx BVC-UNBLOCK illegal for BVCI=0: ", udi); |
| 502 | } |
| 503 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK_ACK(0), 0)) -> value udi { |
| 504 | setverdict(fail, "Rx BVC-BLOCK-ACK illegal for BVCI=0: ", udi); |
| 505 | } |
| 506 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK_ACK(0), 0)) -> value udi { |
| 507 | setverdict(fail, "Rx BVC-UNBLOCK-ACK illegal for BVCI=0: ", udi); |
| 508 | } |
| 509 | |
| 510 | /* Respond to BLOCK for wrong BVCI */ |
| 511 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(?, ?), 0)) -> value udi { |
| 512 | setverdict(fail, "Rx BVC-BLOCK for unknown BVCI"); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 513 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(0, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | /* Respond to RESET with wrong BVCI */ |
| 517 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, ?, ?), 0)) -> value udi { |
| 518 | var BssgpBvci ptp_bvci := oct2int(udi.bssgp.pDU_BSSGP_BVC_RESET.bVCI.unstructured_value); |
| 519 | setverdict(fail, "Rx BVC-RESET for unknown BVCI ", ptp_bvci); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 520 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(ptp_bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 521 | } |
| 522 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 523 | /* Forwarding of ASP_Event to per-BVC components */ |
| 524 | [] BSCP.receive(ASP_Event:?) -> value evt { |
| 525 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 526 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 527 | BVC.send(evt) to BvcTable[i].comp_ref; |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | /* Keep NS Status Indicaitons to us; no need to inform per-BVC components [for now?] */ |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 532 | [] BSCP.receive(tr_NsStsInd(g_cfg.nsei)) -> value nsi { } |
Harald Welte | 445fc61 | 2020-11-10 19:15:30 +0100 | [diff] [blame] | 533 | /* We should never see any different NSEI: There's one BSSGP_CT per NSE */ |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 534 | [] BSCP.receive(tr_NsStsInd(?)) -> value nsi { |
Harald Welte | 445fc61 | 2020-11-10 19:15:30 +0100 | [diff] [blame] | 535 | setverdict(fail, "Rx NsStatusInd for wrong NSEI ", nsi); |
| 536 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 537 | |
| 538 | /* Procedure port request to resolve the per-BVC component for a given ptp BVCI */ |
| 539 | [] PROC.getcall(BSSGP_get_bvci_ct:{?}) -> param(bvci) sender vc_conn { |
| 540 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 541 | if (BvcTable[i].bvci == bvci) { |
| 542 | PROC.reply(BSSGP_get_bvci_ct:{bvci} value BvcTable[i].comp_ref) to vc_conn; |
| 543 | return; |
| 544 | } |
| 545 | } |
| 546 | } |
Harald Welte | e588792 | 2020-11-27 19:04:46 +0100 | [diff] [blame] | 547 | |
| 548 | /* default case of handling unknown PDUs */ |
| 549 | [] BSCP.receive(f_BnsUdInd(?, ?)) -> value udi { |
| 550 | setverdict(fail, "Rx Unexpected BSSGP PDU ", udi.bssgp," in state ", g_sign_bvc_state); |
| 551 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(0, BSSGP_CAUSE_PDU_NOT_COMPATIBLE_WITH_PROTOCOL_STATE, udi.bssgp), 0, 0)); |
| 552 | } |
| 553 | |
| 554 | [] MGMT.receive(BssgpResetRequest:?) -> value brr { |
| 555 | BSCP.send(f_BnsUdReq(ts_BVC_RESET(brr.cause, 0, omit), 0, 0)); |
| 556 | g_T2.start; |
| 557 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /* send the highest decoded layer of the message through given port */ |
| 561 | private function f_send_bssgp_dec(BssgpDecoded dec, BSSGP_Client_CT vc_conn, BSSGP_SP_PT pt) { |
| 562 | #ifdef BSSGP_EM_L3 |
| 563 | if (ispresent(dec.l3_mt)) { |
| 564 | pt.send(dec.l3_mt) to vc_conn; |
| 565 | } else if (ispresent(dec.l3_mo)) { |
| 566 | pt.send(dec.l3_mo) to vc_conn; |
| 567 | } else |
| 568 | #endif |
| 569 | if (ispresent(dec.sndcp)) { |
| 570 | pt.send(dec.sndcp) to vc_conn; |
| 571 | } else if (ispresent(dec.llc)) { |
| 572 | pt.send(dec.llc) to vc_conn; |
| 573 | } else { |
| 574 | pt.send(dec.bssgp) to vc_conn; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | |
| 579 | function f_llc_get_n_u_tx(inout LLC_Entity llc) return uint9_t { |
| 580 | var uint9_t ret := llc.n_u_tx_next; |
| 581 | llc.n_u_tx_next := llc.n_u_tx_next + 1; |
| 582 | return ret; |
| 583 | } |
| 584 | |
| 585 | #ifdef BSSGP_EM_L3 |
| 586 | function f_llc_sapi_by_l3_mo(PDU_L3_MS_SGSN l3_mo) return BIT4 { |
| 587 | if (ischosen(l3_mo.msgs.gprs_mm)) { |
| 588 | return c_LLC_SAPI_LLGMM; |
| 589 | } else if (ischosen(l3_mo.msgs.gprs_sm)) { |
| 590 | return c_LLC_SAPI_LLGMM; |
| 591 | } else if (ischosen(l3_mo.msgs.sms)) { |
| 592 | return c_LLC_SAPI_LLSMS; |
| 593 | } |
| 594 | setverdict(fail, "No LLC SAPI for ", l3_mo); |
| 595 | mtc.stop; |
| 596 | } |
| 597 | |
| 598 | private function f_llc_sapi_by_l3_mt(PDU_L3_SGSN_MS l3_mt) return BIT4 { |
| 599 | if (ischosen(l3_mt.msgs.gprs_mm)) { |
| 600 | return c_LLC_SAPI_LLGMM; |
| 601 | } else if (ischosen(l3_mt.msgs.gprs_sm)) { |
| 602 | return c_LLC_SAPI_LLGMM; |
| 603 | } else if (ischosen(l3_mt.msgs.sms)) { |
| 604 | return c_LLC_SAPI_LLSMS; |
| 605 | } |
| 606 | setverdict(fail, "No LLC SAPI for ", l3_mt); |
| 607 | mtc.stop; |
| 608 | } |
| 609 | #endif |
| 610 | |
| 611 | /* main loop of BSSGP_CT */ |
| 612 | private function f_bssgp_ScanEvents() runs on BSSGP_CT { |
| 613 | while (true) { |
| 614 | alt { |
| 615 | [g_sign_bvc_state == BVC_S_WAIT_RESET] as_sig_wait_reset(); |
Harald Welte | e588792 | 2020-11-27 19:04:46 +0100 | [diff] [blame] | 616 | [] as_sig_allstate_pre(); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 617 | [g_sign_bvc_state == BVC_S_WAIT_NS_ALIVE_UNBLOCKED] as_sig_wait_ns_alive_unblocked(); |
| 618 | [g_sign_bvc_state == BVC_S_UNBLOCKED] as_sig_unblocked(); |
Harald Welte | e588792 | 2020-11-27 19:04:46 +0100 | [diff] [blame] | 619 | [g_sign_bvc_state == BVC_S_WAIT_RESET] as_sig_wait_reset(); |
| 620 | [] as_sig_allstate_post(); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 621 | } |
| 622 | } /* while */ |
| 623 | } |
| 624 | |
| 625 | /* generate a send template. Cannot be a real template as we want to use g_cfg.nsei */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 626 | private function f_BnsUdReq(template PDU_BSSGP pdu, BssgpBvci bvci, integer lsp) |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 627 | runs on BSSGP_CT return NsUnitdataRequest { |
| 628 | var NsUnitdataRequest udr := { |
| 629 | bvci := bvci, |
| 630 | nsei := g_cfg.nsei, |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 631 | lsp := lsp, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 632 | /* for some weird reason we get "Dynamic test case error: Text encoder: Encoding an |
| 633 | * unbound integer value." when trying to send the reocrd rather than the octetstring */ |
| 634 | //sdu := omit, |
| 635 | //bssgp := valueof(pdu) |
| 636 | sdu := enc_PDU_BSSGP(valueof(pdu)), |
| 637 | bssgp := omit |
| 638 | } |
| 639 | return udr; |
| 640 | } |
| 641 | |
| 642 | /* generate a receive template. Cannot be a real template as we want to use g_cfg.nsei */ |
| 643 | private function f_BnsUdInd(template PDU_BSSGP pdu, template BssgpBvci bvci) |
| 644 | runs on BSSGP_CT return template (present) NsUnitdataIndication { |
| 645 | var template (present) NsUnitdataIndication udi := { |
| 646 | bvci := bvci, |
| 647 | nsei := g_cfg.nsei, |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 648 | nsvci := ?, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 649 | sdu := *, |
| 650 | bssgp := pdu |
| 651 | } |
| 652 | return udi; |
| 653 | } |
| 654 | |
| 655 | /* change state of signaling BVCI; notify per-BVC components */ |
| 656 | private function f_sign_change_state(BvcState new_state) runs on BSSGP_CT { |
| 657 | if (new_state == g_sign_bvc_state) { |
| 658 | return; |
| 659 | } |
| 660 | log("BVCI(0) State Transition: ", g_sign_bvc_state, " -> ", new_state); |
| 661 | g_sign_bvc_state := new_state; |
| 662 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 663 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 664 | BVC.send(ts_BssgpStsInd(g_cfg.nsei, 0, g_sign_bvc_state)) to BvcTable[i].comp_ref; |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | /* User wants to get per-BVC component reference from BSSGP_CT */ |
| 670 | signature BSSGP_get_bvci_ct(BssgpBvci bvci) return BSSGP_BVC_CT; |
| 671 | |
| 672 | type port BSSGP_CT_PROC_PT procedure { |
| 673 | inout BSSGP_get_bvci_ct |
| 674 | } with { extension "internal" }; |
| 675 | |
| 676 | /* convenience wrapper function for user */ |
| 677 | function f_bssgp_get_bvci_ct(BssgpBvci bvci, BSSGP_CT_PROC_PT PT) return BSSGP_BVC_CT { |
| 678 | var BSSGP_BVC_CT res; |
| 679 | PT.call(BSSGP_get_bvci_ct:{bvci}) { |
| 680 | [] PT.getreply(BSSGP_get_bvci_ct:{bvci})-> value res { |
| 681 | return res; |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | /*********************************************************************** |
| 687 | * per-BVC (Cell) Component |
| 688 | *********************************************************************** |
| 689 | * Any number of these components runs on top of the BSSGP_CT, each |
| 690 | * representing one PTP BVC within this NSE. Users (test cases) can |
| 691 | * register with TLLI and/or IMSI via the procedure port. |
| 692 | ***********************************************************************/ |
| 693 | |
| 694 | /* per-BVC component. Exists once per cell within a BSSGP_CT */ |
| 695 | type component BSSGP_BVC_CT { |
| 696 | /* port towards the underlying BSSGP_CT */ |
| 697 | port BSSGP_BVC_PT BVC; |
| 698 | |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 699 | /* port to a management instance */ |
| 700 | port BSSGP_BVC_MGMT_SP_PT MGMT; |
| 701 | |
Harald Welte | 71449b0 | 2020-12-09 11:58:23 +0100 | [diff] [blame] | 702 | /* per-BVC global port for e.g. BVC Flow Control */ |
| 703 | port BSSGP_SP_PT GLOBAL; |
| 704 | |
| 705 | /* BSSGP-User SAP towards the user (per-TLLI, Client) */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 706 | port BSSGP_SP_PT BSSGP_SP; |
Stefan Sperling | f82bbb6 | 2018-05-03 19:14:28 +0200 | [diff] [blame] | 707 | port BSSGP_SP_PT BSSGP_SP_SIG; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 708 | port BSSGP_PROC_PT BSSGP_PROC; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 709 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 710 | var BssgpBvcConfig g_cfg; |
| 711 | var boolean g_sgsn_role; |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 712 | var Nsei g_nsei; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 713 | |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 714 | /* default Link Selector Parameter for this BVC (for traffic unrelated to a TLLI) */ |
| 715 | var integer g_bvc_lsp; |
| 716 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 717 | var BvcState g_ptp_bvc_state := BVC_S_BLOCKED; |
| 718 | timer g_T1 := 15.0; |
| 719 | timer g_T2 := 60.0; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 720 | var boolean g_t1_waits_for_block_ack := false; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 721 | /* for re-transmissions */ |
| 722 | var BssgpCause g_last_block_cause; |
| 723 | var BssgpCause g_last_reset_cause; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 724 | |
Harald Welte | 633805b | 2021-02-03 17:47:18 +0100 | [diff] [blame] | 725 | var ClientEntity ClientTable[64]; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 726 | }; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 727 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 728 | /* port between global BSSGP_CT and per-BVC BSSGP_BVC_CT */ |
| 729 | type port BSSGP_BVC_SP_PT message { |
| 730 | in NsUnitdataRequest; |
| 731 | out ASP_Event, |
| 732 | BssgpStatusIndication, |
| 733 | BssgpResetIndication, |
| 734 | NsUnitdataIndication; |
| 735 | } with { extension "internal" }; |
| 736 | type port BSSGP_BVC_PT message { |
| 737 | in ASP_Event, |
| 738 | BssgpStatusIndication, |
| 739 | BssgpResetIndication, |
| 740 | NsUnitdataIndication; |
| 741 | out NsUnitdataRequest; |
| 742 | } with { extension "internal" }; |
Alexander Couzens | 6b449fb | 2018-07-31 14:19:36 +0200 | [diff] [blame] | 743 | |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 744 | /* port between BSSGP_BVC_CT and a management instance */ |
| 745 | type port BSSGP_BVC_MGMT_SP_PT message { |
| 746 | in BssgpResetRequest, |
| 747 | BssgpBlockRequest, |
| 748 | BssgpUnblockRequest; |
| 749 | out BssgpStatusIndication, |
| 750 | BssgpResetIndication; |
| 751 | } with { extension "internal" }; |
| 752 | type port BSSGP_BVC_MGMT_PT message { |
| 753 | in BssgpStatusIndication, |
| 754 | BssgpResetIndication; |
| 755 | out BssgpResetRequest, |
| 756 | BssgpBlockRequest, |
| 757 | BssgpUnblockRequest; |
| 758 | } with { extension "internal" }; |
| 759 | |
| 760 | type record BssgpResetRequest { |
| 761 | BssgpCause cause |
| 762 | }; |
| 763 | type record BssgpBlockRequest { |
| 764 | BssgpCause cause |
| 765 | }; |
| 766 | type record BssgpUnblockRequest { |
| 767 | }; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 768 | |
| 769 | /* one element in the per-TLLI state table */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 770 | type record ClientEntity { |
| 771 | OCT4 tlli, |
| 772 | OCT4 tlli_old optional, |
| 773 | hexstring imsi, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 774 | BSSGP_Client_CT comp_ref, |
| 775 | /* LLC entities, one for each SAPI */ |
| 776 | LLC_Entity llc[16] |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 777 | }; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 778 | type record LLC_Entity { |
| 779 | boolean sgsn_role, |
| 780 | /* N(U) on transmit side for next PDU */ |
| 781 | uint9_t n_u_tx_next, |
| 782 | /* N(U) on receive side, last PDU */ |
| 783 | uint9_t n_u_rx_last optional |
| 784 | }; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 785 | type record length(16) of LLC_Entity LLC_Entities; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 786 | |
Harald Welte | f536524 | 2021-01-17 13:46:57 +0100 | [diff] [blame] | 787 | private template PDU_BSSGP tr_GLOBAL_PTP := ( |
| 788 | {pDU_BSSGP_STATUS:=?} |
| 789 | ); |
| 790 | |
Alexander Couzens | cdfb751 | 2018-07-31 15:37:14 +0200 | [diff] [blame] | 791 | function f_llc_create(boolean sgsn_role := false) return LLC_Entities { |
| 792 | var LLC_Entities llc; |
| 793 | for (var integer i := 0; i < 16; i := i+1) { |
| 794 | llc[i] := valueof(t_LLC_init(sgsn_role)); |
| 795 | } |
| 796 | return llc; |
| 797 | } |
| 798 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 799 | private template LLC_Entity t_LLC_init(boolean sgsn_role := false) := { |
| 800 | sgsn_role := sgsn_role, |
| 801 | n_u_tx_next := 0, |
| 802 | n_u_rx_last := - |
| 803 | } |
| 804 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 805 | /* configuration of BSSGP_CT */ |
| 806 | type record BssgpConfig { |
| 807 | Nsvci nsei, |
| 808 | boolean sgsn_role, |
| 809 | BssgpBvcConfigs bvc |
| 810 | }; |
| 811 | /* Configuration of one BVC (Cell) BSSGP_BVC_CT */ |
| 812 | type record BssgpBvcConfig { |
| 813 | BssgpBvci bvci, |
| 814 | BssgpCellId cell_id, |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 815 | BssgpDecodeDepth depth, |
| 816 | BssgpCreateCallback create_cb |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 817 | }; |
| 818 | type record of BssgpBvcConfig BssgpBvcConfigs; |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 819 | type enumerated BssgpDecodeDepth { |
| 820 | BSSGP_DECODE_DEPTH_BSSGP, |
| 821 | BSSGP_DECODE_DEPTH_LLC, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 822 | BSSGP_DECODE_DEPTH_SNDCP |
| 823 | #ifdef BSSGP_EM_L3 |
| 824 | , |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 825 | BSSGP_DECODE_DEPTH_L3 |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 826 | #endif |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 827 | }; |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 828 | /* call-back function type: Called for inbound BSSGP for unknown TLLIs; could create BSSGP_ClienT_CT */ |
| 829 | type function BssgpCreateCallback(BssgpBvci bvci, BssgpCellId cell_id, OCT4 tlli, BssgpDecoded dec) runs on BSSGP_BVC_CT; |
| 830 | |
| 831 | /* Default Create Callback function: Fail and terminate */ |
| 832 | function DefaultCreateCallback(BssgpBvci bvci, BssgpCellId cell_id, OCT4 tlli, BssgpDecoded dec) runs on BSSGP_BVC_CT { |
| 833 | setverdict(fail, "Couldn't find Component for TLLI ", tlli); |
| 834 | mtc.stop; |
| 835 | } |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 836 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 837 | /* |
| 838 | private function f_tbl_init() runs on BSSGP_BVC_CT { |
| 839 | var integer i; |
| 840 | for (i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 841 | ImsiTable[i] := -; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 842 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 843 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 844 | for (i := 0; i < sizeof(TlliTable); i := i+1) { |
| 845 | TlliTable[i] := -; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 846 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 847 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 848 | */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 849 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 850 | private function f_tbl_client_add(hexstring imsi, OCT4 tlli, BSSGP_Client_CT vc_conn) |
| 851 | runs on BSSGP_BVC_CT { |
| 852 | var integer i; |
| 853 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 854 | if (not isvalue(ClientTable[i].comp_ref)) { |
| 855 | log("Adding Client=", vc_conn, ", IMSI=", imsi, ", TLLI=", tlli, ", index=", i); |
| 856 | ClientTable[i] := { |
| 857 | tlli := tlli, |
| 858 | tlli_old := omit, |
| 859 | imsi := imsi, |
| 860 | comp_ref := vc_conn, |
| 861 | llc := - |
| 862 | }; |
| 863 | for (var integer j := 0; j < sizeof(ClientTable[i].llc); j := j+1) { |
| 864 | ClientTable[i].llc[j] := valueof(t_LLC_init(g_sgsn_role)); |
| 865 | } |
| 866 | return; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 867 | } |
| 868 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 869 | testcase.stop("Client Table full"); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 870 | } |
| 871 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 872 | private function f_tbl_client_del(hexstring imsi, BSSGP_Client_CT vc_conn) runs on BSSGP_BVC_CT { |
| 873 | var integer i; |
| 874 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 875 | if (isvalue(ClientTable[i].imsi) and ClientTable[i].imsi == imsi) { |
| 876 | if (ClientTable[i].comp_ref != vc_conn) { |
| 877 | setverdict(fail, "Cannot unregister index=", i, " IMSI ", imsi, " registred to ", |
| 878 | ClientTable[i].comp_ref, " from ", vc_conn); |
| 879 | mtc.stop; |
| 880 | } |
| 881 | log("Removing Client IMSI=", imsi, ", index=", i); |
| 882 | ClientTable[i] := { |
| 883 | tlli := -, |
| 884 | tlli_old := omit, |
| 885 | imsi := ''H, |
| 886 | comp_ref := null, |
| 887 | llc := - }; |
| 888 | return; |
| 889 | } |
| 890 | } |
| 891 | log("Warning: Could not find client for IMSI ", imsi); |
| 892 | return; |
| 893 | } |
| 894 | |
| 895 | /* TS 44.064 7.2.1.1 LLGMM-ASSIGN */ |
| 896 | private function f_tbl_client_llgmm_assign(OCT4 tlli_old, OCT4 tlli_new, BSSGP_Client_CT vc_conn) |
| 897 | runs on BSSGP_BVC_CT { |
| 898 | var integer i := f_tbl_idx_by_comp(vc_conn); |
| 899 | |
| 900 | if (tlli_old == 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) { |
| 901 | /* TLLI assignment */ |
| 902 | ClientTable[i].tlli := tlli_new; |
| 903 | ClientTable[i].tlli_old := omit; |
| 904 | } else if (tlli_old != 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) { |
| 905 | /* TLLI change: both active */ |
| 906 | ClientTable[i].tlli := tlli_new; |
| 907 | ClientTable[i].tlli_old := tlli_old; |
| 908 | } else if (tlli_old != 'FFFFFFFF'O and tlli_new == 'FFFFFFFF'O) { |
| 909 | /* TLLI unassignment: old shall be unassigned; new stays */ |
| 910 | ClientTable[i].tlli_old := omit; |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | private function f_tbl_comp_by_imsi(hexstring imsi) runs on BSSGP_BVC_CT return BSSGP_Client_CT { |
| 915 | var integer i; |
| 916 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 917 | if (isvalue(ClientTable[i].imsi) and isvalue(ClientTable[i].comp_ref) |
| 918 | and ClientTable[i].imsi == imsi) { |
| 919 | return ClientTable[i].comp_ref; |
| 920 | } |
| 921 | } |
| 922 | setverdict(fail, "Couldn't find Component for IMSI ", imsi); |
| 923 | mtc.stop; |
| 924 | } |
| 925 | |
| 926 | private function f_tbl_comp_by_tlli(OCT4 tlli) runs on BSSGP_BVC_CT return BSSGP_Client_CT { |
| 927 | var integer i; |
| 928 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 929 | if (isvalue(ClientTable[i].comp_ref) and |
| 930 | (isvalue(ClientTable[i].tlli) and (ClientTable[i].tlli == tlli or |
| 931 | isvalue(ClientTable[i].tlli_old) and ClientTable[i].tlli_old == tlli) )) { |
| 932 | return ClientTable[i].comp_ref; |
| 933 | } |
| 934 | } |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 935 | return null; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | private function f_tbl_idx_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_BVC_CT return integer { |
| 939 | var integer i; |
| 940 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 941 | if (isvalue(ClientTable[i].comp_ref) and ClientTable[i].comp_ref == comp_ref) { |
| 942 | return i; |
| 943 | } |
| 944 | } |
| 945 | setverdict(fail, "Couldn't find Client for Component ", comp_ref); |
| 946 | mtc.stop; |
| 947 | } |
| 948 | |
| 949 | private function f_tbl_tlli_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_BVC_CT return OCT4 { |
| 950 | var integer i; |
| 951 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 952 | if (isvalue(ClientTable[i].tlli) and isvalue(ClientTable[i].comp_ref) |
| 953 | and ClientTable[i].comp_ref == comp_ref) { |
| 954 | return ClientTable[i].tlli; |
| 955 | } |
| 956 | } |
| 957 | setverdict(fail, "Couldn't find TLLI for Component ", comp_ref); |
| 958 | mtc.stop; |
| 959 | } |
| 960 | |
| 961 | /* PDU_BSSGP enhanced with LLC and possibly L3 decoded payloads */ |
| 962 | type record BssgpDecoded { |
| 963 | PDU_BSSGP bssgp, |
| 964 | PDU_LLC llc optional, |
| 965 | #ifdef BSSGP_EM_L3 |
| 966 | PDU_L3_MS_SGSN l3_mo optional, |
| 967 | PDU_L3_SGSN_MS l3_mt optional, |
| 968 | #endif |
| 969 | PDU_SN sndcp optional |
| 970 | } |
| 971 | |
| 972 | /* Decode a PDU_BSSGP into a BssgpDecoded (i.e. with LLC/L3 decoded, as applicable) */ |
| 973 | private function f_dec_bssgp(PDU_BSSGP bssgp) runs on BSSGP_BVC_CT return BssgpDecoded { |
| 974 | var BssgpDecoded dec := { |
| 975 | bssgp := bssgp, |
| 976 | llc := omit, |
| 977 | #ifdef BSSGP_EM_L3 |
| 978 | l3_mo := omit, |
| 979 | l3_mt := omit, |
| 980 | #endif |
| 981 | sndcp := omit |
| 982 | }; |
| 983 | |
| 984 | /* Decode LLC, if it is a PDU that contains LLC */ |
| 985 | if (g_cfg.depth >= BSSGP_DECODE_DEPTH_LLC) { |
| 986 | if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) { |
| 987 | dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_DL_UNITDATA.lLC_PDU.lLC_PDU); |
| 988 | } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) { |
| 989 | dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_UL_UNITDATA.lLC_PDU.lLC_PDU); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | /* Decode SNDCP, if it is a LLC PDU containing user plane data */ |
| 994 | if (g_cfg.depth >= BSSGP_DECODE_DEPTH_SNDCP) { |
| 995 | if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_USER)) { |
| 996 | dec.sndcp := dec_PDU_SN(dec.llc.pDU_LLC_UI.information_field_UI); |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | #ifdef BSSGP_EM_L3 |
| 1001 | /* Decode L3, if it is a LLC PDU containing L3 */ |
| 1002 | if (g_cfg.depth >= BSSGP_DECODE_DEPTH_L3) { |
| 1003 | if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_L3)) { |
| 1004 | if (g_sgsn_role) { |
| 1005 | dec.l3_mo := dec_PDU_L3_MS_SGSN(dec.llc.pDU_LLC_UI.information_field_UI); |
| 1006 | } else { |
| 1007 | dec.l3_mt := dec_PDU_L3_SGSN_MS(dec.llc.pDU_LLC_UI.information_field_UI); |
| 1008 | } |
| 1009 | } |
| 1010 | } |
| 1011 | #endif |
| 1012 | |
| 1013 | return dec; |
| 1014 | } |
| 1015 | |
| 1016 | private function f_ptp_sendUnblock() runs on BSSGP_BVC_CT { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1017 | BVC.send(ts_ptp_BnsUdReq(t_BVC_UNBLOCK(g_cfg.bvci), 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1018 | g_t1_waits_for_block_ack := false; |
| 1019 | g_T1.start; |
| 1020 | } |
| 1021 | |
| 1022 | private function f_ptp_sendBlock(BssgpCause cause) runs on BSSGP_BVC_CT { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1023 | BVC.send(ts_ptp_BnsUdReq(t_BVC_BLOCK(g_cfg.bvci, cause), 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1024 | g_t1_waits_for_block_ack := true; |
| 1025 | g_T1.start; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1026 | g_last_block_cause := cause; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | private function f_ptp_sendStatus(BssgpCause cause, PDU_BSSGP pdu) runs on BSSGP_BVC_CT { |
| 1030 | /* FIXME: Make sure correct Signaling or PTP BVCI is used! */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1031 | BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_STATUS(g_cfg.bvci, cause, pdu), g_cfg.bvci, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1032 | } |
| 1033 | |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1034 | private function f_ptp_sendReset(BssgpCause cause := BSSGP_CAUSE_OM_INTERVENTION) runs on BSSGP_BVC_CT { |
Harald Welte | c967d0e | 2020-09-14 16:07:26 +0200 | [diff] [blame] | 1035 | var PDU_BSSGP pdu; |
| 1036 | |
| 1037 | /* The Cell Identifier IE is mandatory in the BVC-RESET PDU sent from BSS to |
| 1038 | * SGSN in order to reset a BVC corresponding to a PTP functional entity. The |
| 1039 | * Cell Identifier IE shall not be used in any other BVC-RESET PDU. */ |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1040 | if (g_sgsn_role) { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1041 | pdu := valueof(ts_BVC_RESET(cause, g_cfg.bvci, omit)); |
Harald Welte | c967d0e | 2020-09-14 16:07:26 +0200 | [diff] [blame] | 1042 | } else { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1043 | pdu := valueof(ts_BVC_RESET(cause, g_cfg.bvci, g_cfg.cell_id)); |
Harald Welte | c967d0e | 2020-09-14 16:07:26 +0200 | [diff] [blame] | 1044 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 1045 | |
| 1046 | /* BVC-RESET is always sent via the SIGNALLING BVCI, see Table 5.4.1 */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1047 | BVC.send(ts_ptp_BnsUdReq(pdu, 0, g_bvc_lsp)); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 1048 | g_T2.start; |
| 1049 | //f_change_state(BVC_S_WAIT_RESET); |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1050 | g_last_reset_cause := cause; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 1051 | } |
| 1052 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1053 | /* PTP-BVC is in BVC_S_BLOCKED state */ |
| 1054 | private altstep as_ptp_blocked() runs on BSSGP_BVC_CT { |
| 1055 | var NsUnitdataIndication udi; |
| 1056 | |
| 1057 | [g_T1.running and not g_t1_waits_for_block_ack] BVC.receive(tr_ptp_BnsUdInd(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0)) { |
| 1058 | g_T1.stop; |
| 1059 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1060 | } |
| 1061 | |
Harald Welte | ddfc667 | 2020-11-24 23:13:01 +0100 | [diff] [blame] | 1062 | /* Inbound BVC-UNBLOCK from peer */ |
| 1063 | [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(t_BVC_UNBLOCK(g_cfg.bvci), 0)) { |
| 1064 | BVC.send(ts_ptp_BnsUdReq(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp)); |
| 1065 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1066 | } |
| 1067 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1068 | /* RESET-ACK before T2 timeout: reset successful. In SGSN role, CellID must be present */ |
| 1069 | [g_T2.running and g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET_ACK(g_cfg.bvci, g_cfg.cell_id), 0)) -> value udi { |
| 1070 | g_T2.stop; |
| 1071 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1072 | } |
| 1073 | /* RESET-ACK before T2 timeout: reset successful. In BSS role, CellID must be absent */ |
| 1074 | [g_T2.running and not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET_ACK(g_cfg.bvci, omit), 0)) -> value udi { |
| 1075 | g_T2.stop; |
| 1076 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1077 | } |
| 1078 | |
Harald Welte | ab50cc2 | 2020-11-25 17:11:08 +0100 | [diff] [blame] | 1079 | [] as_ptp_handle_inbound_reset(); |
| 1080 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1081 | [] g_T2.timeout { |
| 1082 | /* BVC-RESET-ACK PDU was not received within T2: retransmit */ |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1083 | f_ptp_sendReset(g_last_reset_cause); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1084 | } |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1085 | |
| 1086 | [] MGMT.receive(BssgpUnblockRequest:?) { |
| 1087 | f_ptp_sendUnblock(); |
| 1088 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1091 | /* PTP-BVC is in UNBLOCKED state */ |
| 1092 | private altstep as_ptp_unblocked() runs on BSSGP_BVC_CT { |
| 1093 | var NsUnitdataIndication udi; |
| 1094 | var NsStatusIndication nsi; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1095 | var BssgpBlockRequest bbr; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1096 | var BSSGP_Client_CT vc_conn; |
| 1097 | var ASP_Event evt; |
| 1098 | var PDU_BSSGP bs_pdu; |
| 1099 | var PDU_LLC llc; |
| 1100 | #ifdef BSSGP_EM_L3 |
| 1101 | var PDU_L3_MS_SGSN l3_mo; |
| 1102 | var PDU_L3_SGSN_MS l3_mt; |
| 1103 | #endif |
| 1104 | |
| 1105 | /* bogus unblock, just respond with ACK */ |
| 1106 | [] BVC.receive(tr_ptp_BnsUdInd(t_BVC_UNBLOCK(g_cfg.bvci), 0)) -> value udi { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1107 | BVC.send(ts_ptp_BnsUdReq(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1108 | } |
| 1109 | /* Respond to BLOCK with BLOCK-ACK + change state */ |
| 1110 | [] BVC.receive(tr_ptp_BnsUdInd(t_BVC_BLOCK(g_cfg.bvci, ?), 0)) -> value udi { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1111 | BVC.send(ts_ptp_BnsUdReq(t_BVC_BLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1112 | g_T1.stop; |
| 1113 | f_ptp_change_state(BVC_S_BLOCKED); |
| 1114 | } |
| 1115 | /* BLOCK-ACK before T1 timeout: mark as blocked */ |
| 1116 | [g_T1.running and g_t1_waits_for_block_ack] BVC.receive(tr_ptp_BnsUdInd(t_BVC_BLOCK_ACK(g_cfg.bvci), 0)) -> value udi { |
| 1117 | g_T1.stop; |
| 1118 | f_ptp_change_state(BVC_S_BLOCKED); |
| 1119 | } |
| 1120 | /* Re-transmit BLOCK / UNBLOCK on T1 timeout */ |
| 1121 | [not g_t1_waits_for_block_ack] g_T1.timeout { |
| 1122 | f_ptp_sendUnblock(); |
| 1123 | } |
| 1124 | [g_t1_waits_for_block_ack] g_T1.timeout { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1125 | f_ptp_sendBlock(g_last_block_cause); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1126 | } |
| 1127 | |
Harald Welte | ab50cc2 | 2020-11-25 17:11:08 +0100 | [diff] [blame] | 1128 | [] as_ptp_handle_inbound_reset(); |
| 1129 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1130 | [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_FC_BVC, g_cfg.bvci)) -> value udi { |
Harald Welte | 71449b0 | 2020-12-09 11:58:23 +0100 | [diff] [blame] | 1131 | if (GLOBAL.checkstate("Connected")) { |
| 1132 | GLOBAL.send(udi.bssgp); |
| 1133 | } else { |
| 1134 | /* simply acknowledge all per-BVC Flow Control Messages */ |
| 1135 | var OCT1 tag := udi.bssgp.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value; |
| 1136 | BVC.send(ts_ptp_BnsUdReq(t_BVC_FC_BVC_ACK(tag), g_cfg.bvci, g_bvc_lsp)); |
| 1137 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1138 | } |
Harald Welte | 71449b0 | 2020-12-09 11:58:23 +0100 | [diff] [blame] | 1139 | |
| 1140 | [not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(t_BVC_FC_BVC_ACK(?), g_cfg.bvci)) -> value udi { |
| 1141 | if (GLOBAL.checkstate("Connected")) { |
| 1142 | GLOBAL.send(udi.bssgp); |
| 1143 | } else { |
| 1144 | /* ignore any incoming flow control ACK */ |
| 1145 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1146 | } |
Harald Welte | 71449b0 | 2020-12-09 11:58:23 +0100 | [diff] [blame] | 1147 | |
Harald Welte | f536524 | 2021-01-17 13:46:57 +0100 | [diff] [blame] | 1148 | [] BVC.receive(tr_ptp_BnsUdInd(tr_GLOBAL_PTP, g_cfg.bvci)) -> value udi { |
| 1149 | if (GLOBAL.checkstate("Connected")) { |
| 1150 | GLOBAL.send(udi.bssgp); |
| 1151 | } else { |
| 1152 | setverdict(fail, "Received BSSGP STATUS ", udi.bssgp); |
| 1153 | } |
| 1154 | } |
| 1155 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1156 | /* Any other PTP BSSGP message: If it has TLLI, route to component; otherwise broadcast */ |
| 1157 | [] BVC.receive(tr_ptp_BnsUdInd(?, g_cfg.bvci)) -> value udi { |
| 1158 | var BssgpDecoded dec := f_dec_bssgp(udi.bssgp); |
| 1159 | var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp); |
| 1160 | if (isvalue(tlli)) { |
| 1161 | vc_conn := f_tbl_comp_by_tlli(valueof(tlli)); |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 1162 | if (vc_conn == null) { |
| 1163 | g_cfg.create_cb.apply(g_cfg.bvci, g_cfg.cell_id, valueof(tlli), dec); |
| 1164 | } else { |
| 1165 | f_send_bssgp_dec(dec, vc_conn, BSSGP_SP); |
| 1166 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1167 | } else { |
| 1168 | log("No TLLI: Broadcasting ", dec); |
| 1169 | /* broadcast this message to all components */ |
| 1170 | // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;" |
| 1171 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 1172 | if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) { |
| 1173 | f_send_bssgp_dec(dec, ClientTable[i].comp_ref, BSSGP_SP); |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | /* Any other SIG BSSGP message: If it has TLLI, route to component; otherwise broadcast */ |
| 1180 | [] BVC.receive(tr_ptp_BnsUdInd(?, 0)) -> value udi { |
| 1181 | var BssgpDecoded dec := f_dec_bssgp(udi.bssgp); |
| 1182 | var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp); |
| 1183 | if (isvalue(tlli)) { |
| 1184 | vc_conn := f_tbl_comp_by_tlli(valueof(tlli)); |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 1185 | if (vc_conn == null) { |
| 1186 | g_cfg.create_cb.apply(g_cfg.bvci, g_cfg.cell_id, valueof(tlli), dec); |
| 1187 | } else { |
| 1188 | f_send_bssgp_dec(dec, vc_conn, BSSGP_SP_SIG); |
| 1189 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1190 | } else { |
| 1191 | log("No TLLI: Broadcasting ", dec); |
| 1192 | /* broadcast this message to all components */ |
| 1193 | // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;" |
| 1194 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 1195 | if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) { |
| 1196 | f_send_bssgp_dec(dec, ClientTable[i].comp_ref, BSSGP_SP_SIG); |
| 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | /* ConnHdlr sends BSSGP on BVCI=0 port: forward it to BSSGP_CT */ |
| 1203 | [] BSSGP_SP_SIG.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1204 | BVC.send(ts_ptp_BnsUdReq(bs_pdu, 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | /* ConnHdlr sends BSSGP on BVCI=PTP port: forward it to BSSGP_CT */ |
| 1208 | [] BSSGP_SP.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1209 | BVC.send(ts_ptp_BnsUdReq(bs_pdu, g_cfg.bvci, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | #ifdef BSSGP_EM_L3 |
| 1213 | /* ConnHdlr sends L3: Encode and send as UL_UD / DL_UD */ |
| 1214 | [g_sgsn_role] BSSGP_SP.receive(PDU_L3_SGSN_MS:?) -> value l3_mt sender vc_conn { |
| 1215 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1216 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1217 | var octetstring l3_enc := enc_PDU_L3_SGSN_MS(l3_mt); |
| 1218 | var BIT4 sapi := f_llc_sapi_by_l3_mt(l3_mt); |
| 1219 | var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]); |
| 1220 | var octetstring llc_enc := enc_PDU_LLC(valueof(ts_LLC_UI(l3_enc, sapi, '1'B, n_u))); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1221 | BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_DL_UD(tlli, llc_enc), g_cfg.bvci, oct2int(tlli))); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1222 | } |
| 1223 | [not g_sgsn_role] BSSGP_SP.receive(PDU_L3_MS_SGSN:?) -> value l3_mo sender vc_conn { |
| 1224 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1225 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1226 | var octetstring l3_enc := enc_PDU_L3_MS_SGSN(l3_mo); |
| 1227 | var BIT4 sapi := f_llc_sapi_by_l3_mo(l3_mo); |
| 1228 | var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]); |
| 1229 | var octetstring llc_enc := enc_PDU_LLC(valueof(ts_LLC_UI(l3_enc, sapi, '1'B, n_u))); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1230 | BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_UL_UD(tlli, g_cfg.cell_id, llc_enc), g_cfg.bvci, oct2int(tlli))); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1231 | } |
| 1232 | #endif |
| 1233 | |
| 1234 | /* ConnHdlr sends raw LLC: Encode and send as UL_UD / DL_UD */ |
| 1235 | [not g_sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn { |
| 1236 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1237 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1238 | var octetstring llc_enc := enc_PDU_LLC(llc); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1239 | BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_UL_UD(tlli, g_cfg.cell_id, llc_enc), g_cfg.bvci, oct2int(tlli))); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1240 | } |
| 1241 | [g_sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn { |
| 1242 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1243 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1244 | var octetstring llc_enc := enc_PDU_LLC(llc); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1245 | BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_DL_UD(tlli, llc_enc), g_cfg.bvci, oct2int(tlli))); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1246 | } |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1247 | |
Harald Welte | 71449b0 | 2020-12-09 11:58:23 +0100 | [diff] [blame] | 1248 | /* Testcase sends us BSSGP on global port */ |
| 1249 | [] GLOBAL.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn { |
| 1250 | BVC.send(ts_ptp_BnsUdReq(bs_pdu, g_cfg.bvci, g_bvc_lsp)); |
| 1251 | } |
| 1252 | |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1253 | [] MGMT.receive(BssgpBlockRequest:?) -> value bbr { |
| 1254 | f_ptp_sendBlock(bbr.cause); |
| 1255 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 1256 | } |
| 1257 | |
Harald Welte | ab50cc2 | 2020-11-25 17:11:08 +0100 | [diff] [blame] | 1258 | private altstep as_ptp_handle_inbound_reset() runs on BSSGP_BVC_CT { |
| 1259 | var NsUnitdataIndication udi; |
| 1260 | /* we are a SGSN: BSS/PCU-originated RESET must have a cell ID */ |
| 1261 | [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET(?, g_cfg.bvci, g_cfg.cell_id), 0)) -> value udi { |
| 1262 | log("Rx BVC-RESET from BVCI=", g_cfg.bvci); |
Harald Welte | 3c90515 | 2020-11-26 20:56:09 +0100 | [diff] [blame] | 1263 | if (MGMT.checkstate("Connected")) { |
| 1264 | MGMT.send(BssgpResetIndication:{g_cfg.bvci}); |
| 1265 | } |
Harald Welte | ab50cc2 | 2020-11-25 17:11:08 +0100 | [diff] [blame] | 1266 | /* Respond to RESET with correct BVCI but without CellID */ |
| 1267 | BVC.send(ts_ptp_BnsUdReq(ts_BVC_RESET_ACK(g_cfg.bvci, omit), 0, g_bvc_lsp)); |
| 1268 | /* FIXME: reset all state? What about clients? */ |
| 1269 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1270 | } |
| 1271 | /* we are a BSS/PCU: SGSN-originated RESET must not have a cell ID */ |
| 1272 | [not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET(?, g_cfg.bvci, omit), 0)) -> value udi { |
| 1273 | log("Rx BVC-RESET from BVCI=", g_cfg.bvci); |
Harald Welte | 3c90515 | 2020-11-26 20:56:09 +0100 | [diff] [blame] | 1274 | if (MGMT.checkstate("Connected")) { |
| 1275 | MGMT.send(BssgpResetIndication:{g_cfg.bvci}); |
| 1276 | } |
Harald Welte | ab50cc2 | 2020-11-25 17:11:08 +0100 | [diff] [blame] | 1277 | /* Respond to RESET with correct BVCI with CellID */ |
| 1278 | BVC.send(ts_ptp_BnsUdReq(ts_BVC_RESET_ACK(g_cfg.bvci, g_cfg.cell_id), 0, g_bvc_lsp)); |
| 1279 | /* FIXME: reset all state? What about clients? */ |
| 1280 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1281 | } |
| 1282 | } |
| 1283 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1284 | /* Events permitted in all states */ |
| 1285 | private altstep as_ptp_allstate() runs on BSSGP_BVC_CT { |
| 1286 | var NsUnitdataIndication udi; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1287 | var BssgpResetRequest brr; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1288 | var BSSGP_Client_CT vc_conn; |
| 1289 | var OCT4 tlli, tlli_old; |
| 1290 | var hexstring imsi; |
| 1291 | |
| 1292 | /* Signaling BVC was reset */ |
| 1293 | [] BVC.receive(BssgpResetIndication:{0}) { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1294 | if (MGMT.checkstate("Connected")) { |
| 1295 | MGMT.send(BssgpResetIndication:{0}); |
| 1296 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1297 | if (not g_sgsn_role) { |
| 1298 | f_ptp_change_state(BVC_S_BLOCKED); |
| 1299 | /* when the BSS side signaling PTP is RESET, all PTP BVC must start the |
| 1300 | * reset procedure */ |
| 1301 | f_ptp_sendReset(); |
| 1302 | } else { |
| 1303 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1304 | } |
| 1305 | } |
| 1306 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1307 | /* Ignore those for now */ |
| 1308 | [] BVC.receive(ASP_Event:?) { } |
| 1309 | [] BVC.receive(BssgpStatusIndication:?) { } |
| 1310 | |
| 1311 | /* catch-all */ |
| 1312 | [] BVC.receive(tr_ptp_BnsUdInd(?, 0)) -> value udi { |
| 1313 | setverdict(fail, "Received unexpected NS (SIG): ", udi); |
| 1314 | } |
| 1315 | [] BVC.receive(tr_ptp_BnsUdInd(?, ?)) -> value udi { |
| 1316 | setverdict(fail, "Received unexpected NS (PTP): ", udi); |
| 1317 | } |
| 1318 | [] BVC.receive { |
| 1319 | setverdict(fail, "Received unexpected message from BSSGP_CT"); |
| 1320 | } |
| 1321 | |
| 1322 | /* registration/deregistration of Clients (per-TLLI components) */ |
| 1323 | [] BSSGP_PROC.getcall(BSSGP_register_client:{?,?}) -> param(imsi, tlli) sender vc_conn { |
| 1324 | f_tbl_client_add(imsi, tlli, vc_conn); |
| 1325 | BSSGP_PROC.reply(BSSGP_register_client:{imsi, tlli}) to vc_conn; |
| 1326 | } |
| 1327 | [] BSSGP_PROC.getcall(BSSGP_unregister_client:{?}) -> param(imsi) sender vc_conn { |
| 1328 | f_tbl_client_del(imsi, vc_conn); |
| 1329 | BSSGP_PROC.reply(BSSGP_unregister_client:{imsi}) to vc_conn; |
| 1330 | } |
| 1331 | [] BSSGP_PROC.getcall(BSSGP_llgmm_assign:{?,?}) -> param(tlli_old, tlli) sender vc_conn { |
| 1332 | f_tbl_client_llgmm_assign(tlli_old, tlli, vc_conn); |
| 1333 | BSSGP_PROC.reply(BSSGP_llgmm_assign:{tlli_old, tlli}) to vc_conn; |
| 1334 | } |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1335 | |
| 1336 | [] MGMT.receive(BssgpResetRequest:?) -> value brr { |
Harald Welte | 52cecbb | 2020-11-25 21:57:31 +0100 | [diff] [blame] | 1337 | f_ptp_change_state(BVC_S_BLOCKED); |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1338 | f_ptp_sendReset(brr.cause); |
| 1339 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | /* main loop for per-BVC component */ |
| 1343 | private function f_bssgp_bvc_ScanEvents() runs on BSSGP_BVC_CT { |
| 1344 | while (true) { |
| 1345 | alt { |
| 1346 | [g_ptp_bvc_state == BVC_S_BLOCKED] as_ptp_blocked(); |
| 1347 | [g_ptp_bvc_state == BVC_S_UNBLOCKED] as_ptp_unblocked(); |
| 1348 | [] as_ptp_allstate(); |
| 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | |
| 1353 | /* main function for per-BVC Component */ |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 1354 | private function f_bssgp_bvc_main(BssgpBvcConfig cfg, boolean sgsn_role, Nsei nsei, charstring id) runs on BSSGP_BVC_CT { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1355 | g_cfg := cfg; |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 1356 | g_nsei := nsei; |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1357 | g_bvc_lsp := cfg.bvci; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1358 | g_sgsn_role := sgsn_role; |
| 1359 | f_bssgp_bvc_ScanEvents(); |
| 1360 | } |
| 1361 | |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1362 | template (value) NsUnitdataRequest ts_ptp_BnsUdReq(template (value) PDU_BSSGP pdu, template (value) BssgpBvci bvci, |
| 1363 | template (value) integer lsp) := { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1364 | bvci := bvci, |
| 1365 | nsei := 0, // overwritten in BSSGP_CT |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1366 | lsp := lsp, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1367 | /* for some weird reason we get "Dynamic test case error: Text encoder: Encoding an |
| 1368 | * unbound integer value." when trying to send the reocrd rather than the octetstring */ |
| 1369 | //sdu := omit, |
| 1370 | //bssgp := valueof(pdu) |
| 1371 | sdu := enc_PDU_BSSGP(valueof(pdu)), |
| 1372 | bssgp := omit |
| 1373 | } |
| 1374 | |
| 1375 | template (present) NsUnitdataIndication tr_ptp_BnsUdInd(template (present) PDU_BSSGP pdu, template (present) BssgpBvci bvci) := { |
| 1376 | bvci := bvci, |
| 1377 | nsei := ?, |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 1378 | nsvci := ?, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1379 | sdu := *, |
| 1380 | bssgp := pdu |
| 1381 | } |
| 1382 | |
| 1383 | /* change state of PTP BVC; broadcast state change to clients */ |
| 1384 | private function f_ptp_change_state(BvcState new_state) runs on BSSGP_BVC_CT { |
| 1385 | if (new_state == g_ptp_bvc_state) { |
| 1386 | return; |
| 1387 | } |
| 1388 | log("BVCI(", g_cfg.bvci, ") State Transition: ", g_ptp_bvc_state, " -> ", new_state); |
| 1389 | g_ptp_bvc_state := new_state; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1390 | if (MGMT.checkstate("Connected")) { |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 1391 | MGMT.send(ts_BssgpStsInd(g_nsei, g_cfg.bvci, g_ptp_bvc_state)); |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1392 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1393 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 1394 | if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) { |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 1395 | BSSGP_SP.send(ts_BssgpStsInd(g_nsei, g_cfg.bvci, g_ptp_bvc_state)) to ClientTable[i].comp_ref; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1396 | } |
| 1397 | } |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /* attempt to extract the TLLI from a BSSGP PDU */ |
| 1401 | function f_bssgp_get_tlli(PDU_BSSGP bssgp) return template OCT4 { |
| 1402 | if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) { |
| 1403 | return bssgp.pDU_BSSGP_DL_UNITDATA.tLLI_current; |
| 1404 | } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) { |
| 1405 | return bssgp.pDU_BSSGP_UL_UNITDATA.tLLI; |
| 1406 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY)) { |
| 1407 | return bssgp.pDU_BSSGP_RA_CAPABILITY.tLLI.tLLI_Value; |
| 1408 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE)) { |
| 1409 | return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE.tLLI.tLLI_Value; |
| 1410 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK)) { |
| 1411 | return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK.tLLI.tLLI_Value; |
Harald Welte | 650bd72 | 2021-01-17 10:58:56 +0100 | [diff] [blame] | 1412 | } else if (ischosen(bssgp.pDU_BSSGP_RADIO_STATUS) and |
| 1413 | ispresent(bssgp.pDU_BSSGP_RADIO_STATUS.tLLI)) { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 1414 | return bssgp.pDU_BSSGP_RADIO_STATUS.tLLI.tLLI_Value; |
| 1415 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND)) { |
| 1416 | return bssgp.pDU_BSSGP_SUSPEND.tLLI.tLLI_Value; |
| 1417 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_ACK)) { |
| 1418 | return bssgp.pDU_BSSGP_SUSPEND_ACK.tLLI.tLLI_Value; |
| 1419 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_NACK)) { |
| 1420 | return bssgp.pDU_BSSGP_SUSPEND_NACK.tLLI.tLLI_Value; |
| 1421 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME)) { |
| 1422 | return bssgp.pDU_BSSGP_RESUME.tLLI.tLLI_Value; |
| 1423 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME_ACK)) { |
| 1424 | return bssgp.pDU_BSSGP_RESUME_ACK.tLLI.tLLI_Value; |
| 1425 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME_NACK)) { |
| 1426 | return bssgp.pDU_BSSGP_RESUME_NACK.tLLI.tLLI_Value; |
| 1427 | } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL)) { |
| 1428 | return bssgp.pDU_BSSGP_FLUSH_LL.tLLI.tLLI_Value; |
| 1429 | } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL_ACK)) { |
| 1430 | return bssgp.pDU_BSSGP_FLUSH_LL_ACK.tLLI.tLLI_Value; |
| 1431 | } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) { |
| 1432 | return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value; |
| 1433 | } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) { |
| 1434 | return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value; |
| 1435 | } else if (ischosen(bssgp.pDU_BSSGP_PAGING_CS) and |
| 1436 | isvalue(bssgp.pDU_BSSGP_PAGING_CS.tLLI)) { |
| 1437 | return bssgp.pDU_BSSGP_PAGING_CS.tLLI.tLLI_Value; |
| 1438 | } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS)) { |
| 1439 | return bssgp.pDU_BSSGP_FLOW_CONTROL_MS.tLLI.tLLI_Value; |
| 1440 | } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK)) { |
| 1441 | return bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK.tLLI.tLLI_Value; |
| 1442 | } |
| 1443 | /* TODO: Handover, PFC, LCS */ |
| 1444 | return omit; |
| 1445 | } |
| 1446 | |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 1447 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 1448 | |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 1449 | } |