Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 1 | module Test { |
| 2 | |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 3 | import from General_Types all; |
| 4 | import from Osmocom_Types all; |
| 5 | import from GSM_Types all; |
| 6 | import from GSM_RR_Types all; |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 7 | import from Osmocom_Gb_Types all; |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 8 | import from BSSGP_Types all; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 9 | import from BSSGP_Emulation all; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 10 | import from NS_Types all; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 11 | import from NS_Emulation all; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 12 | import from LLC_Types all; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 13 | import from LLC_Templates all; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 14 | import from RLCMAC_Types all; |
| 15 | import from RLCMAC_CSN1_Types all; |
| 16 | import from LAPDm_RAW_PT all; |
| 17 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 18 | modulepar { |
| 19 | BssgpConfig mp_gb_cfg := { |
| 20 | nsei := 96, |
| 21 | bvci := 196, |
| 22 | cell_id := { |
| 23 | ra_id := { |
| 24 | lai := { |
| 25 | mcc_mnc := '26242F'H, lac := 13135 |
| 26 | }, |
| 27 | rac := 0 |
| 28 | }, |
| 29 | cell_id := 20960 |
| 30 | }, |
| 31 | sgsn_role := true |
| 32 | }; |
| 33 | } |
| 34 | |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 35 | type record MmContext { |
| 36 | octetstring imsi optional, |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 37 | GprsTlli tlli, |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 38 | uint9_t n_u |
| 39 | }; |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 40 | |
| 41 | type component dummy_CT { |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 42 | var lapdm_CT lapdm_component; |
| 43 | port LAPDm_PT L1; |
| 44 | |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 45 | port BSSGP_PT BSSGP; |
| 46 | var NS_CT ns_component; |
| 47 | var BSSGP_CT bssgp_component; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 48 | |
| 49 | var MmContext g_mmctx := { |
Harald Welte | acc93ab | 2018-03-02 21:39:09 +0100 | [diff] [blame^] | 50 | tlli := 'FFFFFFFF'O, |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 51 | n_u := 0 |
| 52 | }; |
| 53 | |
| 54 | var boolean g_initialized := false; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | function f_init() runs on dummy_CT { |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 58 | if (g_initialized == true) { |
| 59 | return; |
| 60 | } |
| 61 | g_initialized := true; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 62 | /* create a new NS component */ |
| 63 | ns_component := NS_CT.create; |
| 64 | bssgp_component := BSSGP_CT.create; |
| 65 | /* connect our BSSGP port to the BSSGP Emulation */ |
| 66 | connect(self:BSSGP, bssgp_component:BSSGP_SP); |
| 67 | /* connect lower-end of BSSGP with BSSGP_CODEC_PORT (maps to NS_PT*/ |
| 68 | connect(bssgp_component:BSCP, ns_component:NS_SP); |
| 69 | /* connect lower-end of NS emulation to NS_CODEC_PORT (on top of IPl4) */ |
| 70 | map(ns_component:NSCP, system:NS_CODEC_PORT); |
| 71 | ns_component.start(NSStart()); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 72 | bssgp_component.start(BssgpStart(mp_gb_cfg)); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 73 | |
| 74 | lapdm_component := lapdm_CT.create; |
| 75 | connect(self:L1, lapdm_component:LAPDM_SP); |
| 76 | map(lapdm_component:L1CTL, system:L1CTL); |
| 77 | lapdm_component.start(LAPDmStart()); |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 78 | } |
| 79 | |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 80 | function f_bssgp_dec_and_log(in octetstring inp) { |
| 81 | log("BSSGP Input: ", inp); |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 82 | var PDU_BSSGP dec := dec_PDU_BSSGP(inp); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 83 | log("BSSGP Decoded: ", dec); |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 86 | testcase TC_selftest_bssgp() runs on dummy_CT { |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 87 | const octetstring c_bvc_reset_pcu := '2204820000078108088832f44000c80051e0'O; |
| 88 | const octetstring c_bvc_reset_q := '2204820000078100'O; |
| 89 | const octetstring c_status_pcu := '4107810515882204820000078103'O; |
| 90 | const octetstring c_reset_ack_q := '2304820000'O; |
| 91 | const octetstring c_reset_ack_pcu := '23048200c4'O; |
| 92 | const octetstring c_unblock_pcu := '24048200c4'O; |
| 93 | const octetstring c_unblock_ack_q := '25048200c4'O; |
| 94 | const octetstring c_fc_bvc_pcu := '261e8101058200fa038200c8018200fa1c8200c806820000'O; |
| 95 | const octetstring c_fc_bvc_ack_q := '271e8101'O; |
| 96 | const octetstring c_gmm_mo_att_req := '01bb146ddd000004088832f44000c80051e000800e003b01c001080103e5e000110a0005f4fb146ddd32f44000c8001d1b53432b37159ef9090070000dd9c6321200e00019b32c642401c0002017057bf0ec'O; |
| 97 | const octetstring c_gmm_mt_ac_req := '00bb146ddd0050001682ffff0a8204030e9c41c001081200102198c72477ea104895e8b959acc58b108182f4d045'O; |
| 98 | const octetstring c_gmm_mo_ac_resp := '01bb146ddd000004088832f44000c80051e000800e000e01c00508130122fa361f5fdd623d'O; |
| 99 | const octetstring c_gmm_mt_att_acc := '00bb146ddd0050001682ffff0a8204030e9841c005080201340432f44000c8001805f4fb146ddd0967d0'O; |
| 100 | const octetstring c_gmm_mt_det_req := '00bb146ddd0050001682ffff0a8204030e8941c00908050215f0b6'O; |
| 101 | const octetstring c_gmm_mo_att_cpl := '01fb146ddd000004088832f44000c80051e000800e000801c009080339d7bc'O; |
| 102 | |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 103 | f_bssgp_dec_and_log(c_bvc_reset_pcu); |
| 104 | f_bssgp_dec_and_log(c_bvc_reset_q); |
| 105 | f_bssgp_dec_and_log(c_status_pcu); |
| 106 | f_bssgp_dec_and_log(c_reset_ack_q); |
| 107 | f_bssgp_dec_and_log(c_reset_ack_pcu); |
| 108 | f_bssgp_dec_and_log(c_unblock_pcu); |
| 109 | f_bssgp_dec_and_log(c_unblock_ack_q); |
| 110 | f_bssgp_dec_and_log(c_fc_bvc_pcu); |
| 111 | f_bssgp_dec_and_log(c_fc_bvc_ack_q); |
| 112 | f_bssgp_dec_and_log(c_gmm_mo_att_req); |
| 113 | f_bssgp_dec_and_log(c_gmm_mt_ac_req); |
| 114 | f_bssgp_dec_and_log(c_gmm_mo_ac_resp); |
| 115 | f_bssgp_dec_and_log(c_gmm_mt_att_acc); |
| 116 | f_bssgp_dec_and_log(c_gmm_mt_det_req); |
| 117 | f_bssgp_dec_and_log(c_gmm_mo_att_cpl); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 118 | |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 119 | log(ts_BSSGP_PS_PAGING_IMSI(196, '262420123456789'H)); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | function f_ns_assert_prepr(in octetstring a, in octetstring b) { |
| 123 | log("NS Input: ", a); |
| 124 | log("NS Expected: ", b); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 125 | |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 126 | if (a != b) { |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 127 | setverdict(fail); |
| 128 | } else { |
| 129 | setverdict(pass); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | function f_ns_dec_and_log(in octetstring inp) { |
| 134 | log("NS Input: ", inp); |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 135 | var PDU_NS dec := dec_PDU_NS(inp); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 136 | log("NS Decoded: ", dec); |
| 137 | } |
| 138 | |
| 139 | testcase TC_selftest_ns() runs on dummy_CT { |
| 140 | const octetstring c_ns_reset_pcu := '000000c4271e813d'O; |
| 141 | |
| 142 | /* single byte length to two byte length */ |
| 143 | f_ns_assert_prepr('04058101'O, '0405000101'O); |
| 144 | f_ns_assert_prepr('040589000102030405060708'O, '04050009000102030405060708'O); |
| 145 | /* two byte length to two byte length */ |
| 146 | f_ns_assert_prepr('0405000101'O, '0405000101'O); |
| 147 | /* special case: NS-UNITDATA */ |
| 148 | f_ns_assert_prepr('00aabbccddeeffaa29822342'O, '00aabbccddeeffaa2900022342'O); |
| 149 | /* multiple TLVs */ |
| 150 | f_ns_assert_prepr('234281aa4382bbbb'O, '23420001aa430002bbbb'O); |
| 151 | /* zero-length */ |
| 152 | f_ns_assert_prepr('230080'O, '23000000'O); |
| 153 | |
| 154 | f_ns_dec_and_log(c_ns_reset_pcu); |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 157 | const octetstring gmm_auth_req := '081200102198c72477ea104895e8b959acc58b108182'O; |
| 158 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 159 | /* Wrap downlink GMM into LLC, encode + send it via BSSGP to PCU */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 160 | function tx_gmm(BIT1 c_r, in octetstring gmm_pdu, BIT4 sapi := c_LLC_SAPI_LLGMM) runs on dummy_CT { |
| 161 | var PDU_LLC llc; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 162 | |
Harald Welte | 0e23a8f | 2017-12-12 16:47:48 +0100 | [diff] [blame] | 163 | //log("GMM Tx: ", dec_PDU_L3_SGSN_MS(gmm_pdu)); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 164 | |
| 165 | log(c_r, g_mmctx.n_u, gmm_pdu, sapi); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 166 | llc := valueof(ts_LLC_UI(gmm_pdu, sapi, c_r, g_mmctx.n_u)); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 167 | log(llc); |
| 168 | g_mmctx.n_u := g_mmctx.n_u + 1; |
| 169 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 170 | log(ts_BSSGP_DL_UD(g_mmctx.tlli, enc_PDU_LLC(llc))); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 171 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 172 | BSSGP.send(ts_BSSGP_DL_UD(g_mmctx.tlli, enc_PDU_LLC(llc))); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 173 | } |
| 174 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 175 | /* Establish BSSGP connection to PCU */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 176 | function f_bssgp_establish() runs on dummy_CT { |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 177 | timer T:= 60.0; |
| 178 | |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 179 | f_init(); |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 180 | T.start |
| 181 | alt { |
| 182 | [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { } |
| 183 | [] BSSGP.receive { repeat; } |
| 184 | [] T.timeout { setverdict(fail); } |
| 185 | } |
| 186 | T.stop |
| 187 | log("BSSGP successfully initialized"); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 190 | /* Send PS-PAGING via BSSGP to PCU, expect it to show up on L1/Um */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 191 | testcase TC_paging() runs on dummy_CT { |
| 192 | var hexstring imsi := '262420123456789'H; |
| 193 | var BssgpBvci bvci := 196; |
| 194 | var GsmTmsi tmsi := hex2int('01234567'H); |
| 195 | |
| 196 | f_bssgp_establish(); |
| 197 | |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 198 | BSSGP.send(ts_BSSGP_PS_PAGING_IMSI(bvci, imsi)); |
| 199 | BSSGP.send(ts_BSSGP_PS_PAGING_PTMSI(bvci, imsi, tmsi)); |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 200 | |
| 201 | while (true) { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 202 | var BssgpDecoded bd; |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 203 | alt { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 204 | [] BSSGP.receive(tr_BD_L3_MT(?)) -> value bd { |
| 205 | log("BSSGP Rx: ", bd); |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 206 | } |
| 207 | [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { repeat; } |
| 208 | [] BSSGP.receive { repeat; } |
| 209 | } |
| 210 | } |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 211 | } |
| 212 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 213 | /* Establish an UL TBF: Tune to ARFCN, send RACH, receive AGCH, enable TBF Rx */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 214 | function f_establish_ul_tbf() runs on dummy_CT { |
| 215 | timer T := 5.0; |
| 216 | var BCCH_tune_req tune_req := { { false, 871 }, true }; |
| 217 | L1.send(tune_req); |
| 218 | /* FIXME: wait for confirm */ |
| 219 | |
| 220 | var TBF_establish_req est_req := { ra := hex2int('7B'H) }; |
| 221 | L1.send(est_req); |
| 222 | T.start; |
| 223 | /* FIXME: wait for confirm */ |
| 224 | alt { |
| 225 | [] L1.receive(TBF_establish_res:?) {} |
| 226 | [] L1.receive { repeat; } |
| 227 | [] T.timeout { setverdict(fail); } |
| 228 | } |
| 229 | T.stop; |
| 230 | } |
| 231 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 232 | /* Template fro uplink Data block */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 233 | template RlcmacUlBlock t_RLCMAC_UL_DATA(template uint5_t tfi, template uint4_t cv, template uint7_t bsn, |
| 234 | template LlcBlocks blocks := {}, template boolean stall := false) := { |
| 235 | data := { |
| 236 | mac_hdr := { |
| 237 | payload_type := MAC_PT_RLC_DATA, |
| 238 | countdown := cv, |
| 239 | stall_ind := false, |
| 240 | retry := false, |
| 241 | spare := '0'B, |
| 242 | pfi_ind := false, |
| 243 | tfi := tfi, |
| 244 | tlli_ind := false, |
| 245 | bsn := bsn, |
| 246 | e := false |
| 247 | }, |
| 248 | tlli := omit, |
| 249 | pfi := omit, |
| 250 | blocks := blocks |
| 251 | } |
| 252 | } |
| 253 | template RlcmacUlBlock t_RLCMAC_UL_DATA_TLLI(template uint5_t tfi, template uint4_t cv, template uint7_t bsn, |
| 254 | template LlcBlocks blocks := {}, template boolean stall := false, template GprsTlli tlli) modifies t_RLCMAC_UL_DATA := { |
| 255 | data := { |
| 256 | tlli := tlli |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | template DlMacHeader t_RLCMAC_DlMacH(template MacPayloadType pt, template MacRrbp rrbp, template |
| 261 | uint3_t usf) := { |
| 262 | payload_type := pt, |
| 263 | rrbp := rrbp, |
Harald Welte | 0e23a8f | 2017-12-12 16:47:48 +0100 | [diff] [blame] | 264 | rrbp_valid := ispresent(rrbp), |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 265 | usf := usf |
| 266 | } |
| 267 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 268 | /* Receive Template for Downlink ACK/NACK */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 269 | template RlcmacDlBlock tr_RLCMAC_ACK_NACK(template uint5_t ul_tfi, template GprsTlli tlli := ?) := { |
| 270 | ctrl := { |
| 271 | mac_hdr := { |
| 272 | payload_type := (MAC_PT_RLCMAC_NO_OPT, MAC_PT_RLCMAC_OPT), |
| 273 | rrbp:= ?, |
| 274 | rrbp_valid := true, |
| 275 | usf := ? |
| 276 | }, |
| 277 | opt := *, |
| 278 | payload := { |
| 279 | msg_type := PACKET_UL_ACK_NACK, |
| 280 | u := { |
| 281 | ul_ack_nack := { |
| 282 | page_mode := ?, |
| 283 | msg_excape := ?, |
| 284 | uplink_tfi := ul_tfi, |
| 285 | is_egprs := '0'B, |
| 286 | gprs := { |
| 287 | ch_coding_cmd := ?, |
| 288 | ack_nack_desc := ?, |
| 289 | cont_res_tlli_present := ?, |
| 290 | cont_res_tlli := tlli, |
| 291 | pkt_ta_present := ?, |
| 292 | pkt_ta := *, |
| 293 | pwr_ctrl_present := ?, |
| 294 | pwr_ctrl := * |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 302 | /* Template for Uplink MAC Control Header */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 303 | template UlMacCtrlHeader t_RLCMAC_UlMacCtrlH(template MacPayloadType pt, template boolean retry := false) := { |
| 304 | payload_type := pt, |
| 305 | spare := '00000'B, |
| 306 | retry := retry |
| 307 | } |
| 308 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 309 | /* Template for Uplink Conntrol ACK */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 310 | template RlcmacUlBlock ts_RLCMAC_CTRL_ACK(GprsTlli tlli, CtrlAck ack := MS_RCVD_TWO_RLC_SAME_RTI_DIFF_RBSN) := { |
| 311 | ctrl := { |
| 312 | mac_hdr := t_RLCMAC_UlMacCtrlH(MAC_PT_RLCMAC_NO_OPT), |
| 313 | payload := { |
| 314 | msg_type := PACKET_CONTROL_ACK, |
| 315 | u := { |
| 316 | ctrl_ack := { |
| 317 | tlli := tlli, |
| 318 | ctrl_ack := ack |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 325 | /* Template for a LlcBlock (part of a LLC frame inside RlcMac?lDataBlock */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 326 | template LlcBlock t_RLCMAC_LLCBLOCK(octetstring data, BIT1 more := '0'B, boolean e := true) := { |
| 327 | hdr := { |
| 328 | length_ind := lengthof(data), |
| 329 | more := more, |
| 330 | e := e |
| 331 | }, |
| 332 | payload := data |
| 333 | } |
| 334 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 335 | /* compute a random TLLI; FIXME: what about TLLI prefix / local/foreign/...? */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 336 | function f_random_tlli() return GprsTlli { |
Harald Welte | acc93ab | 2018-03-02 21:39:09 +0100 | [diff] [blame^] | 337 | var GprsTlli tlli := f_rnd_octstring(4); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 338 | return tlli; |
| 339 | } |
| 340 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 341 | /* Send a single Uplink Block via Um; Verify reception on BSSGP; Expect UL_ACK on Um */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 342 | function f_single_ul_block(GprsCodingScheme cs) runs on dummy_CT { |
| 343 | var GprsTlli tlli := f_random_tlli(); |
| 344 | var octetstring payload := '01020304'O; |
| 345 | |
| 346 | /* establish upling TBF */ |
| 347 | f_establish_ul_tbf(); |
| 348 | |
| 349 | /* Generate LLC PDU consisting of single RLC block and send it via simulated MS */ |
| 350 | var template RlcmacUlBlock blk := t_RLCMAC_UL_DATA_TLLI(0, 0, 0, {t_RLCMAC_LLCBLOCK(payload)}, false, tlli); |
| 351 | L1.send(RLCMAC_ph_data_req:{tbf_id := 0, cs := cs, block := blk}); |
| 352 | /* ensure that this LLC-PDU arrives from the right TLLI at the (simulated) SGSN */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 353 | BSSGP.receive(tr_BD_BSSGP(tr_BSSGP_UL_UD(tlli, ?, payload))); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 354 | |
| 355 | /* ensure the MS eceives an UL_ACK_NACK */ |
| 356 | alt { |
| 357 | [] L1.receive(RLCMAC_ph_data_ind:{cs:=?, block:=tr_RLCMAC_ACK_NACK(0, tlli)}) { }; |
| 358 | [] L1.receive { repeat; }; |
| 359 | } |
| 360 | log("found matching ACK/NACK"); |
| 361 | /* send CTRL ACK in uplink */ |
| 362 | //L1.send(FIXME); |
| 363 | } |
| 364 | |
| 365 | testcase TC_rach() runs on dummy_CT { |
| 366 | var hexstring imsi := '262420123456789'H; |
| 367 | var BssgpBvci bvci := 196; |
| 368 | var GsmTmsi tmsi := hex2int('01234567'H); |
| 369 | |
| 370 | f_init(); |
| 371 | |
| 372 | f_bssgp_establish(); |
| 373 | |
| 374 | f_single_ul_block(CS1); |
| 375 | |
| 376 | while (true) { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 377 | var BssgpDecoded bd; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 378 | var RLCMAC_ph_data_ind dl_msg; |
| 379 | alt { |
| 380 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 381 | [] BSSGP.receive(tr_BD_BSSGP(?)) -> value bd { |
| 382 | log("BSSGP Rx: ", bd); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 383 | } |
| 384 | [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { repeat; } |
| 385 | [] BSSGP.receive { repeat; } |
| 386 | |
| 387 | [] L1.receive(RLCMAC_ph_data_ind:?) -> value dl_msg { |
| 388 | log("L1 DL: ", dl_msg); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | |
| 395 | testcase TC_nsem() runs on dummy_CT { |
| 396 | |
| 397 | f_bssgp_establish(); |
| 398 | |
| 399 | while (true) { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 400 | var BssgpDecoded bd; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 401 | alt { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 402 | [] BSSGP.receive(tr_BD_BSSGP(?)) -> value bd { |
| 403 | log("BSSGP Rx: ", bd); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 404 | //log("GMM Rx: ", dec_PDU_L3_MS_SGSN(pdu.payload)); |
Harald Welte | acc93ab | 2018-03-02 21:39:09 +0100 | [diff] [blame^] | 405 | g_mmctx.tlli := bd.bssgp.pDU_BSSGP_UL_UNITDATA.tLLI; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 406 | tx_gmm(LLC_CR_DL_CMD, gmm_auth_req); |
| 407 | } |
| 408 | [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { repeat; } |
| 409 | [] BSSGP.receive { repeat; } |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | |
| 415 | function f_llc_dec_and_log(in octetstring inp) { |
| 416 | log("LLC Input: ", inp); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 417 | var PDU_LLC dec := dec_PDU_LLC(inp); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 418 | log("LLC Decoded: ", dec); |
| 419 | } |
| 420 | |
| 421 | function f_llc_assert(in octetstring a, in octetstring b) { |
| 422 | log("LLC Input: ", a); |
| 423 | log("LLC Expected: ", b); |
| 424 | |
| 425 | if (a != b) { |
| 426 | setverdict(fail); |
| 427 | } else { |
| 428 | setverdict(pass); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | |
| 433 | testcase TC_selftest_llc() runs on dummy_CT { |
| 434 | const octetstring c_gmm_att_pcu := '01c001080103e5e000210a0005f4fb146ddd32f44000c8001d1b53432b37159ef9090070000dd9c6321200e00019b32c642401c00020170580460b'O; |
| 435 | const octetstring c_gmm_att_pcu_nofcs := '01c001080103e5e000210a0005f4fb146ddd32f44000c8001d1b53432b37159ef9090070000dd9c6321200e00019b32c642401c000201705'O; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 436 | |
| 437 | f_llc_dec_and_log(c_gmm_att_pcu); |
| 438 | |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 439 | //f_llc_assert(f_LLC_append_fcs(c_gmm_att_pcu_nofcs), c_gmm_att_pcu); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 440 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 441 | log(valueof(ts_LLC_UI(gmm_auth_req, c_LLC_SAPI_LLGMM, LLC_CR_DL_CMD, g_mmctx.n_u))); |
| 442 | log(ts_LLC_UI(gmm_auth_req, c_LLC_SAPI_LLGMM, LLC_CR_DL_CMD, g_mmctx.n_u)); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | testcase TC_selftest_rlcmac() runs on dummy_CT { |
| 446 | var RlcmacDlCtrlBlock dcb; |
| 447 | var RlcmacUlCtrlBlock ucb; |
| 448 | const octetstring c_dl_ul_ack_nack := '40240080400000000000000077628dbba14b2b2b2b2b2b'O; |
| 449 | const octetstring c_dl_data := '0f00007341c001081200102198c72477ea104895e8b959acc58b108182f4d0454300'O; |
| 450 | const octetstring c_dl_data2 := '070002165dc0012b2b2b43c0012b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b00'O; |
| 451 | const octetstring c_ul_ctrl_ack := '4006ec51b7772b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b'O; |
| 452 | const octetstring c_ul_dl_ack_nack := '4008004000000000000000701000edc0000b2b2b2b2b2b'O; |
| 453 | const octetstring c_dl_ul_assign := '482857628dbbaf0126e68800082b2b2b2b2b2b2b2b2b2b'O; |
| 454 | |
| 455 | log(c_dl_ul_ack_nack); |
| 456 | dcb := dec_RlcmacDlCtrlBlock(c_dl_ul_ack_nack); |
| 457 | log(dcb); |
| 458 | //log(dec_RlcmacDlCtrlMsg(dcb.payload)); |
| 459 | |
| 460 | f_rlcmac_dld_decenc(c_dl_data); |
| 461 | |
| 462 | f_rlcmac_dld_decenc(c_dl_data2); |
| 463 | |
| 464 | log(c_ul_ctrl_ack); |
| 465 | ucb := dec_RlcmacUlCtrlBlock(c_ul_ctrl_ack); |
| 466 | log(ucb); |
| 467 | //log(dec_RlcmacUlCtrlMsg(ucb.payload)); |
| 468 | |
| 469 | log(c_ul_dl_ack_nack); |
| 470 | ucb := dec_RlcmacUlCtrlBlock(c_ul_dl_ack_nack); |
| 471 | log(ucb); |
| 472 | //log(dec_RlcmacUlCtrlMsg(ucb.payload)); |
| 473 | |
| 474 | log(c_dl_ul_assign); |
| 475 | dcb := dec_RlcmacDlCtrlBlock(c_dl_ul_assign); |
| 476 | log(dcb); |
| 477 | //log(dec_RlcmacDlCtrlMsg(dcb.payload)); |
| 478 | |
| 479 | const octetstring c_uld_tlli_noext := '080101a61cab5201c001080103e5e000310a0005f4e61cab5232f44000c8001d1b00'O; |
| 480 | f_rlcmac_uld_decenc(c_uld_tlli_noext); |
| 481 | |
| 482 | const octetstring c_uld_tlli_ext7pad := '0001041da61cab5200201705a96e102b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b00'O; |
| 483 | log("ULD_decenc"); |
| 484 | f_rlcmac_uld_decenc(c_uld_tlli_ext7pad); |
| 485 | log("UL_decenc"); |
| 486 | f_rlcmac_ul_decenc(c_uld_tlli_ext7pad); |
| 487 | |
| 488 | f_rlcmac_ul_decenc(c_ul_dl_ack_nack); |
| 489 | } |
| 490 | |
| 491 | function f_rlcmac_ul_decenc(in octetstring buf) { |
| 492 | log("=================================="); |
| 493 | log("In: ", buf); |
| 494 | var RlcmacUlBlock udb := dec_RlcmacUlBlock(buf); |
| 495 | log("Dec: ", udb); |
| 496 | var octetstring enc := enc_RlcmacUlBlock(udb); |
| 497 | log("Enc: ", enc); |
| 498 | if (enc != buf) { setverdict(fail, "Re-encoded data doesn't equal input data"); } |
| 499 | } |
| 500 | |
| 501 | function f_rlcmac_uld_decenc(in octetstring buf) { |
| 502 | log("=================================="); |
| 503 | log("In: ", buf); |
| 504 | var RlcmacUlDataBlock udb := dec_RlcmacUlDataBlock(buf); |
| 505 | log("Dec: ", udb); |
| 506 | var octetstring enc := enc_RlcmacUlDataBlock(udb); |
| 507 | log("Enc: ", enc); |
| 508 | if (enc != buf) { setverdict(fail, "Re-encoded data doesn't equal input data"); } |
| 509 | } |
| 510 | |
| 511 | function f_rlcmac_dld_decenc(in octetstring buf) { |
| 512 | log("=================================="); |
| 513 | log("In: ", buf); |
| 514 | var RlcmacDlDataBlock udb := dec_RlcmacDlDataBlock(buf); |
| 515 | log("Dec: ", udb); |
| 516 | var octetstring enc := enc_RlcmacDlDataBlock(udb); |
| 517 | log("Enc: ", enc); |
| 518 | if (enc != buf) { setverdict(fail, "Re-encoded data doesn't equal input data"); } |
| 519 | } |
| 520 | |
| 521 | |
| 522 | testcase TC_selftest_rr() runs on dummy_CT { |
| 523 | //const octetstring c_paging_none := '06210001F02B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O |
| 524 | const octetstring c_paging_none := '1506210001F0'O; |
| 525 | const octetstring c_ia_tbf := '2d063f100fe3677bd8440000c800100b2b2b2b2b2b2b2b'O |
| 526 | log(c_paging_none); |
| 527 | log(dec_GsmRrMessage(c_paging_none)); |
| 528 | |
| 529 | log(c_ia_tbf); |
| 530 | log(dec_GsmRrMessage(c_ia_tbf)); |
| 531 | } |
| 532 | |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 533 | control { |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 534 | execute(TC_selftest_bssgp()); |
| 535 | execute(TC_selftest_ns()); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 536 | execute(TC_selftest_llc()); |
| 537 | execute(TC_selftest_rr()); |
| 538 | execute(TC_selftest_rlcmac()); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 539 | execute(TC_nsem()); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 540 | execute(TC_paging()); |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 541 | } |
| 542 | }; |