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