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 |
| 4 | * (C) 2018-2019 Harald Welte <laforge@gnumonks.org> |
| 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 |
| 11 | */ |
| 12 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 13 | import from General_Types all; |
| 14 | import from Osmocom_Types all; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 15 | import from NS_Types all; |
| 16 | import from NS_Emulation all; |
| 17 | import from BSSGP_Types all; |
| 18 | import from Osmocom_Gb_Types all; |
| 19 | import from IPL4asp_Types all; |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 20 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 21 | import from MobileL3_GMM_SM_Types all; |
| 22 | import from MobileL3_Types all; |
| 23 | |
| 24 | import from LLC_Types all; |
| 25 | import from LLC_Templates all; |
| 26 | |
Harald Welte | a2526a8 | 2018-02-18 19:03:36 +0100 | [diff] [blame] | 27 | import from SNDCP_Types all; |
| 28 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 29 | /*********************************************************************** |
| 30 | * Communication between Client Components and Main Component |
| 31 | ***********************************************************************/ |
| 32 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 33 | type record BssgpStatusIndication { |
| 34 | Nsei nsei, |
| 35 | BssgpBvci bvci, |
| 36 | BvcState state |
| 37 | } |
| 38 | |
| 39 | template BssgpStatusIndication t_BssgpStsInd(template Nsei nsei, template BssgpBvci bvci, template BvcState state) := { |
| 40 | nsei := nsei, |
| 41 | bvci := bvci, |
| 42 | state := state |
| 43 | } |
| 44 | |
| 45 | type enumerated BvcState { |
| 46 | BVC_S_BLOCKED, |
| 47 | BVC_S_UNBLOCKED |
| 48 | }; |
| 49 | |
| 50 | /* port from our (internal) point of view */ |
| 51 | type port BSSGP_SP_PT message { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 52 | in PDU_BSSGP, |
Harald Welte | 752abba | 2018-02-18 19:42:17 +0100 | [diff] [blame] | 53 | PDU_LLC, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 54 | PDU_L3_MS_SGSN, |
| 55 | PDU_L3_SGSN_MS; |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 56 | out PDU_BSSGP, |
| 57 | PDU_LLC, |
| 58 | PDU_SN, |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 59 | NsStatusIndication, |
| 60 | BssgpStatusIndication, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 61 | ASP_Event, |
| 62 | PDU_L3_MS_SGSN, |
| 63 | PDU_L3_SGSN_MS; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 64 | } with { extension "internal" }; |
| 65 | |
| 66 | /* port from the user point of view */ |
| 67 | type port BSSGP_PT message { |
| 68 | in ASP_Event, |
| 69 | NsStatusIndication, |
| 70 | BssgpStatusIndication, |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 71 | PDU_BSSGP, |
| 72 | PDU_LLC, |
| 73 | PDU_SN, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 74 | PDU_L3_MS_SGSN, |
| 75 | PDU_L3_SGSN_MS; |
| 76 | out PDU_BSSGP, |
Harald Welte | 752abba | 2018-02-18 19:42:17 +0100 | [diff] [blame] | 77 | PDU_LLC, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 78 | PDU_L3_SGSN_MS, |
| 79 | PDU_L3_MS_SGSN; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 80 | } with { extension "internal" }; |
| 81 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 82 | signature BSSGP_register_client(hexstring imsi, OCT4 tlli, BssgpCellId cell_id); |
| 83 | signature BSSGP_unregister_client(hexstring imsi); |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 84 | signature BSSGP_llgmm_assign(OCT4 tlli_old, OCT4 tlli); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 85 | |
| 86 | type port BSSGP_PROC_PT procedure { |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 87 | inout BSSGP_register_client, BSSGP_unregister_client, BSSGP_llgmm_assign; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 88 | } with { extension "internal" }; |
| 89 | |
| 90 | |
| 91 | /*********************************************************************** |
| 92 | * Client Component for a single MS/TLLI |
| 93 | ***********************************************************************/ |
| 94 | |
| 95 | type component BSSGP_Client_CT { |
Alexander Couzens | 0e510e6 | 2018-07-28 23:06:00 +0200 | [diff] [blame] | 96 | port BSSGP_PT BSSGP[3]; |
| 97 | port BSSGP_PT BSSGP_SIG[3]; |
| 98 | port BSSGP_PROC_PT BSSGP_PROC[3]; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | /*********************************************************************** |
| 102 | * Main Component |
| 103 | ***********************************************************************/ |
| 104 | |
| 105 | function BssgpStart(BssgpConfig cfg) runs on BSSGP_CT { |
| 106 | g_cfg := cfg; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 107 | f_init(); |
| 108 | f_ScanEvents(); |
| 109 | } |
| 110 | |
| 111 | private function f_init() runs on BSSGP_CT { |
| 112 | /* Connect the UDP socket */ |
| 113 | f_change_state(BVC_S_BLOCKED); |
| 114 | } |
| 115 | |
| 116 | type component BSSGP_CT { |
Stefan Sperling | f82bbb6 | 2018-05-03 19:14:28 +0200 | [diff] [blame] | 117 | /* UDP ports towards the bottom (IUT) */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 118 | port NS_PT BSCP; |
| 119 | /* NS-User SAP towards the user */ |
| 120 | port BSSGP_SP_PT BSSGP_SP; |
Stefan Sperling | f82bbb6 | 2018-05-03 19:14:28 +0200 | [diff] [blame] | 121 | port BSSGP_SP_PT BSSGP_SP_SIG; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 122 | port BSSGP_PROC_PT BSSGP_PROC; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 123 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 124 | var BssgpConfig g_cfg; |
| 125 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 126 | var BvcState g_ptp_bvc_state := BVC_S_BLOCKED; |
| 127 | timer g_T1 := 15.0; |
| 128 | timer g_T2 := 60.0; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 129 | |
| 130 | var ClientEntity ClientTable[16]; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 131 | } |
| 132 | |
Alexander Couzens | 6b449fb | 2018-07-31 14:19:36 +0200 | [diff] [blame] | 133 | type record length(16) of LLC_Entity LLC_Entities; |
| 134 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 135 | type record ClientEntity { |
| 136 | OCT4 tlli, |
| 137 | OCT4 tlli_old optional, |
| 138 | hexstring imsi, |
| 139 | BssgpCellId cell_id, |
| 140 | BSSGP_Client_CT comp_ref, |
| 141 | /* LLC entities, one for each SAPI */ |
| 142 | LLC_Entity llc[16] |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 143 | }; |
| 144 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 145 | type record LLC_Entity { |
| 146 | boolean sgsn_role, |
| 147 | /* N(U) on transmit side for next PDU */ |
| 148 | uint9_t n_u_tx_next, |
| 149 | /* N(U) on receive side, last PDU */ |
| 150 | uint9_t n_u_rx_last optional |
| 151 | }; |
| 152 | |
Alexander Couzens | cdfb751 | 2018-07-31 15:37:14 +0200 | [diff] [blame] | 153 | function f_llc_create(boolean sgsn_role := false) return LLC_Entities { |
| 154 | var LLC_Entities llc; |
| 155 | for (var integer i := 0; i < 16; i := i+1) { |
| 156 | llc[i] := valueof(t_LLC_init(sgsn_role)); |
| 157 | } |
| 158 | return llc; |
| 159 | } |
| 160 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 161 | private template LLC_Entity t_LLC_init(boolean sgsn_role := false) := { |
| 162 | sgsn_role := sgsn_role, |
| 163 | n_u_tx_next := 0, |
| 164 | n_u_rx_last := - |
| 165 | } |
| 166 | |
| 167 | type record BssgpConfig { |
| 168 | Nsvci nsei, |
| 169 | Nsvci bvci, |
| 170 | BssgpCellId cell_id, |
| 171 | boolean sgsn_role |
| 172 | }; |
| 173 | |
| 174 | function f_BnsUdReq(template PDU_BSSGP pdu, BssgpBvci bvci) |
| 175 | runs on BSSGP_CT return NsUnitdataRequest { |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 176 | var NsUnitdataRequest udr := { |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 177 | bvci := bvci, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 178 | nsei := g_cfg.nsei, |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 179 | /* for some weird reason we get "Dynamic test case error: Text encoder: Encoding an |
| 180 | * unbound integer value." when trying to send the reocrd rather than the octetstring */ |
| 181 | //sdu := omit, |
| 182 | //bssgp := valueof(pdu) |
| 183 | sdu := enc_PDU_BSSGP(valueof(pdu)), |
| 184 | bssgp := omit |
| 185 | } |
| 186 | return udr; |
| 187 | } |
| 188 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 189 | function f_BnsUdInd(template PDU_BSSGP pdu, template BssgpBvci bvci) |
| 190 | runs on BSSGP_CT return template NsUnitdataIndication { |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 191 | var template NsUnitdataIndication udi := { |
| 192 | bvci := bvci, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 193 | nsei := g_cfg.nsei, |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 194 | sdu := *, |
| 195 | bssgp := pdu |
| 196 | } |
| 197 | return udi; |
| 198 | } |
| 199 | |
| 200 | private function f_change_state(BvcState new_state) runs on BSSGP_CT { |
| 201 | log("BSSGP State Transition: ", g_ptp_bvc_state, " -> ", new_state); |
| 202 | g_ptp_bvc_state := new_state; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 203 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 204 | if (isbound(ClientTable[i].comp_ref)) { |
| 205 | BSSGP_SP.send(t_BssgpStsInd(g_cfg.nsei, g_cfg.bvci, g_ptp_bvc_state)) to ClientTable[i].comp_ref; |
| 206 | } |
| 207 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | private function f_sendReset() runs on BSSGP_CT { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 211 | var PDU_BSSGP pdu := valueof(ts_BVC_RESET(BSSGP_CAUSE_OM_INTERVENTION, g_cfg.bvci, g_cfg.cell_id)); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 212 | log("PDU: ", pdu); |
| 213 | log("ENC: ", enc_PDU_BSSGP(pdu)); |
| 214 | |
| 215 | /* BVC-RESET is always sent via the SIGNALLING BVCI, see Table 5.4.1 */ |
| 216 | BSCP.send(f_BnsUdReq(pdu, 0)); |
| 217 | g_T2.start; |
| 218 | //f_change_state(BVC_S_WAIT_RESET); |
| 219 | } |
| 220 | |
| 221 | private function f_sendUnblock() runs on BSSGP_CT { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 222 | BSCP.send(f_BnsUdReq(t_BVC_UNBLOCK(g_cfg.bvci), 0)); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 223 | g_T1.start; |
| 224 | } |
| 225 | |
| 226 | private function f_sendBlock(BssgpCause cause) runs on BSSGP_CT { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 227 | BSCP.send(f_BnsUdReq(t_BVC_BLOCK(g_cfg.bvci, cause), 0)); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 228 | g_T1.start; |
| 229 | } |
| 230 | |
| 231 | private function f_sendStatus(BssgpCause cause, PDU_BSSGP pdu) runs on BSSGP_CT { |
| 232 | /* FIXME: Make sure correct Signaling or PTP BVCI is used! */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 233 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(g_cfg.bvci, cause, pdu), g_cfg.bvci)); |
| 234 | } |
| 235 | |
| 236 | /* attempt to extract the TLLI from a BSSGP PDU */ |
| 237 | function f_bssgp_get_tlli(PDU_BSSGP bssgp) return template OCT4 { |
| 238 | if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) { |
| 239 | return bssgp.pDU_BSSGP_DL_UNITDATA.tLLI_current; |
| 240 | } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) { |
| 241 | return bssgp.pDU_BSSGP_UL_UNITDATA.tLLI; |
| 242 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY)) { |
| 243 | return bssgp.pDU_BSSGP_RA_CAPABILITY.tLLI.tLLI_Value; |
| 244 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE)) { |
| 245 | return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE.tLLI.tLLI_Value; |
| 246 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK)) { |
| 247 | return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK.tLLI.tLLI_Value; |
| 248 | } else if (ischosen(bssgp.pDU_BSSGP_RADIO_STATUS)) { |
| 249 | return bssgp.pDU_BSSGP_RADIO_STATUS.tLLI.tLLI_Value; |
| 250 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND)) { |
| 251 | return bssgp.pDU_BSSGP_SUSPEND.tLLI.tLLI_Value; |
| 252 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_ACK)) { |
| 253 | return bssgp.pDU_BSSGP_SUSPEND_ACK.tLLI.tLLI_Value; |
| 254 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_NACK)) { |
| 255 | return bssgp.pDU_BSSGP_SUSPEND_NACK.tLLI.tLLI_Value; |
| 256 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME)) { |
| 257 | return bssgp.pDU_BSSGP_RESUME.tLLI.tLLI_Value; |
| 258 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME_ACK)) { |
| 259 | return bssgp.pDU_BSSGP_RESUME_ACK.tLLI.tLLI_Value; |
| 260 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME_NACK)) { |
| 261 | return bssgp.pDU_BSSGP_RESUME_NACK.tLLI.tLLI_Value; |
| 262 | } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL)) { |
| 263 | return bssgp.pDU_BSSGP_FLUSH_LL.tLLI.tLLI_Value; |
| 264 | } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL_ACK)) { |
| 265 | return bssgp.pDU_BSSGP_FLUSH_LL_ACK.tLLI.tLLI_Value; |
| 266 | } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) { |
| 267 | return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value; |
| 268 | } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) { |
| 269 | return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value; |
| 270 | } else if (ischosen(bssgp.pDU_BSSGP_PAGING_CS) and |
| 271 | isvalue(bssgp.pDU_BSSGP_PAGING_CS.tLLI)) { |
| 272 | return bssgp.pDU_BSSGP_PAGING_CS.tLLI.tLLI_Value; |
| 273 | } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS)) { |
| 274 | return bssgp.pDU_BSSGP_FLOW_CONTROL_MS.tLLI.tLLI_Value; |
| 275 | } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK)) { |
| 276 | return bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK.tLLI.tLLI_Value; |
| 277 | } |
| 278 | /* TODO: Handover, PFC, LCS */ |
| 279 | return omit; |
| 280 | } |
| 281 | |
| 282 | /* |
| 283 | private function f_tbl_init() runs on BSSGP_CT { |
| 284 | var integer i; |
| 285 | for (i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 286 | ImsiTable[i] := -; |
| 287 | } |
| 288 | |
| 289 | for (i := 0; i < sizeof(TlliTable); i := i+1) { |
| 290 | TlliTable[i] := -; |
| 291 | } |
| 292 | } |
| 293 | */ |
| 294 | |
| 295 | private function f_tbl_client_add(hexstring imsi, OCT4 tlli, BssgpCellId cell_id, BSSGP_Client_CT vc_conn) |
| 296 | runs on BSSGP_CT { |
| 297 | var integer i; |
| 298 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
Harald Welte | c7872fa | 2018-02-18 14:06:12 +0100 | [diff] [blame] | 299 | if (not isvalue(ClientTable[i].comp_ref)) { |
| 300 | log("Adding Client=", vc_conn, ", IMSI=", imsi, ", TLLI=", tlli, ", index=", i); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 301 | ClientTable[i] := { |
| 302 | tlli := tlli, |
| 303 | tlli_old := omit, |
| 304 | imsi := imsi, |
| 305 | cell_id := cell_id, |
| 306 | comp_ref := vc_conn, |
| 307 | llc := - |
| 308 | }; |
| 309 | for (var integer j := 0; j < sizeof(ClientTable[i].llc); j := j+1) { |
| 310 | ClientTable[i].llc[j] := valueof(t_LLC_init(g_cfg.sgsn_role)); |
| 311 | } |
| 312 | return; |
| 313 | } |
| 314 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 315 | testcase.stop("Client Table full"); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | private function f_tbl_client_del(hexstring imsi, BSSGP_Client_CT vc_conn) runs on BSSGP_CT { |
| 319 | var integer i; |
| 320 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
Harald Welte | c7872fa | 2018-02-18 14:06:12 +0100 | [diff] [blame] | 321 | if (isvalue(ClientTable[i].imsi) and ClientTable[i].imsi == imsi) { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 322 | if (ClientTable[i].comp_ref != vc_conn) { |
Alexander Couzens | 2c15342 | 2018-06-12 18:10:30 +0200 | [diff] [blame] | 323 | setverdict(fail, "Cannot unregister index=", i, " IMSI ", imsi, " registred to ", |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 324 | ClientTable[i].comp_ref, " from ", vc_conn); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 325 | mtc.stop; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 326 | } |
| 327 | log("Removing Client IMSI=", imsi, ", index=", i); |
Alexander Couzens | 2c15342 | 2018-06-12 18:10:30 +0200 | [diff] [blame] | 328 | ClientTable[i] := { |
| 329 | tlli := -, |
| 330 | tlli_old := omit, |
| 331 | imsi := ''H, |
| 332 | cell_id := -, |
| 333 | comp_ref := null, |
| 334 | llc := - }; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 335 | return; |
| 336 | } |
| 337 | } |
Alexander Couzens | 56101c9 | 2018-07-31 15:55:34 +0200 | [diff] [blame] | 338 | log("Warning: Could not find client for IMSI ", imsi); |
| 339 | return; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 340 | } |
| 341 | |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 342 | /* TS 44.064 7.2.1.1 LLGMM-ASSIGN */ |
| 343 | private function f_tbl_client_llgmm_assign(OCT4 tlli_old, OCT4 tlli_new, BSSGP_Client_CT vc_conn) |
| 344 | runs on BSSGP_CT { |
| 345 | var integer i := f_tbl_idx_by_comp(vc_conn); |
| 346 | |
| 347 | if (tlli_old == 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) { |
| 348 | /* TLLI assignment */ |
| 349 | ClientTable[i].tlli := tlli_new; |
| 350 | ClientTable[i].tlli_old := omit; |
| 351 | } else if (tlli_old != 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) { |
| 352 | /* TLLI change: both active */ |
| 353 | ClientTable[i].tlli := tlli_new; |
| 354 | ClientTable[i].tlli_old := tlli_old; |
| 355 | } else if (tlli_old != 'FFFFFFFF'O and tlli_new == 'FFFFFFFF'O) { |
| 356 | /* TLLI unassignment: old shall be unassigned; new stays */ |
| 357 | ClientTable[i].tlli_old := omit; |
| 358 | } |
| 359 | } |
| 360 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 361 | private function f_tbl_comp_by_imsi(hexstring imsi) runs on BSSGP_CT return BSSGP_Client_CT { |
| 362 | var integer i; |
| 363 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
Harald Welte | c7872fa | 2018-02-18 14:06:12 +0100 | [diff] [blame] | 364 | if (isvalue(ClientTable[i].imsi) and isvalue(ClientTable[i].comp_ref) |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 365 | and ClientTable[i].imsi == imsi) { |
| 366 | return ClientTable[i].comp_ref; |
| 367 | } |
| 368 | } |
| 369 | setverdict(fail, "Couldn't find Component for IMSI ", imsi); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 370 | mtc.stop; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | private function f_tbl_comp_by_tlli(OCT4 tlli) runs on BSSGP_CT return BSSGP_Client_CT { |
| 374 | var integer i; |
| 375 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
Harald Welte | c7872fa | 2018-02-18 14:06:12 +0100 | [diff] [blame] | 376 | if (isvalue(ClientTable[i].comp_ref) and |
| 377 | (isvalue(ClientTable[i].tlli) and (ClientTable[i].tlli == tlli or |
| 378 | isvalue(ClientTable[i].tlli_old) and ClientTable[i].tlli_old == tlli) )) { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 379 | return ClientTable[i].comp_ref; |
| 380 | } |
| 381 | } |
| 382 | setverdict(fail, "Couldn't find Component for TLLI ", tlli); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 383 | mtc.stop; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | private function f_tbl_idx_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_CT return integer { |
| 387 | var integer i; |
| 388 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
Harald Welte | c7872fa | 2018-02-18 14:06:12 +0100 | [diff] [blame] | 389 | if (isvalue(ClientTable[i].comp_ref) and ClientTable[i].comp_ref == comp_ref) { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 390 | return i; |
| 391 | } |
| 392 | } |
| 393 | setverdict(fail, "Couldn't find Client for Component ", comp_ref); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 394 | mtc.stop; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | private function f_tbl_tlli_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_CT return OCT4 { |
| 398 | var integer i; |
| 399 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
Harald Welte | c7872fa | 2018-02-18 14:06:12 +0100 | [diff] [blame] | 400 | if (isvalue(ClientTable[i].tlli) and isvalue(ClientTable[i].comp_ref) |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 401 | and ClientTable[i].comp_ref == comp_ref) { |
| 402 | return ClientTable[i].tlli; |
| 403 | } |
| 404 | } |
| 405 | setverdict(fail, "Couldn't find TLLI for Component ", comp_ref); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 406 | mtc.stop; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | altstep as_allstate() runs on BSSGP_CT { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 410 | var BSSGP_Client_CT vc_conn; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 411 | var NsUnitdataIndication udi; |
| 412 | var NsStatusIndication nsi; |
| 413 | var ASP_Event evt; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 414 | var hexstring imsi; |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 415 | var OCT4 tlli, tlli_old; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 416 | var BssgpCellId cell_id; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 417 | |
| 418 | /* Respond to BLOCK for wrong NSVCI */ |
| 419 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(?, ?), 0)) -> value udi { |
| 420 | log("Rx BVC-BLOCK for unknown BVCI"); |
| 421 | f_sendStatus(BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp); |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 422 | } |
| 423 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 424 | /* Respond to RESET with correct BVCI/CellID */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 425 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, g_cfg.bvci, g_cfg.cell_id), 0)) -> value udi { |
| 426 | log("Rx BVC-RESET for Our BVCI=", g_cfg.bvci); |
| 427 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(g_cfg.bvci, g_cfg.cell_id), 0)); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 428 | f_change_state(BVC_S_UNBLOCKED); |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 429 | } |
| 430 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 431 | /* Respond to RESET for signalling BVCI 0 */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 432 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, g_cfg.cell_id), 0)) -> value udi { |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 433 | log("Rx BVC-RESET for Signaling BVCI=0"); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 434 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, g_cfg.cell_id), 0)); |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 435 | } |
| 436 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 437 | /* Respond to RESET with wrong NSEI/NSVCI */ |
| 438 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, ?, ?), 0)) -> value udi { |
| 439 | log("Rx BVC-RESET for unknown BVCI"); |
| 440 | f_sendStatus(BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp); |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 441 | } |
| 442 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 443 | /* default case of handling unknown PDUs */ |
| 444 | [] BSCP.receive(f_BnsUdInd(?, ?)) -> value udi { |
| 445 | log("Rx Unexpected BSSGP PDU ", udi.bssgp," in state ", g_ptp_bvc_state); |
| 446 | f_sendStatus(BSSGP_CAUSE_PDU_NOT_COMPATIBLE_WITH_PROTOCOL_STATE, udi.bssgp); |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 447 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 448 | /* Forwarding of ASP_Event and NsStatusIndication to user */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 449 | [] BSCP.receive(ASP_Event:?) -> value evt { |
| 450 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 451 | if (isbound(ClientTable[i].comp_ref)) { |
| 452 | BSSGP_SP.send(evt) to ClientTable[i].comp_ref; |
| 453 | } |
| 454 | } |
| 455 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 456 | [] BSCP.receive(NsStatusIndication:?) -> value nsi { |
| 457 | /* if we just became NS-unblocked, send a BCC-RESET */ |
| 458 | if (nsi.old_state != NSE_S_ALIVE_UNBLOCKED and nsi.new_state == NSE_S_ALIVE_UNBLOCKED) { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 459 | if (g_cfg.sgsn_role == false) { |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 460 | f_sendReset(); |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 461 | } |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 462 | /* Idea: We could send BVC-UNBLOCK here like some SGSN do */ |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 463 | } |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 464 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 465 | if (isbound(ClientTable[i].comp_ref)) { |
| 466 | BSSGP_SP.send(nsi) to ClientTable[i].comp_ref; |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | [] BSSGP_PROC.getcall(BSSGP_register_client:{?,?,?}) -> param(imsi, tlli, cell_id) sender vc_conn { |
| 472 | f_tbl_client_add(imsi, tlli, cell_id, vc_conn); |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 473 | BSSGP_PROC.reply(BSSGP_register_client:{imsi, tlli, cell_id}) to vc_conn; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 474 | } |
| 475 | [] BSSGP_PROC.getcall(BSSGP_unregister_client:{?}) -> param(imsi) sender vc_conn { |
| 476 | f_tbl_client_del(imsi, vc_conn); |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 477 | BSSGP_PROC.reply(BSSGP_unregister_client:{imsi}) to vc_conn; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 478 | } |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 479 | [] BSSGP_PROC.getcall(BSSGP_llgmm_assign:{?,?}) -> param(tlli_old, tlli) sender vc_conn { |
| 480 | f_tbl_client_llgmm_assign(tlli_old, tlli, vc_conn); |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 481 | BSSGP_PROC.reply(BSSGP_llgmm_assign:{tlli_old, tlli}) to vc_conn; |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 482 | } |
| 483 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | altstep as_blocked() runs on BSSGP_CT { |
Harald Welte | c27f684 | 2018-03-02 21:40:03 +0100 | [diff] [blame] | 487 | [g_T1.running] g_T1.timeout { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 488 | f_sendUnblock(); |
| 489 | } |
| 490 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0)) { |
| 491 | g_T1.stop; |
| 492 | f_change_state(BVC_S_UNBLOCKED); |
| 493 | } |
| 494 | [not g_cfg.sgsn_role] BSCP.receive(f_BnsUdInd(tr_BVC_RESET_ACK(g_cfg.bvci, omit), 0)) { |
| 495 | f_sendUnblock(); |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 496 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 497 | } |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 498 | |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 499 | private function f_send_bssgp_dec(BssgpDecoded dec, BSSGP_Client_CT vc_conn, BSSGP_SP_PT pt := BSSGP_SP) runs on BSSGP_CT { |
| 500 | if (ispresent(dec.l3_mt)) { |
| 501 | pt.send(dec.l3_mt) to vc_conn; |
| 502 | } else if (ispresent(dec.l3_mo)) { |
| 503 | pt.send(dec.l3_mo) to vc_conn; |
| 504 | } else if (ispresent(dec.sndcp)) { |
| 505 | pt.send(dec.sndcp) to vc_conn; |
| 506 | } else if (ispresent(dec.llc)) { |
| 507 | pt.send(dec.llc) to vc_conn; |
| 508 | } else { |
| 509 | pt.send(dec.bssgp) to vc_conn; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 514 | altstep as_unblocked() runs on BSSGP_CT { |
| 515 | var BSSGP_Client_CT vc_conn; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 516 | var NsUnitdataIndication udi; |
| 517 | var PDU_BSSGP bs_pdu; |
Harald Welte | 752abba | 2018-02-18 19:42:17 +0100 | [diff] [blame] | 518 | var PDU_LLC llc; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 519 | var PDU_L3_MS_SGSN l3_mo; |
| 520 | var PDU_L3_SGSN_MS l3_mt; |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 521 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 522 | /* bogus unblock, just respond with ACK */ |
| 523 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK(g_cfg.bvci), 0)) -> value udi { |
| 524 | BSCP.send(f_BnsUdReq(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0)); |
| 525 | } |
| 526 | /* Respond to BLOCK with BLOCK-ACK + change state */ |
| 527 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(g_cfg.bvci, ?), 0)) -> value udi { |
| 528 | BSCP.send(f_BnsUdReq(t_BVC_BLOCK_ACK(g_cfg.bvci), 0)); |
| 529 | g_T1.stop; |
| 530 | f_change_state(BVC_S_BLOCKED); |
| 531 | } |
Harald Welte | c27f684 | 2018-03-02 21:40:03 +0100 | [diff] [blame] | 532 | [g_T1.running] g_T1.timeout { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 533 | f_sendBlock(BSSGP_CAUSE_OM_INTERVENTION); |
| 534 | } |
| 535 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK_ACK(g_cfg.bvci), 0)) -> value udi { |
| 536 | g_T1.stop; |
| 537 | f_change_state(BVC_S_BLOCKED); |
| 538 | } |
| 539 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET_ACK(g_cfg.bvci, g_cfg.cell_id), 0)) -> value udi { |
| 540 | g_T2.stop; |
| 541 | f_change_state(BVC_S_UNBLOCKED); |
| 542 | } |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 543 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 544 | /* simply acknowledge all Flow Control Messages */ |
Harald Welte | edcdd90 | 2018-03-02 22:04:54 +0100 | [diff] [blame] | 545 | [g_cfg.sgsn_role] BSCP.receive(f_BnsUdInd(tr_BVC_FC_BVC, g_cfg.bvci)) -> value udi { |
| 546 | var OCT1 tag := udi.bssgp.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value; |
| 547 | BSCP.send(f_BnsUdReq(t_BVC_FC_BVC_ACK(tag), g_cfg.bvci)); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 548 | } |
Harald Welte | edcdd90 | 2018-03-02 22:04:54 +0100 | [diff] [blame] | 549 | /* |
| 550 | [g_cfg.sgsn_role] BSCP.receive(f_BnsUdInd(t_BVC_FC_MS, g_cfg.bvci)) { |
| 551 | BSCP.send(f_BnsUdReq(t_BVC_FC_MS_ACK, g_cfg.bvci)); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 552 | } |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 553 | */ |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 554 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 555 | /* FIXME: CS PAGING: dispatch by IMSI */ |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 556 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 557 | /* PS PAGING: dispatch by IMSI */ |
| 558 | [] BSCP.receive(f_BnsUdInd(tr_BSSGP_PS_PAGING(g_cfg.bvci), g_cfg.bvci)) -> value udi { |
| 559 | var hexstring imsi := udi.bssgp.pDU_BSSGP_PAGING_PS.iMSI.digits |
| 560 | vc_conn := f_tbl_comp_by_imsi(imsi); |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 561 | f_send_bssgp_dec(f_dec_bssgp(udi.bssgp), vc_conn); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 562 | } |
| 563 | |
Harald Welte | 001b0da | 2019-03-21 21:30:47 +0100 | [diff] [blame] | 564 | /* Any other PTP BSSGP message: If it has TLLi, route to component; otherwise broadcast */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 565 | [] BSCP.receive(f_BnsUdInd(?, g_cfg.bvci)) -> value udi { |
| 566 | var BssgpDecoded dec := f_dec_bssgp(udi.bssgp); |
| 567 | var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp); |
| 568 | if (isvalue(tlli)) { |
| 569 | vc_conn := f_tbl_comp_by_tlli(valueof(tlli)); |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 570 | f_send_bssgp_dec(dec, vc_conn); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 571 | } else { |
| 572 | log("No TLLI: Broadcasting ", dec); |
| 573 | /* broadcast this message to all components */ |
| 574 | // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;" |
| 575 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 576 | if (isbound(ClientTable[i].comp_ref)) { |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 577 | f_send_bssgp_dec(dec, ClientTable[i].comp_ref); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 578 | } |
| 579 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 580 | } |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 581 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 582 | |
Harald Welte | 001b0da | 2019-03-21 21:30:47 +0100 | [diff] [blame] | 583 | /* Any other SIG BSSGP message: If it has TLLi, route to component; otherwise broadcast */ |
| 584 | [] BSCP.receive(f_BnsUdInd(?, 0)) -> value udi { |
| 585 | var BssgpDecoded dec := f_dec_bssgp(udi.bssgp); |
| 586 | var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp); |
| 587 | if (isvalue(tlli)) { |
| 588 | vc_conn := f_tbl_comp_by_tlli(valueof(tlli)); |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 589 | f_send_bssgp_dec(dec, vc_conn, BSSGP_SP_SIG); |
Harald Welte | 001b0da | 2019-03-21 21:30:47 +0100 | [diff] [blame] | 590 | } else { |
| 591 | log("No TLLI: Broadcasting ", dec); |
| 592 | /* broadcast this message to all components */ |
| 593 | // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;" |
| 594 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 595 | if (isbound(ClientTable[i].comp_ref)) { |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 596 | f_send_bssgp_dec(dec, vc_conn, BSSGP_SP_SIG); |
Harald Welte | 001b0da | 2019-03-21 21:30:47 +0100 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | |
Harald Welte | 1e5a02d | 2019-05-03 00:50:48 +0200 | [diff] [blame] | 603 | /* ConnHdlr sends BSSGP on BVCI=0 port: forward it to BSSGP Codec Port */ |
Stefan Sperling | f82bbb6 | 2018-05-03 19:14:28 +0200 | [diff] [blame] | 604 | [] BSSGP_SP_SIG.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn { |
| 605 | BSCP.send(f_BnsUdReq(bs_pdu, 0)); |
| 606 | } |
| 607 | |
Harald Welte | 1e5a02d | 2019-05-03 00:50:48 +0200 | [diff] [blame] | 608 | /* ConnHdlr sends BSSGP on BVCI=PTP port: forward it to BSSGP Codec Port */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 609 | [] BSSGP_SP.receive(PDU_BSSGP:?) -> value bs_pdu sender vc_conn { |
| 610 | BSCP.send(f_BnsUdReq(bs_pdu, g_cfg.bvci)); |
| 611 | } |
| 612 | |
Harald Welte | 1e5a02d | 2019-05-03 00:50:48 +0200 | [diff] [blame] | 613 | /* ConnHdlr sends L3: Encode and send as UL_UD / DL_UD */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 614 | [g_cfg.sgsn_role] BSSGP_SP.receive(PDU_L3_SGSN_MS:?) -> value l3_mt sender vc_conn { |
| 615 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
| 616 | var octetstring l3_enc := enc_PDU_L3_SGSN_MS(l3_mt); |
| 617 | var BIT4 sapi := f_llc_sapi_by_l3_mt(l3_mt); |
| 618 | var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]); |
| 619 | var octetstring llc_enc := enc_PDU_LLC(valueof(ts_LLC_UI(l3_enc, sapi, '1'B, n_u))); |
Harald Welte | 8d1d893 | 2019-05-03 00:41:41 +0200 | [diff] [blame] | 620 | BSCP.send(f_BnsUdReq(ts_BSSGP_DL_UD(ClientTable[idx].tlli, llc_enc), g_cfg.bvci)); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 621 | } |
Harald Welte | 425f782 | 2019-05-03 00:48:46 +0200 | [diff] [blame] | 622 | [not g_cfg.sgsn_role] BSSGP_SP.receive(PDU_L3_MS_SGSN:?) -> value l3_mo sender vc_conn { |
| 623 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
| 624 | var octetstring l3_enc := enc_PDU_L3_MS_SGSN(l3_mo); |
| 625 | var BIT4 sapi := f_llc_sapi_by_l3_mo(l3_mo); |
| 626 | var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]); |
| 627 | var octetstring llc_enc := enc_PDU_LLC(valueof(ts_LLC_UI(l3_enc, sapi, '1'B, n_u))); |
| 628 | BSCP.send(f_BnsUdReq(ts_BSSGP_UL_UD(ClientTable[idx].tlli, ClientTable[idx].cell_id, llc_enc), g_cfg.bvci)); |
| 629 | } |
Harald Welte | 752abba | 2018-02-18 19:42:17 +0100 | [diff] [blame] | 630 | |
Harald Welte | 1b85bf3 | 2019-05-03 00:49:25 +0200 | [diff] [blame] | 631 | /* ConnHdlr sends raw LLC: Encode and send as UL_UD / DL_UD */ |
| 632 | [not g_cfg.sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn { |
Harald Welte | 752abba | 2018-02-18 19:42:17 +0100 | [diff] [blame] | 633 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
| 634 | var octetstring llc_enc := enc_PDU_LLC(llc); |
| 635 | BSCP.send(f_BnsUdReq(ts_BSSGP_UL_UD(ClientTable[idx].tlli, ClientTable[idx].cell_id, llc_enc), g_cfg.bvci)); |
| 636 | } |
Harald Welte | 1b85bf3 | 2019-05-03 00:49:25 +0200 | [diff] [blame] | 637 | [g_cfg.sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn { |
| 638 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
| 639 | var octetstring llc_enc := enc_PDU_LLC(llc); |
| 640 | BSCP.send(f_BnsUdReq(ts_BSSGP_DL_UD(ClientTable[idx].tlli, llc_enc), g_cfg.bvci)); |
| 641 | } |
| 642 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 643 | } |
| 644 | |
Alexander Couzens | cdfb751 | 2018-07-31 15:37:14 +0200 | [diff] [blame] | 645 | function f_llc_get_n_u_tx(inout LLC_Entity llc) return uint9_t { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 646 | var uint9_t ret := llc.n_u_tx_next; |
| 647 | llc.n_u_tx_next := llc.n_u_tx_next + 1; |
| 648 | return ret; |
| 649 | } |
| 650 | |
Alexander Couzens | cdfb751 | 2018-07-31 15:37:14 +0200 | [diff] [blame] | 651 | function f_llc_sapi_by_l3_mo(PDU_L3_MS_SGSN l3_mo) return BIT4 { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 652 | if (ischosen(l3_mo.msgs.gprs_mm)) { |
| 653 | return c_LLC_SAPI_LLGMM; |
| 654 | } else if (ischosen(l3_mo.msgs.gprs_sm)) { |
Harald Welte | d471901 | 2018-02-17 16:45:06 +0100 | [diff] [blame] | 655 | return c_LLC_SAPI_LLGMM; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 656 | } else if (ischosen(l3_mo.msgs.sms)) { |
| 657 | return c_LLC_SAPI_LLSMS; |
| 658 | } |
| 659 | setverdict(fail, "No LLC SAPI for ", l3_mo); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 660 | mtc.stop; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | private function f_llc_sapi_by_l3_mt(PDU_L3_SGSN_MS l3_mt) return BIT4 { |
| 664 | if (ischosen(l3_mt.msgs.gprs_mm)) { |
| 665 | return c_LLC_SAPI_LLGMM; |
| 666 | } else if (ischosen(l3_mt.msgs.gprs_sm)) { |
Harald Welte | d471901 | 2018-02-17 16:45:06 +0100 | [diff] [blame] | 667 | return c_LLC_SAPI_LLGMM; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 668 | } else if (ischosen(l3_mt.msgs.sms)) { |
| 669 | return c_LLC_SAPI_LLSMS; |
| 670 | } |
| 671 | setverdict(fail, "No LLC SAPI for ", l3_mt); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 672 | mtc.stop; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | |
| 676 | |
| 677 | private function f_ScanEvents() runs on BSSGP_CT { |
| 678 | log("matching against ", tr_BVC_RESET(?, g_cfg.bvci, g_cfg.cell_id)); |
| 679 | |
| 680 | while (true) { |
| 681 | alt { |
| 682 | [g_ptp_bvc_state == BVC_S_BLOCKED] as_blocked(); |
| 683 | [g_ptp_bvc_state == BVC_S_UNBLOCKED] as_unblocked(); |
| 684 | [] as_allstate(); |
| 685 | } |
| 686 | } /* while */ |
| 687 | } |
| 688 | |
| 689 | /* PDU_BSSGP enhanced with LLC and possibly L3 decoded payloads */ |
| 690 | type record BssgpDecoded { |
| 691 | PDU_BSSGP bssgp, |
| 692 | PDU_LLC llc optional, |
| 693 | PDU_L3_MS_SGSN l3_mo optional, |
Harald Welte | a2526a8 | 2018-02-18 19:03:36 +0100 | [diff] [blame] | 694 | PDU_L3_SGSN_MS l3_mt optional, |
| 695 | PDU_SN sndcp optional |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | /* Decode a PDU_BSSGP into a BssgpDecoded (i.e. with LLC/L3 decoded, as applicable) */ |
| 699 | private function f_dec_bssgp(PDU_BSSGP bssgp) runs on BSSGP_CT return BssgpDecoded { |
| 700 | var BssgpDecoded dec := { |
| 701 | bssgp := bssgp, |
| 702 | llc := omit, |
| 703 | l3_mo := omit, |
Harald Welte | a2526a8 | 2018-02-18 19:03:36 +0100 | [diff] [blame] | 704 | l3_mt := omit, |
| 705 | sndcp := omit |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 706 | }; |
| 707 | |
| 708 | /* Decode LLC, if it is a PDU that contains LLC */ |
| 709 | if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) { |
| 710 | dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_DL_UNITDATA.lLC_PDU.lLC_PDU); |
| 711 | } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) { |
| 712 | dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_UL_UNITDATA.lLC_PDU.lLC_PDU); |
| 713 | } |
| 714 | |
| 715 | /* Decode L3, if it is a LLC PDU containing L3 */ |
| 716 | if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_L3)) { |
| 717 | if (g_cfg.sgsn_role) { |
| 718 | dec.l3_mo := dec_PDU_L3_MS_SGSN(dec.llc.pDU_LLC_UI.information_field_UI); |
| 719 | } else { |
| 720 | dec.l3_mt := dec_PDU_L3_SGSN_MS(dec.llc.pDU_LLC_UI.information_field_UI); |
| 721 | } |
| 722 | } |
Harald Welte | a2526a8 | 2018-02-18 19:03:36 +0100 | [diff] [blame] | 723 | |
| 724 | /* Decode SNDCP, if it is a LLC PDU containing user plane data */ |
| 725 | if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_USER)) { |
| 726 | dec.sndcp := dec_PDU_SN(dec.llc.pDU_LLC_UI.information_field_UI); |
| 727 | } |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 728 | return dec; |
| 729 | } |
| 730 | |
Alexander Couzens | 0e510e6 | 2018-07-28 23:06:00 +0200 | [diff] [blame] | 731 | function f_bssgp_client_register(hexstring imsi, OCT4 tlli, BssgpCellId cell_id, BSSGP_PROC_PT PT := BSSGP_PROC[0]) |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 732 | runs on BSSGP_Client_CT { |
| 733 | PT.call(BSSGP_register_client:{imsi, tlli, cell_id}) { |
| 734 | [] PT.getreply(BSSGP_register_client:{imsi, tlli, cell_id}) {}; |
| 735 | } |
| 736 | } |
| 737 | |
Alexander Couzens | 0e510e6 | 2018-07-28 23:06:00 +0200 | [diff] [blame] | 738 | function f_bssgp_client_unregister(hexstring imsi, BSSGP_PROC_PT PT := BSSGP_PROC[0]) |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 739 | runs on BSSGP_Client_CT { |
| 740 | PT.call(BSSGP_unregister_client:{imsi}) { |
| 741 | [] PT.getreply(BSSGP_unregister_client:{imsi}) {}; |
| 742 | } |
| 743 | } |
| 744 | |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 745 | /* TS 44.064 7.2.1.1 LLGMM-ASSIGN */ |
Alexander Couzens | 0e510e6 | 2018-07-28 23:06:00 +0200 | [diff] [blame] | 746 | function f_bssgp_client_llgmm_assign(OCT4 tlli_old, OCT4 tlli_new, BSSGP_PROC_PT PT := BSSGP_PROC[0]) |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 747 | runs on BSSGP_Client_CT { |
| 748 | PT.call(BSSGP_llgmm_assign:{tlli_old, tlli_new}) { |
| 749 | [] PT.getreply(BSSGP_llgmm_assign:{tlli_old, tlli_new}) {}; |
| 750 | } |
| 751 | } |
| 752 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 753 | |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 754 | } |