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