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