Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 1 | module L1CTL_Test { |
| 2 | import from GSM_Types all; |
| 3 | import from Osmocom_Types all; |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 4 | import from LAPDm_RAW_PT all; |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 5 | import from LAPDm_Types all; |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 6 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 7 | type component dummy_CT { |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 8 | port LAPDm_PT LAPDM; |
| 9 | var lapdm_CT lapdm_component; |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 10 | }; |
| 11 | |
Harald Welte | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 12 | function f_init() runs on dummy_CT { |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 13 | /* create the LAPDm component */ |
| 14 | lapdm_component := lapdm_CT.create; |
| 15 | /* connect our own LAPDM port to the LAPDM Service Provider of the LAPDm component */ |
| 16 | connect(self:LAPDM, lapdm_component:LAPDM_SP); |
| 17 | /* connect the LAPDm compoent's lower-side port to the system L1CTL port (which is internally |
| 18 | * connected to the Unix Domain Socket test port */ |
| 19 | map(lapdm_component:L1CTL, system:L1CTL); |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 20 | |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 21 | /* start the LAPDm parallel component calling it's local function LAPDmStart */ |
| 22 | lapdm_component.start(LAPDmStart()); |
Harald Welte | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 23 | } |
| 24 | |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 25 | /* master function establishing a dedicated radio channel (takes care of RACH/IMM.ASS handling) */ |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 26 | function f_establish_dcch() runs on dummy_CT { |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 27 | var BCCH_tune_req tune_req := { arfcn := { false, 871 }, combined_ccch := true }; |
| 28 | var DCCH_establish_req est_req := { ra := 23 }; |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 29 | |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 30 | LAPDM.send(tune_req); |
| 31 | LAPDM.send(est_req); |
| 32 | LAPDM.receive(DCCH_establish_res:?); |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 33 | } |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 34 | |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 35 | /* helper function releasing dedicated radio channel physically (no Um signaling!) */ |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 36 | function f_release_dcch() runs on dummy_CT { |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 37 | var DCCH_release_req rel_req := {}; |
| 38 | LAPDM.send(rel_req); |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 39 | } |
| 40 | |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 41 | template LAPDm_ph_data t_PH_DATA(template GsmSapi sapi, template boolean sacch, template LapdmFrame frame) := { |
| 42 | sacch := sacch, |
| 43 | sapi := sapi, |
| 44 | lapdm := frame |
| 45 | } |
| 46 | /* template for a valid SABM frame */ |
| 47 | template LapdmFrame LAPDm_B_SABM(template GsmSapi sapi, template octetstring payload) := { |
| 48 | b := { |
| 49 | addr := tr_LapdmAddr(sapi, false), |
| 50 | ctrl := t_LapdmCtrlSABM(true), |
| 51 | len := lengthof(payload), |
| 52 | m := false, |
| 53 | el := 1, |
| 54 | payload := payload |
| 55 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 56 | } |
| 57 | |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 58 | /* template for a valid UA frame */ |
| 59 | template LapdmFrame LAPDm_B_UA(template GsmSapi sapi, template octetstring payload) := { |
| 60 | b := { |
| 61 | addr := tr_LapdmAddr(sapi, false), |
| 62 | ctrl := t_LapdmCtrlUA(true), |
| 63 | len := lengthof(payload), |
| 64 | m := false, |
| 65 | el := 1, |
| 66 | payload := payload |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /* template for a valid UI frame */ |
| 71 | template LapdmFrame LAPDm_B_UI(template GsmSapi sapi, template octetstring payload) := { |
| 72 | b := { |
| 73 | addr := tr_LapdmAddr(sapi, true), |
| 74 | ctrl := t_LapdmCtrlUI(false), |
| 75 | len := lengthof(payload), |
| 76 | m := false, |
| 77 | el := 1, |
| 78 | payload := payload |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | function f_test_sabm_results_in_ua(uint8_t sapi, boolean use_sacch, octetstring payload) runs on dummy_CT return boolean { |
| 83 | var LAPDm_ph_data phd; |
| 84 | var boolean result := false; |
| 85 | timer T := 5.0; |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 86 | |
| 87 | f_establish_dcch(); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 88 | LAPDM.send(t_PH_DATA(sapi, use_sacch, LAPDm_B_SABM(sapi, payload))); |
| 89 | log("====> expecting ", t_PH_DATA(sapi, use_sacch, LAPDm_B_UA(sapi, payload))); |
| 90 | T.start |
| 91 | alt { |
Harald Welte | dca7e45 | 2017-07-17 21:43:58 +0200 | [diff] [blame^] | 92 | [] LAPDM.receive(t_PH_DATA(?, use_sacch, LAPDm_B_UA(sapi, payload))) { result := true; } |
| 93 | [] LAPDM.receive(t_PH_DATA(?, use_sacch, ?)) -> value phd { log("Other msg on DCH: ", phd); repeat; } |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 94 | [] LAPDM.receive(t_PH_DATA(?, ?, ?)) -> value phd { log("Other PH-DATA: ", phd); repeat; } |
Harald Welte | dca7e45 | 2017-07-17 21:43:58 +0200 | [diff] [blame^] | 95 | [] T.timeout { } |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 96 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 97 | f_release_dcch(); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 98 | return result; |
| 99 | } |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 100 | |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 101 | testcase TC_sabm_ua_dcch_sapi0() runs on dummy_CT { |
| 102 | f_init(); |
| 103 | if (not f_test_sabm_results_in_ua(0, false, 'FEFE'O)) { |
| 104 | setverdict(fail); |
| 105 | } |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 106 | setverdict(pass); |
| 107 | } |
| 108 | |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 109 | testcase TC_sabm_ua_dcch_sapi0_nopayload() runs on dummy_CT { |
| 110 | f_init(); |
Harald Welte | dca7e45 | 2017-07-17 21:43:58 +0200 | [diff] [blame^] | 111 | if (f_test_sabm_results_in_ua(0, false, ''O)) { |
| 112 | setverdict(fail, "Initial SABM/UA must contain L3 payload but BTS accepts without"); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 113 | } |
| 114 | setverdict(pass); |
| 115 | } |
| 116 | |
| 117 | testcase TC_sabm_ua_dcch_sapi3() runs on dummy_CT { |
| 118 | f_init(); |
Harald Welte | dca7e45 | 2017-07-17 21:43:58 +0200 | [diff] [blame^] | 119 | if (f_test_sabm_results_in_ua(3, false, 'FEFE'O)) { |
| 120 | setverdict(fail, "Initial SABM/UA must be on SAPI0, but BTS accepts SAPI=3"); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 121 | } |
| 122 | setverdict(pass); |
| 123 | } |
| 124 | |
| 125 | testcase TC_sabm_ua_dcch_sapi4() runs on dummy_CT { |
| 126 | f_init(); |
Harald Welte | dca7e45 | 2017-07-17 21:43:58 +0200 | [diff] [blame^] | 127 | if (f_test_sabm_results_in_ua(4, false, 'FEFE'O)) { |
| 128 | setverdict(fail, "Initial SABM/UA must be on SAPI0, but BTS accepts SAPI=4"); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 129 | } |
| 130 | setverdict(pass); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | testcase TC_foo() runs on dummy_CT { |
| 135 | /* |
| 136 | var LapdmFrame lf := valueof(LAPDm_B_UA(0, ''O)); |
| 137 | log("ENC UA: ", enc_LapdmFrame(lf)); |
| 138 | lf := valueof(LAPDm_B_UI(0, ''O)); |
| 139 | log("ENC UI B: ", enc_LapdmFrame(lf)); |
| 140 | log("ENC UI B: ", enc_LapdmFrameB(lf.b)); |
| 141 | |
| 142 | log("DEC UI AF: ", dec_LapdmAddressField('03'O)); |
| 143 | */ |
| 144 | log("DEC UI CU: ", dec_LapdmCtrlU('03'O)); |
| 145 | log("DEC UI CT: ", dec_LapdmCtrl('03'O)); |
| 146 | |
| 147 | log("DEC UA: ", dec_LapdmFrameB('017301'O)); |
| 148 | log("DEC UI: ", dec_LapdmFrameA('030301'O)); |
| 149 | log("DEC I: ", dec_LapdmFrameA('030001'O)); |
| 150 | log("DEC S: ", dec_LapdmFrameA('030101'O)); |
| 151 | log("DEC: ", dec_LapdmFrameB('030301'O)); |
| 152 | log("DEC: ", dec_LapdmFrameB('0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O)); |
| 153 | } |
| 154 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 155 | control { |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 156 | execute(TC_foo()); |
| 157 | execute(TC_sabm_ua_dcch_sapi0()); |
| 158 | /* |
| 159 | execute(TC_sabm_ua_dcch_sapi0_nopayload()); |
| 160 | execute(TC_sabm_ua_dcch_sapi3()); |
| 161 | execute(TC_sabm_ua_dcch_sapi4()); |
| 162 | */ |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 163 | } |
| 164 | } |