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