Harald Welte | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 1 | /* dual-faced port that wraps an Unixdomain port and encodes/decodes L1CTL */ |
| 2 | module L1CTL_PortType { |
| 3 | import from L1CTL_Types all; |
| 4 | import from UD_PortType all; |
| 5 | import from UD_Types all; |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 6 | import from Osmocom_Types all; |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 7 | import from Osmocom_Types all; |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 8 | import from GSM_Types all; |
Harald Welte | 9419c8a | 2017-07-30 04:07:05 +0200 | [diff] [blame] | 9 | import from GSM_RR_Types all; |
Harald Welte | 6fc784e | 2018-02-25 23:31:37 +0100 | [diff] [blame] | 10 | import from L1CTL_PortType_CtrlFunct all; |
Harald Welte | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 11 | |
| 12 | type record L1CTL_connect { |
| 13 | charstring path |
| 14 | } |
| 15 | |
| 16 | type record L1CTL_connect_result { |
| 17 | UD_Result_code result_code optional, |
| 18 | charstring err optional |
| 19 | } |
| 20 | |
Harald Welte | f68765d | 2017-08-20 22:54:57 +0200 | [diff] [blame] | 21 | modulepar { |
| 22 | charstring m_l1ctl_sock_path := "/tmp/osmocom_l2"; |
| 23 | } |
| 24 | |
Harald Welte | 6fc784e | 2018-02-25 23:31:37 +0100 | [diff] [blame] | 25 | function f_L1CTL_getMsgLen(in octetstring stream, inout ro_integer args) return integer { |
| 26 | var integer stream_len := lengthof(stream); |
| 27 | var integer len; |
| 28 | if (stream_len < 2) { |
Harald Welte | 6fc784e | 2018-02-25 23:31:37 +0100 | [diff] [blame] | 29 | return -1; |
| 30 | } |
| 31 | len := 2 + oct2int(substr(stream, 0, 2)); |
Harald Welte | 6fc784e | 2018-02-25 23:31:37 +0100 | [diff] [blame] | 32 | return len; |
| 33 | } |
| 34 | |
Pau Espin Pedrol | 752ffd5 | 2018-06-07 13:55:45 +0200 | [diff] [blame] | 35 | function f_L1CTL_FBSB(L1CTL_PT pt, Arfcn arfcn, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED, integer rxlev_exp := 57) { |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 36 | timer T := 15.0; |
Harald Welte | 8fe9eba | 2018-03-09 17:03:49 +0100 | [diff] [blame] | 37 | for (var integer i := 0; i < 10; i := i+1) { |
Stefan Sperling | 0258590 | 2018-08-30 17:03:50 +0200 | [diff] [blame] | 38 | var L1ctlDlMessage dl; |
Pau Espin Pedrol | 752ffd5 | 2018-06-07 13:55:45 +0200 | [diff] [blame] | 39 | pt.send(ts_L1CTL_FBSB_REQ(arfcn, valueof(t_L1CTL_FBSB_F_ALL), 0, ccch_mode, rxlev_exp)); |
Harald Welte | 8fe9eba | 2018-03-09 17:03:49 +0100 | [diff] [blame] | 40 | T.start |
| 41 | alt { |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 42 | [] pt.receive(tr_L1CTL_FBSB_CONF(0)) { return; }; |
Stefan Sperling | 0258590 | 2018-08-30 17:03:50 +0200 | [diff] [blame] | 43 | [i >= 9] pt.receive(tr_L1CTL_FBSB_CONF(?)) -> value dl { |
| 44 | setverdict(fail, "FBSB Failed with non-zero return code ", dl.payload.fbsb_conf.result); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 45 | mtc.stop; |
Harald Welte | 7d7d26c | 2018-02-22 18:52:28 +0100 | [diff] [blame] | 46 | }; |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 47 | [] pt.receive(tr_L1CTL_FBSB_CONF(?)) { |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 48 | f_sleep(1.0); |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 49 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 50 | [] pt.receive { repeat; }; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 51 | [] T.timeout { |
| 52 | setverdict(fail, "Timeout in FBSB") |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 53 | mtc.stop; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 54 | }; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | function f_L1CTL_CCCH_MODE(L1CTL_PT pt, L1ctlCcchMode ccch_mode) { |
| 60 | timer T := 2.0; |
| 61 | pt.send(ts_L1CTL_CCCH_MODE_REQ(ccch_mode)); |
| 62 | T.start; |
| 63 | alt { |
| 64 | [] pt.receive(tr_L1CTL_CCCH_MODE_CONF) { } |
| 65 | [] pt.receive { repeat; } |
| 66 | [] T.timeout { |
| 67 | setverdict(fail, "Timeout in CCH_MODE"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 68 | mtc.stop; |
Harald Welte | 8fe9eba | 2018-03-09 17:03:49 +0100 | [diff] [blame] | 69 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | function f_L1CTL_RACH(L1CTL_PT pt, uint8_t ra, uint8_t combined := 1, uint16_t offset := 0) return GsmFrameNumber { |
| 74 | var L1ctlDlMessage rc; |
| 75 | var GsmFrameNumber fn; |
| 76 | timer T := 2.0; |
| 77 | T.start |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 78 | pt.send(ts_L1CTL_RACH_REQ(ra, combined, offset)) |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 79 | alt { |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 80 | [] pt.receive(tr_L1CTL_RACH_CONF) -> value rc { fn := rc.dl_info.frame_nr }; |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 81 | [] pt.receive { repeat; }; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 82 | [] T.timeout { |
| 83 | setverdict(fail, "Timeout in RACH"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 84 | mtc.stop; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 85 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 86 | } |
| 87 | return fn; |
| 88 | } |
| 89 | |
Harald Welte | 3705273 | 2018-03-09 19:38:46 +0100 | [diff] [blame] | 90 | function f_L1CTL_PARAM(L1CTL_PT pt, uint8_t ta, uint8_t tx_power) { |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 91 | pt.send(ts_L1CTL_PAR_REQ(ta, tx_power)); |
Harald Welte | 3705273 | 2018-03-09 19:38:46 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 94 | function f_L1CTL_WAIT_IMM_ASS(L1CTL_PT pt, uint8_t ra, GsmFrameNumber rach_fn) return ImmediateAssignment { |
| 95 | var L1ctlDlMessage dl; |
| 96 | var GsmRrMessage rr; |
| 97 | timer T := 10.0; |
| 98 | T.start; |
| 99 | alt { |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 100 | [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl { |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 101 | rr := dec_GsmRrMessage(dl.payload.data_ind.payload); |
Harald Welte | 0472ab4 | 2018-03-12 15:02:26 +0100 | [diff] [blame] | 102 | log("PCH/AGCH DL RR: ", rr); |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 103 | if (match(rr, t_RR_IMM_ASS(ra, rach_fn))) { |
| 104 | log("Received IMM.ASS for our RACH!"); |
| 105 | } else { |
| 106 | repeat; |
| 107 | } |
| 108 | }; |
| 109 | [] pt.receive { repeat }; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 110 | [] T.timeout { |
| 111 | setverdict(fail, "Timeout waiting for IMM ASS"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 112 | mtc.stop; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 113 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 114 | } |
| 115 | T.stop; |
| 116 | return rr.payload.imm_ass; |
| 117 | } |
| 118 | |
Harald Welte | b669ee0 | 2018-03-09 12:50:02 +0100 | [diff] [blame] | 119 | function f_L1CTL_WAIT_IMM_ASS_TBF_DL(L1CTL_PT pt, GprsTlli tlli) return ImmediateAssignment { |
| 120 | var L1ctlDlMessage dl; |
| 121 | var GsmRrMessage rr; |
| 122 | timer T := 10.0; |
| 123 | T.start; |
| 124 | alt { |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 125 | [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl { |
Harald Welte | b669ee0 | 2018-03-09 12:50:02 +0100 | [diff] [blame] | 126 | rr := dec_GsmRrMessage(dl.payload.data_ind.payload); |
| 127 | log("PCH/AGCN DL RR: ", rr); |
| 128 | if (match(rr, t_RR_IMM_ASS_TBF_DL(tlli))) { |
| 129 | log("Received IMM.ASS for our TLLI!"); |
| 130 | } else { |
| 131 | repeat; |
| 132 | } |
| 133 | }; |
| 134 | [] pt.receive { repeat }; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 135 | [] T.timeout { |
| 136 | setverdict(fail, "Timeout waiting for IMM ASS"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 137 | mtc.stop; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 138 | } |
Harald Welte | b669ee0 | 2018-03-09 12:50:02 +0100 | [diff] [blame] | 139 | } |
| 140 | T.stop; |
| 141 | return rr.payload.imm_ass; |
| 142 | } |
| 143 | |
Harald Welte | b3c226e | 2017-07-30 17:18:01 +0200 | [diff] [blame] | 144 | function f_L1CTL_TBF_CFG(L1CTL_PT pt, boolean is_uplink, TfiUsfArr tfi_usf) { |
| 145 | timer T := 2.0; |
| 146 | T.start; |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 147 | pt.send(ts_L1CTL_TBF_CFG_REQ(is_uplink, tfi_usf)); |
Harald Welte | b3c226e | 2017-07-30 17:18:01 +0200 | [diff] [blame] | 148 | alt { |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 149 | [] pt.receive(tr_L1CTL_TBF_CFG_CONF(is_uplink)) {} |
Harald Welte | b3c226e | 2017-07-30 17:18:01 +0200 | [diff] [blame] | 150 | [] pt.receive { repeat }; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 151 | [] T.timeout { |
| 152 | setverdict(fail, "Timeout waiting for TBF-CFG.conf"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 153 | mtc.stop; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 154 | }; |
Harald Welte | b3c226e | 2017-07-30 17:18:01 +0200 | [diff] [blame] | 155 | } |
| 156 | T.stop; |
| 157 | } |
| 158 | |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 159 | /* Send DM_EST_REQ from parameters derived from IMM ASS */ |
| 160 | function f_L1CTL_DM_EST_REQ_IA(L1CTL_PT pt, ImmediateAssignment imm_ass) { |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 161 | pt.send(ts_L1CTL_DM_EST_REQ({ false, imm_ass.chan_desc.arfcn }, imm_ass.chan_desc.chan_nr, imm_ass.chan_desc.tsc)); |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Harald Welte | 3dc2046 | 2018-03-10 23:03:38 +0100 | [diff] [blame] | 164 | /* Send DM_REL_REQ from parameters derived from IMM ASS */ |
| 165 | function f_L1CTL_DM_REL_REQ(L1CTL_PT pt, RslChannelNr chan_nr) { |
| 166 | pt.send(ts_L1CTL_DM_REL_REQ(chan_nr)); |
| 167 | } |
| 168 | |
Harald Welte | aca6e07 | 2018-03-10 17:15:38 +0100 | [diff] [blame] | 169 | function f_L1CTL_RESET(L1CTL_PT pt, L1ctlResetType res_type := L1CTL_RES_T_FULL) { |
| 170 | timer T := 2.0; |
| 171 | pt.send(t_L1ctlResetReq(res_type)); |
| 172 | T.start; |
| 173 | alt { |
| 174 | [] pt.receive(tr_L1CTL_MsgType(L1CTL_RESET_CONF)) { } |
| 175 | [] pt.receive { repeat; } |
| 176 | [] T.timeout { |
| 177 | setverdict(fail, "Timeout waiting for RESET.conf"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 178 | mtc.stop; |
Harald Welte | aca6e07 | 2018-03-10 17:15:38 +0100 | [diff] [blame] | 179 | } |
| 180 | } |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 181 | } |
Harald Welte | aca6e07 | 2018-03-10 17:15:38 +0100 | [diff] [blame] | 182 | |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 183 | function f_L1CTL_CRYPTO_REQ(L1CTL_PT pt, RslChannelNr chan_nr, uint8_t algo, octetstring key) { |
| 184 | pt.send(ts_L1CTL_CRYPTO_REQ(chan_nr, algo, key)); |
Harald Welte | aca6e07 | 2018-03-10 17:15:38 +0100 | [diff] [blame] | 185 | } |
| 186 | |
Harald Welte | f68765d | 2017-08-20 22:54:57 +0200 | [diff] [blame] | 187 | function f_connect_reset(L1CTL_PT pt, charstring l1ctl_sock_path := m_l1ctl_sock_path) { |
Harald Welte | 6fc784e | 2018-02-25 23:31:37 +0100 | [diff] [blame] | 188 | var f_UD_getMsgLen vl_f := refers(f_L1CTL_getMsgLen); |
| 189 | f_L1CTL_setGetMsgLen(pt, -1, vl_f, {}); |
Harald Welte | d1209a6 | 2017-07-29 12:55:06 +0200 | [diff] [blame] | 190 | pt.send(L1CTL_connect:{path:=l1ctl_sock_path}); |
| 191 | pt.receive(L1CTL_connect_result:{result_code := SUCCESS, err:=omit}); |
Harald Welte | 6fc784e | 2018-02-25 23:31:37 +0100 | [diff] [blame] | 192 | f_L1CTL_setGetMsgLen(pt, 0, vl_f, {}); |
Harald Welte | aca6e07 | 2018-03-10 17:15:38 +0100 | [diff] [blame] | 193 | f_L1CTL_RESET(pt); |
Harald Welte | d1209a6 | 2017-07-29 12:55:06 +0200 | [diff] [blame] | 194 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 195 | |
Harald Welte | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 196 | private function L1CTL_to_UD_connect(in L1CTL_connect pin, out UD_connect pout) { |
| 197 | pout.path := pin.path; |
| 198 | pout.id := 0; |
| 199 | } with { extension "prototype(fast)" } |
| 200 | |
| 201 | private function UD_to_L1CTL_connect_result(in UD_connect_result pin, out L1CTL_connect_result pout) { |
| 202 | pout.result_code := pin.result.result_code; |
| 203 | pout.err := pin.result.err; |
| 204 | } with { extension "prototype(fast)" } |
| 205 | |
| 206 | private function L1CTL_to_UD_ul(in L1ctlUlMessage pin, out UD_send_data pout) { |
| 207 | var L1ctlUlMessageLV msg_lv := { msg := pin }; |
| 208 | pout.data := enc_L1ctlUlMessageLV(msg_lv); |
| 209 | pout.id := 0; |
| 210 | } with { extension "prototype(fast)" } |
| 211 | |
| 212 | private function UD_to_L1CTL_dl(in UD_send_data pin, out L1ctlDlMessage pout) { |
| 213 | var L1ctlDlMessageLV msg_lv := dec_L1ctlDlMessageLV(pin.data); |
| 214 | pout:= msg_lv.msg; |
| 215 | } with { extension "prototype(fast)" } |
| 216 | |
| 217 | type port L1CTL_PT message { |
| 218 | out L1ctlUlMessage |
| 219 | out L1CTL_connect |
| 220 | in L1ctlDlMessage |
| 221 | in L1CTL_connect_result |
| 222 | in UD_listen_result |
| 223 | in UD_connected |
| 224 | } with { extension "user UD_PT |
| 225 | out(L1ctlUlMessage -> UD_send_data: function(L1CTL_to_UD_ul); |
| 226 | L1CTL_connect -> UD_connect: function(L1CTL_to_UD_connect)) |
| 227 | in(UD_send_data -> L1ctlDlMessage: function(UD_to_L1CTL_dl); |
| 228 | UD_connect_result -> L1CTL_connect_result: function(UD_to_L1CTL_connect_result); |
| 229 | UD_listen_result -> UD_listen_result: simple; |
| 230 | UD_connected -> UD_connected: simple |
| 231 | )" } |
| 232 | } |