blob: 7a9ee3e66f04026ae34e123a98c00d4a6af4c7c8 [file] [log] [blame]
Harald Welte52c713c2017-07-16 15:44:44 +02001/* dual-faced port that wraps an Unixdomain port and encodes/decodes L1CTL */
2module L1CTL_PortType {
3 import from L1CTL_Types all;
4 import from UD_PortType all;
5 import from UD_Types all;
Harald Welte9e4725d2017-07-16 23:18:09 +02006 import from Osmocom_Types all;
7 import from GSM_Types all;
Harald Welte9419c8a2017-07-30 04:07:05 +02008 import from GSM_RR_Types all;
Harald Welte52c713c2017-07-16 15:44:44 +02009
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 Welte9e4725d2017-07-16 23:18:09 +020019 function f_L1CTL_FBSB(L1CTL_PT pt, Arfcn arfcn, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
20 timer T := 5.0;
21 pt.send(t_L1CTL_FBSB_REQ(arfcn, t_L1CTL_FBSB_F_ALL, 0, ccch_mode, 0));
22 T.start
23 alt {
24 [] pt.receive(t_L1CTL_FBSB_CONF(0)) {};
25 [] pt.receive { repeat; };
26 [] T.timeout { setverdict(fail, "Timeout in FBSB") };
27 }
28 }
29
30 function f_L1CTL_RACH(L1CTL_PT pt, uint8_t ra, uint8_t combined := 1, uint16_t offset := 0) return GsmFrameNumber {
31 var L1ctlDlMessage rc;
32 var GsmFrameNumber fn;
33 timer T := 2.0;
34 T.start
35 pt.send(t_L1CTL_RACH_REQ(ra, 0, 0))
36 alt {
37 [] pt.receive(t_L1CTL_RACH_CONF) -> value rc { fn := rc.dl_info.frame_nr };
38 [] pt.receive { repeat; };
39 [] T.timeout { setverdict(fail, "Timeout in RACH") };
40 }
41 return fn;
42 }
43
44 function f_L1CTL_WAIT_IMM_ASS(L1CTL_PT pt, uint8_t ra, GsmFrameNumber rach_fn) return ImmediateAssignment {
45 var L1ctlDlMessage dl;
46 var GsmRrMessage rr;
47 timer T := 10.0;
48 T.start;
49 alt {
50 [] pt.receive(t_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
51 rr := dec_GsmRrMessage(dl.payload.data_ind.payload);
52 log("PCH/AGCN DL RR: ", rr);
53 if (match(rr, t_RR_IMM_ASS(ra, rach_fn))) {
54 log("Received IMM.ASS for our RACH!");
55 } else {
56 repeat;
57 }
58 };
59 [] pt.receive { repeat };
60 [] T.timeout { setverdict(fail, "Timeout waiting for IMM ASS") };
61 }
62 T.stop;
63 return rr.payload.imm_ass;
64 }
65
66 /* Send DM_EST_REQ from parameters derived from IMM ASS */
67 function f_L1CTL_DM_EST_REQ_IA(L1CTL_PT pt, ImmediateAssignment imm_ass) {
68 pt.send(t_L1CTL_DM_EST_REQ({ false, imm_ass.chan_desc.arfcn }, imm_ass.chan_desc.chan_nr, imm_ass.chan_desc.tsc));
69 }
70
Harald Welted1209a62017-07-29 12:55:06 +020071 function f_connect_reset(L1CTL_PT pt, charstring l1ctl_sock_path := "/tmp/osmocom_l2") {
72 pt.send(L1CTL_connect:{path:=l1ctl_sock_path});
73 pt.receive(L1CTL_connect_result:{result_code := SUCCESS, err:=omit});
74
75 pt.send(t_L1ctlResetReq(L1CTL_RES_T_SCHED));
76 pt.receive;
77 }
Harald Welte9e4725d2017-07-16 23:18:09 +020078
Harald Welte52c713c2017-07-16 15:44:44 +020079 private function L1CTL_to_UD_connect(in L1CTL_connect pin, out UD_connect pout) {
80 pout.path := pin.path;
81 pout.id := 0;
82 } with { extension "prototype(fast)" }
83
84 private function UD_to_L1CTL_connect_result(in UD_connect_result pin, out L1CTL_connect_result pout) {
85 pout.result_code := pin.result.result_code;
86 pout.err := pin.result.err;
87 } with { extension "prototype(fast)" }
88
89 private function L1CTL_to_UD_ul(in L1ctlUlMessage pin, out UD_send_data pout) {
90 var L1ctlUlMessageLV msg_lv := { msg := pin };
91 pout.data := enc_L1ctlUlMessageLV(msg_lv);
92 pout.id := 0;
93 } with { extension "prototype(fast)" }
94
95 private function UD_to_L1CTL_dl(in UD_send_data pin, out L1ctlDlMessage pout) {
96 var L1ctlDlMessageLV msg_lv := dec_L1ctlDlMessageLV(pin.data);
97 pout:= msg_lv.msg;
98 } with { extension "prototype(fast)" }
99
100 type port L1CTL_PT message {
101 out L1ctlUlMessage
102 out L1CTL_connect
103 in L1ctlDlMessage
104 in L1CTL_connect_result
105 in UD_listen_result
106 in UD_connected
107 } with { extension "user UD_PT
108 out(L1ctlUlMessage -> UD_send_data: function(L1CTL_to_UD_ul);
109 L1CTL_connect -> UD_connect: function(L1CTL_to_UD_connect))
110 in(UD_send_data -> L1ctlDlMessage: function(UD_to_L1CTL_dl);
111 UD_connect_result -> L1CTL_connect_result: function(UD_to_L1CTL_connect_result);
112 UD_listen_result -> UD_listen_result: simple;
113 UD_connected -> UD_connected: simple
114 )" }
115}