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 | |
Vadim Yanitskiy | 51cbc10 | 2019-04-22 06:37:30 +0700 | [diff] [blame] | 90 | function f_L1CTL_EXT_RACH( |
| 91 | L1CTL_PT pt, uint16_t ra11, L1ctlRachSynchSeq seq, |
| 92 | uint8_t combined := 1, uint16_t offset := 0 |
| 93 | ) return GsmFrameNumber { |
| 94 | var L1ctlDlMessage rc; |
| 95 | var GsmFrameNumber fn; |
| 96 | timer T := 2.0; |
| 97 | |
| 98 | T.start; |
| 99 | pt.send(ts_L1CTL_EXT_RACH_REQ(ra11, seq, combined, offset)); |
| 100 | alt { |
| 101 | [] pt.receive(tr_L1CTL_RACH_CONF) -> value rc { fn := rc.dl_info.frame_nr }; |
| 102 | [] pt.receive { repeat; }; |
| 103 | [] T.timeout { |
| 104 | setverdict(fail, "Timeout in extended RACH"); |
| 105 | mtc.stop; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return fn; |
| 110 | } |
| 111 | |
Harald Welte | 3705273 | 2018-03-09 19:38:46 +0100 | [diff] [blame] | 112 | 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] | 113 | pt.send(ts_L1CTL_PAR_REQ(ta, tx_power)); |
Harald Welte | 3705273 | 2018-03-09 19:38:46 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 116 | function f_L1CTL_WAIT_IMM_ASS(L1CTL_PT pt, uint8_t ra, GsmFrameNumber rach_fn) return ImmediateAssignment { |
| 117 | var L1ctlDlMessage dl; |
| 118 | var GsmRrMessage rr; |
| 119 | timer T := 10.0; |
| 120 | T.start; |
| 121 | alt { |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 122 | [] 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] | 123 | rr := dec_GsmRrMessage(dl.payload.data_ind.payload); |
Harald Welte | 0472ab4 | 2018-03-12 15:02:26 +0100 | [diff] [blame] | 124 | log("PCH/AGCH DL RR: ", rr); |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 125 | if (match(rr, t_RR_IMM_ASS(ra, rach_fn))) { |
| 126 | log("Received IMM.ASS for our RACH!"); |
| 127 | } else { |
| 128 | repeat; |
| 129 | } |
| 130 | }; |
| 131 | [] pt.receive { repeat }; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 132 | [] T.timeout { |
| 133 | setverdict(fail, "Timeout waiting for IMM ASS"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 134 | mtc.stop; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 135 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 136 | } |
| 137 | T.stop; |
| 138 | return rr.payload.imm_ass; |
| 139 | } |
| 140 | |
Harald Welte | b669ee0 | 2018-03-09 12:50:02 +0100 | [diff] [blame] | 141 | function f_L1CTL_WAIT_IMM_ASS_TBF_DL(L1CTL_PT pt, GprsTlli tlli) return ImmediateAssignment { |
| 142 | var L1ctlDlMessage dl; |
| 143 | var GsmRrMessage rr; |
| 144 | timer T := 10.0; |
| 145 | T.start; |
| 146 | alt { |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 147 | [] 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] | 148 | rr := dec_GsmRrMessage(dl.payload.data_ind.payload); |
| 149 | log("PCH/AGCN DL RR: ", rr); |
| 150 | if (match(rr, t_RR_IMM_ASS_TBF_DL(tlli))) { |
| 151 | log("Received IMM.ASS for our TLLI!"); |
| 152 | } else { |
| 153 | repeat; |
| 154 | } |
| 155 | }; |
| 156 | [] pt.receive { repeat }; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 157 | [] T.timeout { |
| 158 | setverdict(fail, "Timeout waiting for IMM ASS"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 159 | mtc.stop; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 160 | } |
Harald Welte | b669ee0 | 2018-03-09 12:50:02 +0100 | [diff] [blame] | 161 | } |
| 162 | T.stop; |
| 163 | return rr.payload.imm_ass; |
| 164 | } |
| 165 | |
Harald Welte | b3c226e | 2017-07-30 17:18:01 +0200 | [diff] [blame] | 166 | function f_L1CTL_TBF_CFG(L1CTL_PT pt, boolean is_uplink, TfiUsfArr tfi_usf) { |
| 167 | timer T := 2.0; |
| 168 | T.start; |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 169 | pt.send(ts_L1CTL_TBF_CFG_REQ(is_uplink, tfi_usf)); |
Harald Welte | b3c226e | 2017-07-30 17:18:01 +0200 | [diff] [blame] | 170 | alt { |
Harald Welte | f8df4cb | 2018-03-10 15:15:08 +0100 | [diff] [blame] | 171 | [] pt.receive(tr_L1CTL_TBF_CFG_CONF(is_uplink)) {} |
Harald Welte | b3c226e | 2017-07-30 17:18:01 +0200 | [diff] [blame] | 172 | [] pt.receive { repeat }; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 173 | [] T.timeout { |
| 174 | setverdict(fail, "Timeout waiting for TBF-CFG.conf"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 175 | mtc.stop; |
Harald Welte | 3757e60 | 2018-03-10 17:12:02 +0100 | [diff] [blame] | 176 | }; |
Harald Welte | b3c226e | 2017-07-30 17:18:01 +0200 | [diff] [blame] | 177 | } |
| 178 | T.stop; |
| 179 | } |
Harald Welte | b05fd2d | 2019-05-19 22:25:38 +0200 | [diff] [blame^] | 180 | function f_L1CTL_DM_EST_REQ(L1CTL_PT pt, Arfcn arfcn, RslChannelNr chan_nr, GsmTsc tsc) { |
| 181 | pt.send(ts_L1CTL_DM_EST_REQ(arfcn, chan_nr, tsc)); |
| 182 | } |
Harald Welte | b3c226e | 2017-07-30 17:18:01 +0200 | [diff] [blame] | 183 | |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 184 | /* Send DM_EST_REQ from parameters derived from IMM ASS */ |
| 185 | function f_L1CTL_DM_EST_REQ_IA(L1CTL_PT pt, ImmediateAssignment imm_ass) { |
Harald Welte | b05fd2d | 2019-05-19 22:25:38 +0200 | [diff] [blame^] | 186 | f_L1CTL_DM_EST_REQ(pt, { false, imm_ass.chan_desc.arfcn }, imm_ass.chan_desc.chan_nr, |
| 187 | imm_ass.chan_desc.tsc); |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Harald Welte | 3dc2046 | 2018-03-10 23:03:38 +0100 | [diff] [blame] | 190 | /* Send DM_REL_REQ from parameters derived from IMM ASS */ |
| 191 | function f_L1CTL_DM_REL_REQ(L1CTL_PT pt, RslChannelNr chan_nr) { |
| 192 | pt.send(ts_L1CTL_DM_REL_REQ(chan_nr)); |
| 193 | } |
| 194 | |
Harald Welte | aca6e07 | 2018-03-10 17:15:38 +0100 | [diff] [blame] | 195 | function f_L1CTL_RESET(L1CTL_PT pt, L1ctlResetType res_type := L1CTL_RES_T_FULL) { |
| 196 | timer T := 2.0; |
| 197 | pt.send(t_L1ctlResetReq(res_type)); |
| 198 | T.start; |
| 199 | alt { |
| 200 | [] pt.receive(tr_L1CTL_MsgType(L1CTL_RESET_CONF)) { } |
| 201 | [] pt.receive { repeat; } |
| 202 | [] T.timeout { |
| 203 | setverdict(fail, "Timeout waiting for RESET.conf"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 204 | mtc.stop; |
Harald Welte | aca6e07 | 2018-03-10 17:15:38 +0100 | [diff] [blame] | 205 | } |
| 206 | } |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 207 | } |
Harald Welte | aca6e07 | 2018-03-10 17:15:38 +0100 | [diff] [blame] | 208 | |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 209 | function f_L1CTL_CRYPTO_REQ(L1CTL_PT pt, RslChannelNr chan_nr, uint8_t algo, octetstring key) { |
| 210 | pt.send(ts_L1CTL_CRYPTO_REQ(chan_nr, algo, key)); |
Harald Welte | aca6e07 | 2018-03-10 17:15:38 +0100 | [diff] [blame] | 211 | } |
| 212 | |
Harald Welte | f68765d | 2017-08-20 22:54:57 +0200 | [diff] [blame] | 213 | 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] | 214 | var f_UD_getMsgLen vl_f := refers(f_L1CTL_getMsgLen); |
| 215 | f_L1CTL_setGetMsgLen(pt, -1, vl_f, {}); |
Harald Welte | d1209a6 | 2017-07-29 12:55:06 +0200 | [diff] [blame] | 216 | pt.send(L1CTL_connect:{path:=l1ctl_sock_path}); |
| 217 | pt.receive(L1CTL_connect_result:{result_code := SUCCESS, err:=omit}); |
Harald Welte | 6fc784e | 2018-02-25 23:31:37 +0100 | [diff] [blame] | 218 | f_L1CTL_setGetMsgLen(pt, 0, vl_f, {}); |
Harald Welte | aca6e07 | 2018-03-10 17:15:38 +0100 | [diff] [blame] | 219 | f_L1CTL_RESET(pt); |
Harald Welte | d1209a6 | 2017-07-29 12:55:06 +0200 | [diff] [blame] | 220 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 221 | |
Harald Welte | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 222 | private function L1CTL_to_UD_connect(in L1CTL_connect pin, out UD_connect pout) { |
| 223 | pout.path := pin.path; |
| 224 | pout.id := 0; |
| 225 | } with { extension "prototype(fast)" } |
| 226 | |
| 227 | private function UD_to_L1CTL_connect_result(in UD_connect_result pin, out L1CTL_connect_result pout) { |
| 228 | pout.result_code := pin.result.result_code; |
| 229 | pout.err := pin.result.err; |
| 230 | } with { extension "prototype(fast)" } |
| 231 | |
| 232 | private function L1CTL_to_UD_ul(in L1ctlUlMessage pin, out UD_send_data pout) { |
| 233 | var L1ctlUlMessageLV msg_lv := { msg := pin }; |
| 234 | pout.data := enc_L1ctlUlMessageLV(msg_lv); |
| 235 | pout.id := 0; |
| 236 | } with { extension "prototype(fast)" } |
| 237 | |
| 238 | private function UD_to_L1CTL_dl(in UD_send_data pin, out L1ctlDlMessage pout) { |
| 239 | var L1ctlDlMessageLV msg_lv := dec_L1ctlDlMessageLV(pin.data); |
| 240 | pout:= msg_lv.msg; |
| 241 | } with { extension "prototype(fast)" } |
| 242 | |
| 243 | type port L1CTL_PT message { |
| 244 | out L1ctlUlMessage |
| 245 | out L1CTL_connect |
| 246 | in L1ctlDlMessage |
| 247 | in L1CTL_connect_result |
| 248 | in UD_listen_result |
| 249 | in UD_connected |
| 250 | } with { extension "user UD_PT |
| 251 | out(L1ctlUlMessage -> UD_send_data: function(L1CTL_to_UD_ul); |
| 252 | L1CTL_connect -> UD_connect: function(L1CTL_to_UD_connect)) |
| 253 | in(UD_send_data -> L1ctlDlMessage: function(UD_to_L1CTL_dl); |
| 254 | UD_connect_result -> L1CTL_connect_result: function(UD_to_L1CTL_connect_result); |
| 255 | UD_listen_result -> UD_listen_result: simple; |
| 256 | UD_connected -> UD_connected: simple |
| 257 | )" } |
| 258 | } |