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) { |
| 28 | log("getMsgLen(", stream, ",", args, ")=-1"); |
| 29 | return -1; |
| 30 | } |
| 31 | len := 2 + oct2int(substr(stream, 0, 2)); |
| 32 | log("getMsgLen(", stream, ",", args, ")=", len); |
| 33 | return len; |
| 34 | } |
| 35 | |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 36 | function f_L1CTL_FBSB(L1CTL_PT pt, Arfcn arfcn, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) { |
| 37 | timer T := 5.0; |
Harald Welte | 8fe9eba | 2018-03-09 17:03:49 +0100 | [diff] [blame^] | 38 | for (var integer i := 0; i < 10; i := i+1) { |
| 39 | pt.send(t_L1CTL_FBSB_REQ(arfcn, t_L1CTL_FBSB_F_ALL, 0, ccch_mode, 63)); |
| 40 | T.start |
| 41 | alt { |
| 42 | [] pt.receive(t_L1CTL_FBSB_CONF(0)) { return; }; |
| 43 | [] pt.receive(t_L1CTL_FBSB_CONF(?)) { } |
| 44 | [i == 9] pt.receive(t_L1CTL_FBSB_CONF(?)) { |
Harald Welte | 7d7d26c | 2018-02-22 18:52:28 +0100 | [diff] [blame] | 45 | setverdict(fail, "FBSB Failed with non-zero return code"); |
| 46 | }; |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 47 | [] pt.receive { repeat; }; |
| 48 | [] T.timeout { setverdict(fail, "Timeout in FBSB") }; |
Harald Welte | 8fe9eba | 2018-03-09 17:03:49 +0100 | [diff] [blame^] | 49 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | function f_L1CTL_RACH(L1CTL_PT pt, uint8_t ra, uint8_t combined := 1, uint16_t offset := 0) return GsmFrameNumber { |
| 54 | var L1ctlDlMessage rc; |
| 55 | var GsmFrameNumber fn; |
| 56 | timer T := 2.0; |
| 57 | T.start |
| 58 | pt.send(t_L1CTL_RACH_REQ(ra, 0, 0)) |
| 59 | alt { |
| 60 | [] pt.receive(t_L1CTL_RACH_CONF) -> value rc { fn := rc.dl_info.frame_nr }; |
| 61 | [] pt.receive { repeat; }; |
| 62 | [] T.timeout { setverdict(fail, "Timeout in RACH") }; |
| 63 | } |
| 64 | return fn; |
| 65 | } |
| 66 | |
| 67 | function f_L1CTL_WAIT_IMM_ASS(L1CTL_PT pt, uint8_t ra, GsmFrameNumber rach_fn) return ImmediateAssignment { |
| 68 | var L1ctlDlMessage dl; |
| 69 | var GsmRrMessage rr; |
| 70 | timer T := 10.0; |
| 71 | T.start; |
| 72 | alt { |
| 73 | [] pt.receive(t_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl { |
| 74 | rr := dec_GsmRrMessage(dl.payload.data_ind.payload); |
| 75 | log("PCH/AGCN DL RR: ", rr); |
| 76 | if (match(rr, t_RR_IMM_ASS(ra, rach_fn))) { |
| 77 | log("Received IMM.ASS for our RACH!"); |
| 78 | } else { |
| 79 | repeat; |
| 80 | } |
| 81 | }; |
| 82 | [] pt.receive { repeat }; |
| 83 | [] T.timeout { setverdict(fail, "Timeout waiting for IMM ASS") }; |
| 84 | } |
| 85 | T.stop; |
| 86 | return rr.payload.imm_ass; |
| 87 | } |
| 88 | |
Harald Welte | b3c226e | 2017-07-30 17:18:01 +0200 | [diff] [blame] | 89 | function f_L1CTL_TBF_CFG(L1CTL_PT pt, boolean is_uplink, TfiUsfArr tfi_usf) { |
| 90 | timer T := 2.0; |
| 91 | T.start; |
| 92 | pt.send(t_L1CTL_TBF_CFG_REQ(is_uplink, tfi_usf)); |
| 93 | alt { |
| 94 | [] pt.receive(t_L1CTL_TBF_CFG_CONF(is_uplink)) {} |
| 95 | [] pt.receive { repeat }; |
| 96 | [] T.timeout { setverdict(fail, "Timeout waiting for TBF-CFG.conf") }; |
| 97 | } |
| 98 | T.stop; |
| 99 | } |
| 100 | |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 101 | /* Send DM_EST_REQ from parameters derived from IMM ASS */ |
| 102 | function f_L1CTL_DM_EST_REQ_IA(L1CTL_PT pt, ImmediateAssignment imm_ass) { |
| 103 | pt.send(t_L1CTL_DM_EST_REQ({ false, imm_ass.chan_desc.arfcn }, imm_ass.chan_desc.chan_nr, imm_ass.chan_desc.tsc)); |
| 104 | } |
| 105 | |
Harald Welte | f68765d | 2017-08-20 22:54:57 +0200 | [diff] [blame] | 106 | 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] | 107 | var f_UD_getMsgLen vl_f := refers(f_L1CTL_getMsgLen); |
| 108 | f_L1CTL_setGetMsgLen(pt, -1, vl_f, {}); |
Harald Welte | d1209a6 | 2017-07-29 12:55:06 +0200 | [diff] [blame] | 109 | pt.send(L1CTL_connect:{path:=l1ctl_sock_path}); |
| 110 | pt.receive(L1CTL_connect_result:{result_code := SUCCESS, err:=omit}); |
Harald Welte | 6fc784e | 2018-02-25 23:31:37 +0100 | [diff] [blame] | 111 | f_L1CTL_setGetMsgLen(pt, 0, vl_f, {}); |
Harald Welte | d1209a6 | 2017-07-29 12:55:06 +0200 | [diff] [blame] | 112 | |
| 113 | pt.send(t_L1ctlResetReq(L1CTL_RES_T_SCHED)); |
| 114 | pt.receive; |
| 115 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 116 | |
Harald Welte | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 117 | private function L1CTL_to_UD_connect(in L1CTL_connect pin, out UD_connect pout) { |
| 118 | pout.path := pin.path; |
| 119 | pout.id := 0; |
| 120 | } with { extension "prototype(fast)" } |
| 121 | |
| 122 | private function UD_to_L1CTL_connect_result(in UD_connect_result pin, out L1CTL_connect_result pout) { |
| 123 | pout.result_code := pin.result.result_code; |
| 124 | pout.err := pin.result.err; |
| 125 | } with { extension "prototype(fast)" } |
| 126 | |
| 127 | private function L1CTL_to_UD_ul(in L1ctlUlMessage pin, out UD_send_data pout) { |
| 128 | var L1ctlUlMessageLV msg_lv := { msg := pin }; |
| 129 | pout.data := enc_L1ctlUlMessageLV(msg_lv); |
| 130 | pout.id := 0; |
| 131 | } with { extension "prototype(fast)" } |
| 132 | |
| 133 | private function UD_to_L1CTL_dl(in UD_send_data pin, out L1ctlDlMessage pout) { |
| 134 | var L1ctlDlMessageLV msg_lv := dec_L1ctlDlMessageLV(pin.data); |
| 135 | pout:= msg_lv.msg; |
| 136 | } with { extension "prototype(fast)" } |
| 137 | |
| 138 | type port L1CTL_PT message { |
| 139 | out L1ctlUlMessage |
| 140 | out L1CTL_connect |
| 141 | in L1ctlDlMessage |
| 142 | in L1CTL_connect_result |
| 143 | in UD_listen_result |
| 144 | in UD_connected |
| 145 | } with { extension "user UD_PT |
| 146 | out(L1ctlUlMessage -> UD_send_data: function(L1CTL_to_UD_ul); |
| 147 | L1CTL_connect -> UD_connect: function(L1CTL_to_UD_connect)) |
| 148 | in(UD_send_data -> L1ctlDlMessage: function(UD_to_L1CTL_dl); |
| 149 | UD_connect_result -> L1CTL_connect_result: function(UD_to_L1CTL_connect_result); |
| 150 | UD_listen_result -> UD_listen_result: simple; |
| 151 | UD_connected -> UD_connected: simple |
| 152 | )" } |
| 153 | } |