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