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