Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 1 | /* LLC Templates in TTCN-3 |
| 2 | * (C) 2018-2019 Harald Welte <laforge@gnumonks.org> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Released under the terms of GNU General Public License, Version 2 or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 9 | */ |
| 10 | |
| 11 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 12 | module LLC_Templates { |
| 13 | |
| 14 | import from LLC_Types all; |
| 15 | import from Osmocom_Types all; |
| 16 | import from General_Types all; |
| 17 | |
| 18 | template Address_field t_LLC_Addr(template BIT4 sapi, template BIT1 cr, template BIT1 pd := '0'B) := { |
| 19 | sAPI := sapi, |
| 20 | spare := '00'B, |
| 21 | cR := cr, |
| 22 | pD := '0'B |
| 23 | } |
Harald Welte | f7a5c3c | 2019-04-23 22:00:00 +0200 | [diff] [blame] | 24 | template (value) Address_field ts_LLC_Addr(template (value) BIT4 sapi, |
| 25 | template (value) BIT1 cr, |
| 26 | template (value) BIT1 pd := '0'B) := { |
| 27 | sAPI := sapi, |
| 28 | spare := '00'B, |
| 29 | cR := cr, |
| 30 | pD := '0'B |
| 31 | } |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 32 | |
| 33 | template (value) Control_field_UI ts_LLC_CtrlUI(uint9_t n_u, boolean encrypted := false, |
| 34 | boolean protected := false) := { |
| 35 | format := '110'B, |
| 36 | spare := '00'B, |
| 37 | nU := n_u, |
| 38 | e := bool2bit(encrypted), |
| 39 | pM := bool2bit(protected) |
| 40 | } |
| 41 | |
Harald Welte | f7a5c3c | 2019-04-23 22:00:00 +0200 | [diff] [blame] | 42 | template (value) Control_field_U ts_LLC_CtrlU(template (value) BIT4 m_bits, template (value) BIT1 p_f) := { |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 43 | mBits := m_bits, |
| 44 | pF := p_f, |
| 45 | format := '111'B |
| 46 | } |
| 47 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 48 | template Control_field_UI tr_LLC_CtrlUI(template uint9_t n_u, |
| 49 | template boolean encrypted := ?, |
| 50 | template boolean protected := ?) := { |
| 51 | format := '110'B, |
| 52 | spare := '00'B, |
| 53 | nU := n_u, |
| 54 | e := bool2bit_tmpl(encrypted), |
| 55 | pM := bool2bit_tmpl(protected) |
| 56 | } |
| 57 | |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 58 | template Control_field_U tr_LLC_CtrlU(template BIT4 m_bits := ?, |
| 59 | template BIT1 p_f := ?) := { |
| 60 | mBits := m_bits, |
| 61 | pF := p_f, |
| 62 | format := '111'B |
| 63 | } |
| 64 | |
| 65 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 66 | template PDU_LLC ts_LLC_UI(octetstring payload, BIT4 sapi, BIT1 cr, uint9_t n_u, |
| 67 | boolean encrypted := false, boolean protected := false) := { |
| 68 | pDU_LLC_UI := { |
Harald Welte | f7a5c3c | 2019-04-23 22:00:00 +0200 | [diff] [blame] | 69 | address_field := ts_LLC_Addr(sapi, cr), |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 70 | control_field := ts_LLC_CtrlUI(n_u, encrypted, protected), |
| 71 | information_field_UI := payload, |
| 72 | fCS := omit /* causes encoder to generate FCS */ |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | template PDU_LLC tr_LLC_UI(template octetstring payload := ?, template BIT4 sapi := ?, |
| 77 | template BIT1 cr := ?, template uint9_t n_u := ?, |
| 78 | template boolean encrypted := ?, template boolean protected := ?) := { |
| 79 | pDU_LLC_UI := { |
| 80 | address_field := t_LLC_Addr(sapi, cr), |
| 81 | control_field := tr_LLC_CtrlUI(n_u, encrypted, protected), |
| 82 | information_field_UI := payload, |
| 83 | fCS := '000000'O /* provided by decoder if FCS OK */ |
| 84 | } |
| 85 | } |
| 86 | |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 87 | template PDU_LLC tr_LLC_XID(template XID_Information xid, template BIT4 sapi := ?, |
| 88 | template BIT1 cr := ?, template BIT1 p_f := ?) := { |
| 89 | pDU_LLC_U := { |
| 90 | address_field := t_LLC_Addr(sapi, cr), |
| 91 | control_field := tr_LLC_CtrlU('1011'B, p_f), |
| 92 | information_field_U := { |
| 93 | xID := xid |
| 94 | }, |
| 95 | fCS := '000000'O /* provided by decoder if FCS OK */ |
| 96 | } |
| 97 | } |
Harald Welte | d21f6a2 | 2019-05-02 09:50:34 +0200 | [diff] [blame] | 98 | template PDU_LLC tr_LLC_XID_MO_CMD(template XID_Information xid, template BIT4 sapi) := |
| 99 | tr_LLC_XID(xid, sapi, LLC_CR_UL_CMD, '1'B); |
| 100 | template PDU_LLC tr_LLC_XID_MO_RSP(template XID_Information xid, template BIT4 sapi) := |
| 101 | tr_LLC_XID(xid, sapi, LLC_CR_UL_RSP, '1'B); |
| 102 | template PDU_LLC tr_LLC_XID_MT_CMD(template XID_Information xid, template BIT4 sapi) := |
| 103 | tr_LLC_XID(xid, sapi, LLC_CR_DL_CMD, '1'B); |
| 104 | template PDU_LLC tr_LLC_XID_MT_RSP(template XID_Information xid, template BIT4 sapi) := |
| 105 | tr_LLC_XID(xid, sapi, LLC_CR_DL_RSP, '1'B); |
| 106 | template (value) PDU_LLC ts_LLC_XID(template (value) XID_Information xid, |
| 107 | template (value) BIT4 sapi, |
| 108 | template (value) BIT1 cr, |
| 109 | template (value) BIT1 p_f) := { |
| 110 | pDU_LLC_U := { |
| 111 | address_field := ts_LLC_Addr(sapi, cr), |
| 112 | control_field := ts_LLC_CtrlU('1011'B, p_f), |
| 113 | information_field_U := { |
| 114 | xID := xid |
| 115 | }, |
| 116 | fCS := omit /* causes encoder to generate FCS */ |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | template (value) PDU_LLC ts_LLC_XID_MO_CMD(template (value) XID_Information xid, template (value) BIT4 sapi) := |
| 121 | ts_LLC_XID(xid, sapi, LLC_CR_UL_CMD, '1'B); |
| 122 | template (value) PDU_LLC ts_LLC_XID_MO_RSP(template (value) XID_Information xid, template (value) BIT4 sapi) := |
| 123 | ts_LLC_XID(xid, sapi, LLC_CR_UL_RSP, '1'B); |
| 124 | template (value) PDU_LLC ts_LLC_XID_MT_CMD(template (value) XID_Information xid, template (value) BIT4 sapi) := |
| 125 | ts_LLC_XID(xid, sapi, LLC_CR_DL_CMD, '1'B); |
| 126 | template (value) PDU_LLC ts_LLC_XID_MT_RSP(template (value) XID_Information xid, template (value) BIT4 sapi) := |
| 127 | ts_LLC_XID(xid, sapi, LLC_CR_DL_RSP, '1'B); |
| 128 | |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 129 | |
Harald Welte | f7a5c3c | 2019-04-23 22:00:00 +0200 | [diff] [blame] | 130 | template PDU_LLC tr_LLC_U(template BIT4 m_bits, template BIT1 p_f, template Information_field_U u, |
| 131 | template BIT4 sapi, template BIT1 cr) := { |
| 132 | pDU_LLC_U := { |
| 133 | address_field := t_LLC_Addr(sapi, cr), |
| 134 | control_field := tr_LLC_CtrlU(m_bits, p_f), |
| 135 | information_field_U := u, |
| 136 | fCS := '000000'O /* provided by decoder if FCS OK */ |
| 137 | } |
| 138 | } |
| 139 | template (value) PDU_LLC ts_LLC_U(template (value) BIT4 m_bits, template (value) BIT1 p_f, |
| 140 | template (value) Information_field_U u, |
| 141 | template (value) BIT4 sapi, template (value) BIT1 cr) := { |
| 142 | pDU_LLC_U := { |
| 143 | address_field := ts_LLC_Addr(sapi, cr), |
| 144 | control_field := ts_LLC_CtrlU(m_bits, p_f), |
| 145 | information_field_U := u, |
| 146 | fCS := omit /* causes encoder to generate FCS */ |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | template PDU_LLC tr_LLC_SABM(template SABM_Information sabm_xid, template BIT1 p_f, |
| 151 | template BIT4 sapi, template BIT1 cr) := |
| 152 | tr_LLC_U('0111'B, p_f, Information_field_U:{sABM := sabm_xid}, sapi, cr); |
| 153 | template (value) PDU_LLC ts_LLC_SABM(template (value) SABM_Information sabm_xid, |
| 154 | template (value) BIT1 p_f, |
| 155 | template (value) BIT4 sapi, template (value) BIT1 cr) := |
| 156 | ts_LLC_U('0111'B, p_f, Information_field_U:{sABM := sabm_xid}, sapi, cr); |
| 157 | |
| 158 | template PDU_LLC tr_LLC_UA(template UA_Information ua_xid, template BIT1 p_f, |
| 159 | template BIT4 sapi, template BIT1 cr) := |
| 160 | tr_LLC_U('0110'B, p_f, Information_field_U:{uA := ua_xid}, sapi, cr); |
| 161 | template (value) PDU_LLC ts_LLC_UA(template (value) UA_Information ua_xid, |
| 162 | template (value) BIT1 p_f, |
| 163 | template (value) BIT4 sapi, template (value) BIT1 cr) := |
| 164 | ts_LLC_U('0110'B, p_f, Information_field_U:{uA := ua_xid}, sapi, cr); |
| 165 | |
| 166 | template PDU_LLC tr_LLC_FRMR(template FRMR_Information frmr, template BIT1 p_f, |
| 167 | template BIT4 sapi, template BIT1 cr) := |
| 168 | tr_LLC_U('1000'B, p_f, Information_field_U:{fRMR := frmr}, sapi, cr); |
| 169 | template (value) PDU_LLC ts_LLC_FRMR(template (value) FRMR_Information frmr, |
| 170 | template (value) BIT1 p_f, |
| 171 | template (value) BIT4 sapi, template (value) BIT1 cr) := |
| 172 | ts_LLC_U('1000'B, p_f, Information_field_U:{fRMR := frmr}, sapi, cr); |
| 173 | |
| 174 | template PDU_LLC tr_LLC_DM(template BIT1 p_f, template BIT4 sapi, template BIT1 cr) := |
| 175 | tr_LLC_U('0001'B, p_f, Information_field_U:{dM := ''O}, sapi, cr); |
| 176 | template (value) PDU_LLC ts_LLC_DM(template (value) BIT1 p_f, template (value) BIT4 sapi, |
| 177 | template (value) BIT1 cr) := |
| 178 | ts_LLC_U('0001'B, p_f, Information_field_U:{dM := ''O}, sapi, cr); |
Harald Welte | 37692d8 | 2018-02-18 15:21:34 +0100 | [diff] [blame] | 179 | |
Harald Welte | ceaff26 | 2019-04-23 22:18:05 +0200 | [diff] [blame] | 180 | template PDU_LLC tr_LLC_NULL(template BIT1 p_f, template BIT4 sapi, template BIT1 cr) := |
| 181 | tr_LLC_U('0000'B, p_f, Information_field_U:{nULL := ''O}, sapi, cr); |
| 182 | template (value) PDU_LLC ts_LLC_NULL(template (value) BIT1 p_f, template (value) BIT4 sapi, |
| 183 | template (value) BIT1 cr) := |
| 184 | ts_LLC_U('0000'B, p_f, Information_field_U:{nULL := ''O}, sapi, cr); |
| 185 | |
| 186 | template PDU_LLC tr_LLC_DISC(template BIT1 p_f, template BIT4 sapi, template BIT1 cr) := |
| 187 | tr_LLC_U('0100'B, p_f, Information_field_U:{dISC := ''O}, sapi, cr); |
| 188 | template (value) PDU_LLC ts_LLC_DISC(template (value) BIT1 p_f, template (value) BIT4 sapi, |
| 189 | template (value) BIT1 cr) := |
| 190 | ts_LLC_U('0100'B, p_f, Information_field_U:{dISC := ''O}, sapi, cr); |
| 191 | |
| 192 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 193 | const BIT4 c_LLC_SAPI_LLGMM := '0001'B; |
| 194 | const BIT4 c_LLC_SAPI_TOM2 := '0010'B; |
| 195 | const BIT4 c_LLC_SAPI_LL3 := '0011'B; |
| 196 | const BIT4 c_LLC_SAPI_LL5 := '0101'B; |
| 197 | const BIT4 c_LLC_SAPI_LLSMS := '0111'B; |
| 198 | const BIT4 c_LLC_SAPI_TOM8 := '1000'B; |
| 199 | const BIT4 c_LLC_SAPI_LL9 := '1001'B; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 200 | const BIT4 c_LLC_SAPI_LL11 := '1011'B; |
| 201 | |
| 202 | const BIT1 LLC_CR_DL_CMD := '1'B; |
| 203 | const BIT1 LLC_CR_DL_RSP := '0'B; |
| 204 | const BIT1 LLC_CR_UL_CMD := '0'B; |
| 205 | const BIT1 LLC_CR_UL_RSP := '1'B; |
| 206 | |
| 207 | /* LLC UI frame with SAPI for L3 payload */ |
Harald Welte | d471901 | 2018-02-17 16:45:06 +0100 | [diff] [blame] | 208 | template PDU_LLC tr_LLC_UI_L3 := ( tr_LLC_UI(?, c_LLC_SAPI_LLGMM) ); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 209 | |
Harald Welte | a2526a8 | 2018-02-18 19:03:36 +0100 | [diff] [blame] | 210 | /* LLC UI frame with SAPI for User payload */ |
| 211 | template PDU_LLC tr_LLC_UI_USER := tr_LLC_UI(?, (c_LLC_SAPI_LL3, |
| 212 | c_LLC_SAPI_LL5, |
| 213 | c_LLC_SAPI_LL9, |
| 214 | c_LLC_SAPI_LL11) |
| 215 | ); |
| 216 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 217 | |
Harald Welte | d21f6a2 | 2019-05-02 09:50:34 +0200 | [diff] [blame] | 218 | template XID tr_XID(template XID_Data xd := ?) := { |
| 219 | xl := ?, |
| 220 | typefield := ?, |
| 221 | xID_length := ?, |
| 222 | xID_Data := xd |
| 223 | }; |
| 224 | template (value) XID ts_XID(template (value) BIT5 tf, template (value) XID_Data xd) := { |
| 225 | xl := '0'B, |
| 226 | typefield := tf, |
| 227 | xID_length := { |
| 228 | short_len := 0 |
| 229 | }, |
| 230 | xID_Data := xd |
| 231 | }; |
| 232 | |
| 233 | template XID tr_XID_kU(template uint8_t ku) := tr_XID({kU := ku}); |
| 234 | template (value) XID ts_XID_kU(template (value) uint8_t ku) := ts_XID('01010'B, {kU := ku}); |
| 235 | |
| 236 | template XID tr_XID_kD(template uint8_t kd) := tr_XID({kD := kd}); |
| 237 | template (value) XID ts_XID_kD(template (value) uint8_t kd) := ts_XID('01001'B, {kD := kd}); |
| 238 | |
| 239 | template XID tr_XID_mD(template uint15_t md) := tr_XID({mD := {spare := '0'B, mDValue := md}}); |
| 240 | template (value) XID ts_XID_mD(template (value) uint15_t md) := ts_XID('00111'B, {mD := { spare := '0'B, mDValue := md}}); |
| 241 | |
| 242 | template XID tr_XID_mU(template uint15_t mu) := tr_XID({mU := {spare := '0'B, mUValue := mu}}); |
| 243 | template (value) XID ts_XID_mU(template (value) uint15_t mu) := ts_XID('01000'B, {mU := { spare := '0'B, mUValue := mu}}); |
| 244 | |
| 245 | template XID tr_XID_N201I(template uint11_t n201i) := |
| 246 | tr_XID({n201_I := {spare := '00000'B, n201IValue := n201i}}); |
| 247 | template (value) XID ts_XID_N201I(template (value) uint11_t n201i) := |
| 248 | ts_XID('00110'B, {n201_I := { spare := '00000'B, n201IValue := n201i}}); |
| 249 | |
| 250 | template XID tr_XID_N201U(template uint11_t n201u) := |
| 251 | tr_XID({n201_U := {spare := '00000'B, n201UValue := n201u}}); |
| 252 | template (value) XID ts_XID_N201U(template (value) uint11_t n201u) := |
| 253 | ts_XID('00101'B, {n201_U := { spare := '00000'B, n201UValue := n201u}}); |
| 254 | |
| 255 | template XID tr_XID_N200(template uint4_t n200) := |
| 256 | tr_XID({n200 := { retransmissions := n200, spare := '0000'B}}); |
| 257 | template (value) XID ts_XID_N200(template (value) uint4_t n200) := |
| 258 | ts_XID('00100'B, {n200 := { retransmissions := n200, spare := '0000'B}}); |
| 259 | |
| 260 | template XID tr_XID_T200(template uint12_t t200) := |
| 261 | tr_XID({t200 := { spare := '0000'B, t200Value := t200}}); |
| 262 | template (value) XID ts_XID_T200(template (value) uint12_t t200) := |
| 263 | ts_XID('00011'B, {t200 := { spare := '0000'B, t200Value := t200}}); |
| 264 | |
| 265 | template XID tr_XID_version(template uint4_t v) := |
| 266 | tr_XID({version := {version_value := v, spare := '0000'B}}); |
| 267 | template (value) XID ts_XID_version(template (value) uint4_t v) := |
| 268 | ts_XID('00000'B, {version := {version_value := v, spare := '0000'B}}); |
| 269 | |
| 270 | template XID tr_XID_IOV_UI(template OCT4 iov) := tr_XID({iOV_UI := iov}); |
| 271 | template (value) XID ts_XID_IOV_UI(template (value) OCT4 iov) := ts_XID('00001'B, {iOV_UI := iov}); |
| 272 | |
| 273 | template XID tr_XID_IOV_I(template OCT4 iov) := tr_XID({iOV_I := iov}); |
| 274 | template (value) XID ts_XID_IOV_I(template (value) OCT4 iov) := ts_XID('00010'B, {iOV_I := iov}); |
| 275 | |
| 276 | template XID tr_XID_L3(template octetstring l3) := tr_XID({l3param := l3}); |
| 277 | template (value) XID ts_XID_L3(template (value) octetstring l3) := ts_XID('01011'B, {l3param := l3}); |
| 278 | |
| 279 | template XID tr_XID_RESET := tr_XID({reset := ''O}); |
| 280 | template (value) XID ts_XID_RESET := ts_XID('01100'B, {reset := ''O}); |
| 281 | |
| 282 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 283 | } |