Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file lapdm.c |
| 2 | * GSM LAPDm (TS 04.06) implementation. */ |
| 3 | /* |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 4 | * (C) 2010-2019 by Harald Welte <laforge@gnumonks.org> |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 5 | * (C) 2010-2011 by Andreas Eversberg <jolly@eversberg.eu> |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 6 | * (C) 2014-2016 by sysmocom - s.f.m.c GmbH |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 7 | * |
| 8 | * All Rights Reserved |
| 9 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
| 11 | * |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along |
| 23 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 25 | * |
| 26 | */ |
| 27 | |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 28 | /*! \addtogroup lapdm |
| 29 | * @{ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 30 | * \file lapdm.c */ |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 31 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 32 | #include <stdio.h> |
| 33 | #include <stdint.h> |
| 34 | #include <string.h> |
| 35 | #include <errno.h> |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 36 | |
| 37 | #include <osmocom/core/logging.h> |
| 38 | #include <osmocom/core/timer.h> |
| 39 | #include <osmocom/core/msgb.h> |
| 40 | #include <osmocom/core/utils.h> |
| 41 | |
| 42 | #include <osmocom/gsm/tlv.h> |
| 43 | #include <osmocom/gsm/rsl.h> |
| 44 | #include <osmocom/gsm/prim.h> |
| 45 | #include <osmocom/gsm/gsm_utils.h> |
| 46 | #include <osmocom/gsm/lapdm.h> |
| 47 | |
| 48 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 49 | #include <osmocom/gsm/protocol/gsm_08_58.h> |
| 50 | |
Harald Welte | 1284c3e | 2018-05-01 18:11:02 +0200 | [diff] [blame] | 51 | #define LAPD_U_SABM 0x7 |
| 52 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 53 | /* TS 04.06 Figure 4 / Section 3.2 */ |
| 54 | #define LAPDm_LPD_NORMAL 0 |
| 55 | #define LAPDm_LPD_SMSCB 1 |
| 56 | #define LAPDm_SAPI_NORMAL 0 |
| 57 | #define LAPDm_SAPI_SMS 3 |
| 58 | #define LAPDm_ADDR(lpd, sapi, cr) ((((lpd) & 0x3) << 5) | (((sapi) & 0x7) << 2) | (((cr) & 0x1) << 1) | 0x1) |
| 59 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 60 | #define LAPDm_ADDR_LPD(addr) (((addr) >> 5) & 0x3) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 61 | #define LAPDm_ADDR_SAPI(addr) (((addr) >> 2) & 0x7) |
| 62 | #define LAPDm_ADDR_CR(addr) (((addr) >> 1) & 0x1) |
| 63 | #define LAPDm_ADDR_EA(addr) ((addr) & 0x1) |
| 64 | |
| 65 | /* TS 04.06 Table 3 / Section 3.4.3 */ |
| 66 | #define LAPDm_CTRL_I(nr, ns, p) ((((nr) & 0x7) << 5) | (((p) & 0x1) << 4) | (((ns) & 0x7) << 1)) |
| 67 | #define LAPDm_CTRL_S(nr, s, p) ((((nr) & 0x7) << 5) | (((p) & 0x1) << 4) | (((s) & 0x3) << 2) | 0x1) |
| 68 | #define LAPDm_CTRL_U(u, p) ((((u) & 0x1c) << (5-2)) | (((p) & 0x1) << 4) | (((u) & 0x3) << 2) | 0x3) |
| 69 | |
| 70 | #define LAPDm_CTRL_is_I(ctrl) (((ctrl) & 0x1) == 0) |
| 71 | #define LAPDm_CTRL_is_S(ctrl) (((ctrl) & 0x3) == 1) |
| 72 | #define LAPDm_CTRL_is_U(ctrl) (((ctrl) & 0x3) == 3) |
| 73 | |
| 74 | #define LAPDm_CTRL_U_BITS(ctrl) ((((ctrl) & 0xC) >> 2) | ((ctrl) & 0xE0) >> 3) |
| 75 | #define LAPDm_CTRL_PF_BIT(ctrl) (((ctrl) >> 4) & 0x1) |
| 76 | |
| 77 | #define LAPDm_CTRL_S_BITS(ctrl) (((ctrl) & 0xC) >> 2) |
| 78 | |
| 79 | #define LAPDm_CTRL_I_Ns(ctrl) (((ctrl) & 0xE) >> 1) |
| 80 | #define LAPDm_CTRL_Nr(ctrl) (((ctrl) & 0xE0) >> 5) |
| 81 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 82 | #define LAPDm_LEN(len) ((len << 2) | 0x1) |
| 83 | #define LAPDm_MORE 0x2 |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 84 | #define LAPDm_EL 0x1 |
| 85 | |
| 86 | #define LAPDm_U_UI 0x0 |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 87 | |
| 88 | /* TS 04.06 Section 5.8.3 */ |
| 89 | #define N201_AB_SACCH 18 |
| 90 | #define N201_AB_SDCCH 20 |
| 91 | #define N201_AB_FACCH 20 |
| 92 | #define N201_Bbis 23 |
| 93 | #define N201_Bter_SACCH 21 |
| 94 | #define N201_Bter_SDCCH 23 |
| 95 | #define N201_Bter_FACCH 23 |
| 96 | #define N201_B4 19 |
| 97 | |
| 98 | /* 5.8.2.1 N200 during establish and release */ |
| 99 | #define N200_EST_REL 5 |
| 100 | /* 5.8.2.1 N200 during timer recovery state */ |
| 101 | #define N200_TR_SACCH 5 |
| 102 | #define N200_TR_SDCCH 23 |
| 103 | #define N200_TR_FACCH_FR 34 |
| 104 | #define N200_TR_EFACCH_FR 48 |
| 105 | #define N200_TR_FACCH_HR 29 |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 106 | /* FIXME: set N200 depending on chan_nr */ |
| 107 | #define N200 N200_TR_SDCCH |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 108 | |
| 109 | enum lapdm_format { |
| 110 | LAPDm_FMT_A, |
| 111 | LAPDm_FMT_B, |
| 112 | LAPDm_FMT_Bbis, |
| 113 | LAPDm_FMT_Bter, |
| 114 | LAPDm_FMT_B4, |
| 115 | }; |
| 116 | |
Max | adef12a | 2016-05-25 15:25:02 +0200 | [diff] [blame] | 117 | const struct value_string osmo_ph_prim_names[] = { |
| 118 | { PRIM_PH_DATA, "PH-DATA" }, |
| 119 | { PRIM_PH_RACH, "PH-RANDOM_ACCESS" }, |
| 120 | { PRIM_PH_CONN, "PH-CONNECT" }, |
| 121 | { PRIM_PH_EMPTY_FRAME, "PH-EMPTY_FRAME" }, |
| 122 | { PRIM_PH_RTS, "PH-RTS" }, |
| 123 | { PRIM_MPH_INFO, "MPH-INFO" }, |
| 124 | { PRIM_TCH, "TCH" }, |
| 125 | { PRIM_TCH_RTS, "TCH-RTS" }, |
| 126 | { 0, NULL } |
| 127 | }; |
| 128 | |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 129 | extern void *tall_lapd_ctx; |
| 130 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 131 | static int lapdm_send_ph_data_req(struct lapd_msg_ctx *lctx, struct msgb *msg); |
| 132 | static int send_rslms_dlsap(struct osmo_dlsap_prim *dp, |
| 133 | struct lapd_msg_ctx *lctx); |
Daniel Willmann | 3dc4e16 | 2014-03-20 19:24:48 +0100 | [diff] [blame] | 134 | static int update_pending_frames(struct lapd_msg_ctx *lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 135 | |
| 136 | static void lapdm_dl_init(struct lapdm_datalink *dl, |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 137 | struct lapdm_entity *entity, int t200_ms, uint32_t n200, |
| 138 | const char *name) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 139 | { |
| 140 | memset(dl, 0, sizeof(*dl)); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 141 | dl->entity = entity; |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 142 | lapd_dl_init2(&dl->dl, 1, 8, 251, name); /* Section 5.8.5 of TS 04.06 */ |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 143 | dl->dl.reestablish = 0; /* GSM uses no reestablish */ |
| 144 | dl->dl.send_ph_data_req = lapdm_send_ph_data_req; |
| 145 | dl->dl.send_dlsap = send_rslms_dlsap; |
Daniel Willmann | 3dc4e16 | 2014-03-20 19:24:48 +0100 | [diff] [blame] | 146 | dl->dl.update_pending_frames = update_pending_frames; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 147 | dl->dl.n200_est_rel = N200_EST_REL; |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 148 | dl->dl.n200 = n200; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 149 | dl->dl.t203_sec = 0; dl->dl.t203_usec = 0; |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 150 | dl->dl.t200_sec = t200_ms / 1000; dl->dl.t200_usec = (t200_ms % 1000) * 1000; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 151 | } |
| 152 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 153 | /*! initialize a LAPDm entity and all datalinks inside |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 154 | * \param[in] le LAPDm entity |
| 155 | * \param[in] mode \ref lapdm_mode (BTS/MS) |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 156 | * \param[in] t200 T200 re-transmission timer for all SAPIs in seconds |
| 157 | * |
| 158 | * Don't use this function; It doesn't support different T200 values per API |
| 159 | * and doesn't permit the caller to specify the N200 counter, both of which |
| 160 | * are required by GSM specs and supported by lapdm_entity_init2(). |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 161 | */ |
Andreas.Eversberg | 5ac4478 | 2011-11-06 20:35:48 +0100 | [diff] [blame] | 162 | void lapdm_entity_init(struct lapdm_entity *le, enum lapdm_mode mode, int t200) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 163 | { |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 164 | /* convert from single full-second value to per-SAPI milli-second value */ |
| 165 | int t200_ms_sapi_arr[_NR_DL_SAPI]; |
| 166 | int i; |
| 167 | |
| 168 | for (i = 0; i < ARRAY_SIZE(t200_ms_sapi_arr); i++) |
| 169 | t200_ms_sapi_arr[i] = t200 * 1000; |
| 170 | |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 171 | return lapdm_entity_init3(le, mode, t200_ms_sapi_arr, N200, NULL); |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /*! initialize a LAPDm entity and all datalinks inside |
| 175 | * \param[in] le LAPDm entity |
| 176 | * \param[in] mode lapdm_mode (BTS/MS) |
| 177 | * \param[in] t200_ms per-SAPI array of T200 re-transmission timer in milli-seconds |
| 178 | * \param[in] n200 N200 re-transmisison count |
| 179 | */ |
| 180 | void lapdm_entity_init2(struct lapdm_entity *le, enum lapdm_mode mode, |
| 181 | const int *t200_ms, int n200) |
| 182 | { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 183 | lapdm_entity_init3(le, mode, t200_ms, n200, NULL); |
| 184 | } |
| 185 | |
| 186 | /*! initialize a LAPDm entity and all datalinks inside |
| 187 | * \param[in] le LAPDm entity |
| 188 | * \param[in] mode lapdm_mode (BTS/MS) |
| 189 | * \param[in] t200_ms per-SAPI array of T200 re-transmission timer in milli-seconds |
| 190 | * \param[in] n200 N200 re-transmisison count |
| 191 | * \param[in] name human-readable name (will be copied internally + extended with SAPI) |
| 192 | */ |
| 193 | void lapdm_entity_init3(struct lapdm_entity *le, enum lapdm_mode mode, |
| 194 | const int *t200_ms, int n200, const char *name_pfx) |
| 195 | { |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 196 | unsigned int i; |
| 197 | |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 198 | for (i = 0; i < ARRAY_SIZE(le->datalink); i++) { |
| 199 | char name[256]; |
| 200 | if (name_pfx) { |
| 201 | snprintf(name, sizeof(name), "%s[%s]", name_pfx, i == 0 ? "0" : "3"); |
| 202 | lapdm_dl_init(&le->datalink[i], le, t200_ms[i], n200, name); |
| 203 | } else |
| 204 | lapdm_dl_init(&le->datalink[i], le, t200_ms[i], n200, NULL); |
| 205 | } |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 206 | |
| 207 | lapdm_entity_set_mode(le, mode); |
| 208 | } |
| 209 | |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 210 | static int get_n200_dcch(enum gsm_chan_t chan_t) |
| 211 | { |
| 212 | switch (chan_t) { |
| 213 | case GSM_LCHAN_SDCCH: |
| 214 | return N200_TR_SDCCH; |
| 215 | case GSM_LCHAN_TCH_F: |
| 216 | return N200_TR_FACCH_FR; |
| 217 | case GSM_LCHAN_TCH_H: |
| 218 | return N200_TR_FACCH_HR; |
| 219 | default: |
| 220 | return -1; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | /*! initialize a LAPDm channel and all its channels |
| 225 | * \param[in] lc lapdm_channel to be initialized |
| 226 | * \param[in] mode lapdm_mode (BTS/MS) |
| 227 | * |
| 228 | * Don't use this function; It doesn't support different T200 values per API |
| 229 | * and doesn't set the correct N200 counter, both of which |
| 230 | * are required by GSM specs and supported by lapdm_channel_init2(). |
| 231 | */ |
| 232 | void lapdm_channel_init(struct lapdm_channel *lc, enum lapdm_mode mode) |
| 233 | { |
| 234 | /* emulate old backwards-compatible behavior with 1s/2s */ |
| 235 | const int t200_ms_dcch[_NR_DL_SAPI] = { 1000, 1000 }; |
| 236 | const int t200_ms_acch[_NR_DL_SAPI] = { 2000, 2000 }; |
| 237 | |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 238 | lapdm_channel_init3(lc, mode, t200_ms_dcch, t200_ms_acch, GSM_LCHAN_SDCCH, NULL); |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 239 | } |
| 240 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 241 | /*! initialize a LAPDm channel and all its channels |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 242 | * \param[in] lc \ref lapdm_channel to be initialized |
| 243 | * \param[in] mode \ref lapdm_mode (BTS/MS) |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 244 | * \param[in] t200_ms_dcch per-SAPI array of T200 in milli-seconds for DCCH |
| 245 | * \param[in] t200_ms_acch per-SAPI array of T200 in milli-seconds for SACCH |
| 246 | * \param[in] chan_t GSM channel type (to correctly set N200) |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 247 | */ |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 248 | int lapdm_channel_init2(struct lapdm_channel *lc, enum lapdm_mode mode, |
| 249 | const int *t200_ms_dcch, const int *t200_ms_acch, enum gsm_chan_t chan_t) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 250 | { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 251 | return lapdm_channel_init3(lc, mode, t200_ms_dcch, t200_ms_acch, chan_t, NULL); |
| 252 | } |
| 253 | |
| 254 | /*! initialize a LAPDm channel and all its channels |
| 255 | * \param[in] lc \ref lapdm_channel to be initialized |
| 256 | * \param[in] mode \ref lapdm_mode (BTS/MS) |
| 257 | * \param[in] t200_ms_dcch per-SAPI array of T200 in milli-seconds for DCCH |
| 258 | * \param[in] t200_ms_acch per-SAPI array of T200 in milli-seconds for SACCH |
| 259 | * \param[in] chan_t GSM channel type (to correctly set N200) |
| 260 | * \parma[in] name_pfx human-readable name (copied by function + extended with ACCH/DCCH) |
| 261 | */ |
| 262 | int lapdm_channel_init3(struct lapdm_channel *lc, enum lapdm_mode mode, |
| 263 | const int *t200_ms_dcch, const int *t200_ms_acch, enum gsm_chan_t chan_t, |
| 264 | const char *name_pfx) |
| 265 | { |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 266 | int n200_dcch = get_n200_dcch(chan_t); |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 267 | char namebuf[256]; |
| 268 | char *name = NULL; |
| 269 | |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 270 | if (n200_dcch < 0) |
| 271 | return -EINVAL; |
| 272 | |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 273 | osmo_talloc_replace_string(tall_lapd_ctx, &lc->name, name_pfx); |
| 274 | |
| 275 | if (name_pfx) { |
| 276 | snprintf(namebuf, sizeof(namebuf), "%s[ACCH]", name_pfx); |
| 277 | name = namebuf; |
| 278 | } |
| 279 | lapdm_entity_init3(&lc->lapdm_acch, mode, t200_ms_acch, N200_TR_SACCH, name); |
Harald Welte | 3e8c520 | 2018-05-04 20:58:48 +0200 | [diff] [blame] | 280 | lc->lapdm_acch.lapdm_ch = lc; |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 281 | |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 282 | if (name_pfx) { |
| 283 | snprintf(namebuf, sizeof(namebuf), "%s[DCCH]", name_pfx); |
| 284 | name = namebuf; |
| 285 | } |
| 286 | lapdm_entity_init3(&lc->lapdm_dcch, mode, t200_ms_dcch, n200_dcch, name); |
Harald Welte | 3e8c520 | 2018-05-04 20:58:48 +0200 | [diff] [blame] | 287 | lc->lapdm_dcch.lapdm_ch = lc; |
Harald Welte | 20de620 | 2019-06-02 21:33:38 +0200 | [diff] [blame] | 288 | |
| 289 | return 0; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 292 | /*! flush and release all resoures in LAPDm entity */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 293 | void lapdm_entity_exit(struct lapdm_entity *le) |
| 294 | { |
| 295 | unsigned int i; |
| 296 | struct lapdm_datalink *dl; |
| 297 | |
| 298 | for (i = 0; i < ARRAY_SIZE(le->datalink); i++) { |
| 299 | dl = &le->datalink[i]; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 300 | lapd_dl_exit(&dl->dl); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 304 | /* lfush and release all resources in LAPDm channel |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 305 | * |
| 306 | * A convenience wrapper calling \ref lapdm_entity_exit on both |
| 307 | * entities inside the \ref lapdm_channel |
| 308 | */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 309 | void lapdm_channel_exit(struct lapdm_channel *lc) |
| 310 | { |
| 311 | lapdm_entity_exit(&lc->lapdm_acch); |
| 312 | lapdm_entity_exit(&lc->lapdm_dcch); |
| 313 | } |
| 314 | |
Daniel Willmann | 55405fb | 2014-03-26 13:45:17 +0100 | [diff] [blame] | 315 | struct lapdm_datalink *lapdm_datalink_for_sapi(struct lapdm_entity *le, uint8_t sapi) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 316 | { |
| 317 | switch (sapi) { |
| 318 | case LAPDm_SAPI_NORMAL: |
| 319 | return &le->datalink[0]; |
| 320 | case LAPDm_SAPI_SMS: |
| 321 | return &le->datalink[1]; |
| 322 | default: |
| 323 | return NULL; |
| 324 | } |
| 325 | } |
| 326 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 327 | /* Append padding (if required) */ |
| 328 | static void lapdm_pad_msgb(struct msgb *msg, uint8_t n201) |
| 329 | { |
| 330 | int pad_len = n201 - msgb_l2len(msg); |
| 331 | uint8_t *data; |
| 332 | |
| 333 | if (pad_len < 0) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 334 | LOGP(DLLAPD, LOGL_ERROR, |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 335 | "cannot pad message that is already too big!\n"); |
| 336 | return; |
| 337 | } |
| 338 | |
| 339 | data = msgb_put(msg, pad_len); |
| 340 | memset(data, 0x2B, pad_len); |
| 341 | } |
| 342 | |
| 343 | /* input function that L2 calls when sending messages up to L3 */ |
| 344 | static int rslms_sendmsg(struct msgb *msg, struct lapdm_entity *le) |
| 345 | { |
| 346 | if (!le->l3_cb) { |
| 347 | msgb_free(msg); |
| 348 | return -EIO; |
| 349 | } |
| 350 | |
| 351 | /* call the layer2 message handler that is registered */ |
| 352 | return le->l3_cb(msg, le, le->l3_ctx); |
| 353 | } |
| 354 | |
| 355 | /* write a frame into the tx queue */ |
| 356 | static int tx_ph_data_enqueue(struct lapdm_datalink *dl, struct msgb *msg, |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 357 | uint8_t chan_nr, uint8_t link_id, uint8_t pad) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 358 | { |
| 359 | struct lapdm_entity *le = dl->entity; |
| 360 | struct osmo_phsap_prim pp; |
| 361 | |
| 362 | /* if there is a pending message, queue it */ |
| 363 | if (le->tx_pending || le->flags & LAPDM_ENT_F_POLLING_ONLY) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 364 | *msgb_push(msg, 1) = pad; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 365 | *msgb_push(msg, 1) = link_id; |
| 366 | *msgb_push(msg, 1) = chan_nr; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 367 | msgb_enqueue(&dl->dl.tx_queue, msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 368 | return -EBUSY; |
| 369 | } |
| 370 | |
| 371 | osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_DATA, |
| 372 | PRIM_OP_REQUEST, msg); |
| 373 | pp.u.data.chan_nr = chan_nr; |
| 374 | pp.u.data.link_id = link_id; |
| 375 | |
| 376 | /* send the frame now */ |
| 377 | le->tx_pending = 0; /* disabled flow control */ |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 378 | lapdm_pad_msgb(msg, pad); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 379 | |
| 380 | return le->l1_prim_cb(&pp.oph, le->l1_ctx); |
| 381 | } |
| 382 | |
| 383 | static struct msgb *tx_dequeue_msgb(struct lapdm_entity *le) |
| 384 | { |
| 385 | struct lapdm_datalink *dl; |
| 386 | int last = le->last_tx_dequeue; |
| 387 | int i = last, n = ARRAY_SIZE(le->datalink); |
| 388 | struct msgb *msg = NULL; |
| 389 | |
| 390 | /* round-robin dequeue */ |
| 391 | do { |
| 392 | /* next */ |
| 393 | i = (i + 1) % n; |
| 394 | dl = &le->datalink[i]; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 395 | if ((msg = msgb_dequeue(&dl->dl.tx_queue))) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 396 | break; |
| 397 | } while (i != last); |
| 398 | |
| 399 | if (msg) { |
| 400 | /* Set last dequeue position */ |
| 401 | le->last_tx_dequeue = i; |
| 402 | } |
| 403 | |
| 404 | return msg; |
| 405 | } |
| 406 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 407 | /*! dequeue a msg that's pending transmission via L1 and wrap it into |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 408 | * a osmo_phsap_prim */ |
| 409 | int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp) |
| 410 | { |
| 411 | struct msgb *msg; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 412 | uint8_t pad; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 413 | |
| 414 | msg = tx_dequeue_msgb(le); |
| 415 | if (!msg) |
| 416 | return -ENODEV; |
| 417 | |
| 418 | /* if we have a message, send PH-DATA.req */ |
| 419 | osmo_prim_init(&pp->oph, SAP_GSM_PH, PRIM_PH_DATA, |
| 420 | PRIM_OP_REQUEST, msg); |
| 421 | |
| 422 | /* Pull chan_nr and link_id */ |
| 423 | pp->u.data.chan_nr = *msg->data; |
| 424 | msgb_pull(msg, 1); |
| 425 | pp->u.data.link_id = *msg->data; |
| 426 | msgb_pull(msg, 1); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 427 | pad = *msg->data; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 428 | msgb_pull(msg, 1); |
| 429 | |
| 430 | /* Pad the frame, we can transmit now */ |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 431 | lapdm_pad_msgb(msg, pad); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | /* get next frame from the tx queue. because the ms has multiple datalinks, |
| 437 | * each datalink's queue is read round-robin. |
| 438 | */ |
| 439 | static int l2_ph_data_conf(struct msgb *msg, struct lapdm_entity *le) |
| 440 | { |
| 441 | struct osmo_phsap_prim pp; |
| 442 | |
| 443 | /* we may send again */ |
| 444 | le->tx_pending = 0; |
| 445 | |
| 446 | /* free confirm message */ |
| 447 | if (msg) |
| 448 | msgb_free(msg); |
| 449 | |
| 450 | if (lapdm_phsap_dequeue_prim(le, &pp) < 0) { |
| 451 | /* no message in all queues */ |
| 452 | |
| 453 | /* If user didn't request PH-EMPTY_FRAME.req, abort */ |
| 454 | if (!(le->flags & LAPDM_ENT_F_EMPTY_FRAME)) |
| 455 | return 0; |
| 456 | |
| 457 | /* otherwise, send PH-EMPTY_FRAME.req */ |
| 458 | osmo_prim_init(&pp.oph, SAP_GSM_PH, |
| 459 | PRIM_PH_EMPTY_FRAME, |
| 460 | PRIM_OP_REQUEST, NULL); |
| 461 | } else { |
| 462 | le->tx_pending = 1; |
| 463 | } |
| 464 | |
| 465 | return le->l1_prim_cb(&pp.oph, le->l1_ctx); |
| 466 | } |
| 467 | |
Harald Welte | 542301b | 2018-04-19 16:11:14 +0200 | [diff] [blame] | 468 | /* Is a given msg_type "transparent" as per TS 48.058 Section 8.1 */ |
| 469 | static int rsl_is_transparent(uint8_t msg_type) |
| 470 | { |
| 471 | switch (msg_type) { |
| 472 | case RSL_MT_DATA_IND: |
| 473 | case RSL_MT_UNIT_DATA_IND: |
| 474 | return 1; |
| 475 | case RSL_MT_DATA_REQ: |
| 476 | case RSL_MT_UNIT_DATA_REQ: |
| 477 | return 1; |
| 478 | default: |
| 479 | return 0; |
| 480 | } |
| 481 | } |
| 482 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 483 | /* Create RSLms various RSLms messages */ |
| 484 | static int send_rslms_rll_l3(uint8_t msg_type, struct lapdm_msg_ctx *mctx, |
| 485 | struct msgb *msg) |
| 486 | { |
Harald Welte | 542301b | 2018-04-19 16:11:14 +0200 | [diff] [blame] | 487 | int transparent = rsl_is_transparent(msg_type); |
| 488 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 489 | /* Add the RSL + RLL header */ |
Harald Welte | 542301b | 2018-04-19 16:11:14 +0200 | [diff] [blame] | 490 | rsl_rll_push_l3(msg, msg_type, mctx->chan_nr, mctx->link_id, transparent); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 491 | |
| 492 | /* send off the RSLms message to L3 */ |
| 493 | return rslms_sendmsg(msg, mctx->dl->entity); |
| 494 | } |
| 495 | |
| 496 | /* Take a B4 format message from L1 and create RSLms UNIT DATA IND */ |
| 497 | static int send_rslms_rll_l3_ui(struct lapdm_msg_ctx *mctx, struct msgb *msg) |
| 498 | { |
| 499 | uint8_t l3_len = msg->tail - (uint8_t *)msgb_l3(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 500 | |
| 501 | /* Add the RSL + RLL header */ |
| 502 | msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len); |
Harald Welte | d977f5f | 2018-05-08 21:53:28 +0200 | [diff] [blame] | 503 | |
Harald Welte | f1bdf78 | 2018-05-08 22:03:20 +0200 | [diff] [blame] | 504 | /* Add two non-standard IEs carrying MS power and TA values for B4 (SACCH) */ |
| 505 | if (mctx->lapdm_fmt == LAPDm_FMT_B4) { |
| 506 | msgb_tv_push(msg, RSL_IE_MS_POWER, mctx->tx_power_ind); |
| 507 | msgb_tv_push(msg, RSL_IE_TIMING_ADVANCE, mctx->ta_ind); |
| 508 | } |
Harald Welte | d977f5f | 2018-05-08 21:53:28 +0200 | [diff] [blame] | 509 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 510 | rsl_rll_push_hdr(msg, RSL_MT_UNIT_DATA_IND, mctx->chan_nr, |
| 511 | mctx->link_id, 1); |
Pau Espin Pedrol | a99e110 | 2017-12-08 14:30:47 +0100 | [diff] [blame] | 512 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 513 | return rslms_sendmsg(msg, mctx->dl->entity); |
| 514 | } |
| 515 | |
| 516 | static int send_rll_simple(uint8_t msg_type, struct lapdm_msg_ctx *mctx) |
| 517 | { |
| 518 | struct msgb *msg; |
Harald Welte | 542301b | 2018-04-19 16:11:14 +0200 | [diff] [blame] | 519 | int transparent = rsl_is_transparent(msg_type); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 520 | |
Harald Welte | 542301b | 2018-04-19 16:11:14 +0200 | [diff] [blame] | 521 | msg = rsl_rll_simple(msg_type, mctx->chan_nr, mctx->link_id, transparent); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 522 | |
| 523 | /* send off the RSLms message to L3 */ |
| 524 | return rslms_sendmsg(msg, mctx->dl->entity); |
| 525 | } |
| 526 | |
| 527 | static int rsl_rll_error(uint8_t cause, struct lapdm_msg_ctx *mctx) |
| 528 | { |
| 529 | struct msgb *msg; |
| 530 | |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 531 | LOGDL(&mctx->dl->dl, LOGL_NOTICE, "sending MDL-ERROR-IND %d\n", cause); |
Harald Welte | 542301b | 2018-04-19 16:11:14 +0200 | [diff] [blame] | 532 | msg = rsl_rll_simple(RSL_MT_ERROR_IND, mctx->chan_nr, mctx->link_id, 0); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 533 | msgb_tlv_put(msg, RSL_IE_RLM_CAUSE, 1, &cause); |
| 534 | return rslms_sendmsg(msg, mctx->dl->entity); |
| 535 | } |
| 536 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 537 | /* DLSAP L2 -> L3 (RSLms) */ |
| 538 | static int send_rslms_dlsap(struct osmo_dlsap_prim *dp, |
| 539 | struct lapd_msg_ctx *lctx) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 540 | { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 541 | struct lapd_datalink *dl = lctx->dl; |
| 542 | struct lapdm_datalink *mdl = |
| 543 | container_of(dl, struct lapdm_datalink, dl); |
| 544 | struct lapdm_msg_ctx *mctx = &mdl->mctx; |
| 545 | uint8_t rll_msg = 0; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 546 | |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 547 | switch (OSMO_PRIM_HDR(&dp->oph)) { |
| 548 | case OSMO_PRIM(PRIM_DL_EST, PRIM_OP_INDICATION): |
| 549 | rll_msg = RSL_MT_EST_IND; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 550 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 551 | case OSMO_PRIM(PRIM_DL_EST, PRIM_OP_CONFIRM): |
| 552 | rll_msg = RSL_MT_EST_CONF; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 553 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 554 | case OSMO_PRIM(PRIM_DL_DATA, PRIM_OP_INDICATION): |
| 555 | rll_msg = RSL_MT_DATA_IND; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 556 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 557 | case OSMO_PRIM(PRIM_DL_UNIT_DATA, PRIM_OP_INDICATION): |
| 558 | return send_rslms_rll_l3_ui(mctx, dp->oph.msg); |
| 559 | case OSMO_PRIM(PRIM_DL_REL, PRIM_OP_INDICATION): |
| 560 | rll_msg = RSL_MT_REL_IND; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 561 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 562 | case OSMO_PRIM(PRIM_DL_REL, PRIM_OP_CONFIRM): |
| 563 | rll_msg = RSL_MT_REL_CONF; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 564 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 565 | case OSMO_PRIM(PRIM_DL_SUSP, PRIM_OP_CONFIRM): |
| 566 | rll_msg = RSL_MT_SUSP_CONF; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 567 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 568 | case OSMO_PRIM(PRIM_MDL_ERROR, PRIM_OP_INDICATION): |
| 569 | rsl_rll_error(dp->u.error_ind.cause, mctx); |
| 570 | if (dp->oph.msg) |
| 571 | msgb_free(dp->oph.msg); |
| 572 | return 0; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 573 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 574 | |
| 575 | if (!rll_msg) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 576 | LOGDL(dl, LOGL_ERROR, "Unsupported op %d, prim %d. Please " |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 577 | "fix!\n", dp->oph.primitive, dp->oph.operation); |
| 578 | return -EINVAL; |
| 579 | } |
| 580 | |
| 581 | if (!dp->oph.msg) |
| 582 | return send_rll_simple(rll_msg, mctx); |
| 583 | |
| 584 | return send_rslms_rll_l3(rll_msg, mctx, dp->oph.msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 585 | } |
| 586 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 587 | /* send a data frame to layer 1 */ |
| 588 | static int lapdm_send_ph_data_req(struct lapd_msg_ctx *lctx, struct msgb *msg) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 589 | { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 590 | uint8_t l3_len = msg->tail - msg->data; |
| 591 | struct lapd_datalink *dl = lctx->dl; |
| 592 | struct lapdm_datalink *mdl = |
| 593 | container_of(dl, struct lapdm_datalink, dl); |
| 594 | struct lapdm_msg_ctx *mctx = &mdl->mctx; |
| 595 | int format = lctx->format; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 596 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 597 | /* prepend l2 header */ |
| 598 | msg->l2h = msgb_push(msg, 3); |
| 599 | msg->l2h[0] = LAPDm_ADDR(lctx->lpd, lctx->sapi, lctx->cr); |
| 600 | /* EA is set here too */ |
| 601 | switch (format) { |
| 602 | case LAPD_FORM_I: |
| 603 | msg->l2h[1] = LAPDm_CTRL_I(lctx->n_recv, lctx->n_send, |
| 604 | lctx->p_f); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 605 | break; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 606 | case LAPD_FORM_S: |
| 607 | msg->l2h[1] = LAPDm_CTRL_S(lctx->n_recv, lctx->s_u, lctx->p_f); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 608 | break; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 609 | case LAPD_FORM_U: |
| 610 | msg->l2h[1] = LAPDm_CTRL_U(lctx->s_u, lctx->p_f); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 611 | break; |
| 612 | default: |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 613 | msgb_free(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 614 | return -EINVAL; |
| 615 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 616 | msg->l2h[2] = LAPDm_LEN(l3_len); /* EL is set here too */ |
| 617 | if (lctx->more) |
| 618 | msg->l2h[2] |= LAPDm_MORE; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 619 | |
Andreas.Eversberg | f1f80de | 2011-11-06 20:45:29 +0100 | [diff] [blame] | 620 | /* add ACCH header with last indicated tx-power and TA */ |
| 621 | if ((mctx->link_id & 0x40)) { |
| 622 | struct lapdm_entity *le = mdl->entity; |
| 623 | |
| 624 | msg->l2h = msgb_push(msg, 2); |
| 625 | msg->l2h[0] = le->tx_power; |
| 626 | msg->l2h[1] = le->ta; |
| 627 | } |
| 628 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 629 | return tx_ph_data_enqueue(mctx->dl, msg, mctx->chan_nr, mctx->link_id, |
| 630 | 23); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 631 | } |
| 632 | |
Daniel Willmann | 3dc4e16 | 2014-03-20 19:24:48 +0100 | [diff] [blame] | 633 | static int update_pending_frames(struct lapd_msg_ctx *lctx) |
| 634 | { |
| 635 | struct lapd_datalink *dl = lctx->dl; |
| 636 | struct msgb *msg; |
| 637 | int rc = -1; |
| 638 | |
| 639 | llist_for_each_entry(msg, &dl->tx_queue, list) { |
| 640 | if (LAPDm_CTRL_is_I(msg->l2h[1])) { |
| 641 | msg->l2h[1] = LAPDm_CTRL_I(dl->v_recv, LAPDm_CTRL_I_Ns(msg->l2h[1]), |
| 642 | LAPDm_CTRL_PF_BIT(msg->l2h[1])); |
| 643 | rc = 0; |
| 644 | } else if (LAPDm_CTRL_is_S(msg->l2h[1])) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 645 | LOGDL(dl, LOGL_ERROR, "Supervisory frame in queue, this shouldn't happen\n"); |
Daniel Willmann | 3dc4e16 | 2014-03-20 19:24:48 +0100 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | |
| 649 | return rc; |
| 650 | } |
| 651 | |
Harald Welte | 1284c3e | 2018-05-01 18:11:02 +0200 | [diff] [blame] | 652 | /* determine if receiving a given LAPDm message is not permitted */ |
| 653 | static int lapdm_rx_not_permitted(const struct lapdm_entity *le, |
| 654 | const struct lapd_msg_ctx *lctx) |
| 655 | { |
| 656 | /* we currently only implement SABM related checks here */ |
| 657 | if (lctx->format != LAPD_FORM_U || lctx->s_u != LAPD_U_SABM) |
| 658 | return 0; |
| 659 | |
| 660 | if (le->mode == LAPDM_MODE_BTS) { |
| 661 | if (le == &le->lapdm_ch->lapdm_acch) { |
| 662 | /* no contention resolution on SACCH */ |
| 663 | if (lctx->length > 0) |
| 664 | return RLL_CAUSE_SABM_INFO_NOTALL; |
| 665 | } else { |
| 666 | switch (lctx->sapi) { |
Harald Welte | 1284c3e | 2018-05-01 18:11:02 +0200 | [diff] [blame] | 667 | case 3: |
| 668 | /* SAPI3 doesn't support contention resolution */ |
| 669 | if (lctx->length > 0) |
| 670 | return RLL_CAUSE_SABM_INFO_NOTALL; |
| 671 | break; |
Harald Welte | b82a407 | 2018-05-09 16:31:16 +0200 | [diff] [blame] | 672 | default: |
| 673 | break; |
Harald Welte | 1284c3e | 2018-05-01 18:11:02 +0200 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | } else if (le->mode == LAPDM_MODE_MS) { |
| 677 | /* contention resolution (L3 present) is only sent by MS, but |
| 678 | * never received by it */ |
| 679 | if (lctx->length > 0) |
| 680 | return RLL_CAUSE_SABM_INFO_NOTALL; |
| 681 | } |
| 682 | return 0; |
| 683 | } |
| 684 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 685 | /* input into layer2 (from layer 1) */ |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 686 | static int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le, |
| 687 | uint8_t chan_nr, uint8_t link_id) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 688 | { |
| 689 | uint8_t cbits = chan_nr >> 3; |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 690 | uint8_t sapi; /* we cannot take SAPI from link_id, as L1 has no clue */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 691 | struct lapdm_msg_ctx mctx; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 692 | struct lapd_msg_ctx lctx; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 693 | int rc = 0; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 694 | int n201; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 695 | |
| 696 | /* when we reach here, we have a msgb with l2h pointing to the raw |
| 697 | * 23byte mac block. The l1h has already been purged. */ |
| 698 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 699 | memset(&mctx, 0, sizeof(mctx)); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 700 | mctx.chan_nr = chan_nr; |
| 701 | mctx.link_id = link_id; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 702 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 703 | /* check for L1 chan_nr/link_id and determine LAPDm hdr format */ |
| 704 | if (cbits == 0x10 || cbits == 0x12) { |
| 705 | /* Format Bbis is used on BCCH and CCCH(PCH, NCH and AGCH) */ |
| 706 | mctx.lapdm_fmt = LAPDm_FMT_Bbis; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 707 | n201 = N201_Bbis; |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 708 | sapi = 0; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 709 | } else { |
| 710 | if (mctx.link_id & 0x40) { |
Harald Welte | 7ca604b | 2011-06-29 12:13:51 +0200 | [diff] [blame] | 711 | /* It was received from network on SACCH */ |
| 712 | |
Andreas.Eversberg | 816e178 | 2011-11-06 20:46:30 +0100 | [diff] [blame] | 713 | /* If UI on SACCH sent by BTS, lapdm_fmt must be B4 */ |
| 714 | if (le->mode == LAPDM_MODE_MS |
| 715 | && LAPDm_CTRL_is_U(msg->l2h[3]) |
| 716 | && LAPDm_CTRL_U_BITS(msg->l2h[3]) == 0) { |
Harald Welte | 7ca604b | 2011-06-29 12:13:51 +0200 | [diff] [blame] | 717 | mctx.lapdm_fmt = LAPDm_FMT_B4; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 718 | n201 = N201_B4; |
| 719 | LOGP(DLLAPD, LOGL_INFO, "fmt=B4\n"); |
Harald Welte | 7ca604b | 2011-06-29 12:13:51 +0200 | [diff] [blame] | 720 | } else { |
| 721 | mctx.lapdm_fmt = LAPDm_FMT_B; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 722 | n201 = N201_AB_SACCH; |
| 723 | LOGP(DLLAPD, LOGL_INFO, "fmt=B\n"); |
Harald Welte | 7ca604b | 2011-06-29 12:13:51 +0200 | [diff] [blame] | 724 | } |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 725 | /* SACCH frames have a two-byte L1 header that |
| 726 | * OsmocomBB L1 doesn't strip */ |
| 727 | mctx.tx_power_ind = msg->l2h[0] & 0x1f; |
| 728 | mctx.ta_ind = msg->l2h[1]; |
| 729 | msgb_pull(msg, 2); |
| 730 | msg->l2h += 2; |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 731 | sapi = (msg->l2h[0] >> 2) & 7; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 732 | } else { |
| 733 | mctx.lapdm_fmt = LAPDm_FMT_B; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 734 | LOGP(DLLAPD, LOGL_INFO, "fmt=B\n"); |
Andreas.Eversberg | cbed327 | 2011-11-06 20:43:08 +0100 | [diff] [blame] | 735 | n201 = N201_AB_SDCCH; |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 736 | sapi = (msg->l2h[0] >> 2) & 7; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
Daniel Willmann | 55405fb | 2014-03-26 13:45:17 +0100 | [diff] [blame] | 740 | mctx.dl = lapdm_datalink_for_sapi(le, sapi); |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 741 | /* G.2.1 No action on frames containing an unallocated SAPI. */ |
| 742 | if (!mctx.dl) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 743 | LOGP(DLLAPD, LOGL_NOTICE, "Received frame for unsupported SAPI %d!\n", sapi); |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 744 | msgb_free(msg); |
| 745 | return -EIO; |
| 746 | } |
| 747 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 748 | switch (mctx.lapdm_fmt) { |
| 749 | case LAPDm_FMT_A: |
| 750 | case LAPDm_FMT_B: |
| 751 | case LAPDm_FMT_B4: |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 752 | lctx.dl = &mctx.dl->dl; |
| 753 | /* obtain SAPI from address field */ |
| 754 | mctx.link_id |= LAPDm_ADDR_SAPI(msg->l2h[0]); |
| 755 | /* G.2.3 EA bit set to "0" is not allowed in GSM */ |
| 756 | if (!LAPDm_ADDR_EA(msg->l2h[0])) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 757 | LOGDL(lctx.dl, LOGL_NOTICE, "EA bit 0 is not allowed in GSM\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 758 | msgb_free(msg); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 759 | rsl_rll_error(RLL_CAUSE_FRM_UNIMPL, &mctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 760 | return -EINVAL; |
| 761 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 762 | /* adress field */ |
| 763 | lctx.lpd = LAPDm_ADDR_LPD(msg->l2h[0]); |
| 764 | lctx.sapi = LAPDm_ADDR_SAPI(msg->l2h[0]); |
| 765 | lctx.cr = LAPDm_ADDR_CR(msg->l2h[0]); |
| 766 | /* command field */ |
| 767 | if (LAPDm_CTRL_is_I(msg->l2h[1])) { |
| 768 | lctx.format = LAPD_FORM_I; |
| 769 | lctx.n_send = LAPDm_CTRL_I_Ns(msg->l2h[1]); |
| 770 | lctx.n_recv = LAPDm_CTRL_Nr(msg->l2h[1]); |
| 771 | } else if (LAPDm_CTRL_is_S(msg->l2h[1])) { |
| 772 | lctx.format = LAPD_FORM_S; |
| 773 | lctx.n_recv = LAPDm_CTRL_Nr(msg->l2h[1]); |
| 774 | lctx.s_u = LAPDm_CTRL_S_BITS(msg->l2h[1]); |
| 775 | } else if (LAPDm_CTRL_is_U(msg->l2h[1])) { |
| 776 | lctx.format = LAPD_FORM_U; |
| 777 | lctx.s_u = LAPDm_CTRL_U_BITS(msg->l2h[1]); |
| 778 | } else |
| 779 | lctx.format = LAPD_FORM_UKN; |
| 780 | lctx.p_f = LAPDm_CTRL_PF_BIT(msg->l2h[1]); |
| 781 | if (lctx.sapi != LAPDm_SAPI_NORMAL |
| 782 | && lctx.sapi != LAPDm_SAPI_SMS |
| 783 | && lctx.format == LAPD_FORM_U |
| 784 | && lctx.s_u == LAPDm_U_UI) { |
| 785 | /* 5.3.3 UI frames with invalid SAPI values shall be |
| 786 | * discarded |
| 787 | */ |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 788 | LOGDL(lctx.dl, LOGL_INFO, "sapi=%u (discarding)\n", lctx.sapi); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 789 | msgb_free(msg); |
| 790 | return 0; |
| 791 | } |
| 792 | if (mctx.lapdm_fmt == LAPDm_FMT_B4) { |
| 793 | lctx.n201 = n201; |
| 794 | lctx.length = n201; |
| 795 | lctx.more = 0; |
| 796 | msg->l3h = msg->l2h + 2; |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 797 | msgb_pull_to_l3(msg); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 798 | } else { |
| 799 | /* length field */ |
| 800 | if (!(msg->l2h[2] & LAPDm_EL)) { |
| 801 | /* G.4.1 If the EL bit is set to "0", an |
| 802 | * MDL-ERROR-INDICATION primitive with cause |
| 803 | * "frame not implemented" is sent to the |
| 804 | * mobile management entity. */ |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 805 | LOGDL(lctx.dl, LOGL_NOTICE, "we don't support multi-octet length\n"); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 806 | msgb_free(msg); |
| 807 | rsl_rll_error(RLL_CAUSE_FRM_UNIMPL, &mctx); |
| 808 | return -EINVAL; |
| 809 | } |
| 810 | lctx.n201 = n201; |
| 811 | lctx.length = msg->l2h[2] >> 2; |
| 812 | lctx.more = !!(msg->l2h[2] & LAPDm_MORE); |
| 813 | msg->l3h = msg->l2h + 3; |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 814 | msgb_pull_to_l3(msg); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 815 | } |
| 816 | /* store context for messages from lapd */ |
| 817 | memcpy(&mctx.dl->mctx, &mctx, sizeof(mctx.dl->mctx)); |
Harald Welte | 1284c3e | 2018-05-01 18:11:02 +0200 | [diff] [blame] | 818 | rc =lapdm_rx_not_permitted(le, &lctx); |
| 819 | if (rc > 0) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 820 | LOGDL(lctx.dl, LOGL_NOTICE, "received message not permitted\n"); |
Harald Welte | 1284c3e | 2018-05-01 18:11:02 +0200 | [diff] [blame] | 821 | msgb_free(msg); |
| 822 | rsl_rll_error(rc, &mctx); |
| 823 | return -EINVAL; |
| 824 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 825 | /* send to LAPD */ |
| 826 | rc = lapd_ph_data_ind(msg, &lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 827 | break; |
| 828 | case LAPDm_FMT_Bter: |
| 829 | /* FIXME */ |
| 830 | msgb_free(msg); |
| 831 | break; |
| 832 | case LAPDm_FMT_Bbis: |
| 833 | /* directly pass up to layer3 */ |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 834 | LOGP(DLLAPD, LOGL_INFO, "fmt=Bbis UI\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 835 | msg->l3h = msg->l2h; |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 836 | msgb_pull_to_l3(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 837 | rc = send_rslms_rll_l3(RSL_MT_UNIT_DATA_IND, &mctx, msg); |
| 838 | break; |
| 839 | default: |
| 840 | msgb_free(msg); |
| 841 | } |
| 842 | |
| 843 | return rc; |
| 844 | } |
| 845 | |
| 846 | /* input into layer2 (from layer 1) */ |
| 847 | static int l2_ph_rach_ind(struct lapdm_entity *le, uint8_t ra, uint32_t fn, uint8_t acc_delay) |
| 848 | { |
| 849 | struct abis_rsl_cchan_hdr *ch; |
| 850 | struct gsm48_req_ref req_ref; |
| 851 | struct gsm_time gt; |
| 852 | struct msgb *msg = msgb_alloc_headroom(512, 64, "RSL CHAN RQD"); |
| 853 | |
Jacob Erlbeck | d154f8b | 2015-04-09 14:22:21 +0200 | [diff] [blame] | 854 | if (!msg) |
| 855 | return -ENOMEM; |
| 856 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 857 | msg->l2h = msgb_push(msg, sizeof(*ch)); |
| 858 | ch = (struct abis_rsl_cchan_hdr *)msg->l2h; |
| 859 | rsl_init_cchan_hdr(ch, RSL_MT_CHAN_RQD); |
| 860 | ch->chan_nr = RSL_CHAN_RACH; |
| 861 | |
| 862 | /* generate a RSL CHANNEL REQUIRED message */ |
| 863 | gsm_fn2gsmtime(>, fn); |
| 864 | req_ref.ra = ra; |
| 865 | req_ref.t1 = gt.t1; /* FIXME: modulo? */ |
| 866 | req_ref.t2 = gt.t2; |
| 867 | req_ref.t3_low = gt.t3 & 7; |
| 868 | req_ref.t3_high = gt.t3 >> 3; |
| 869 | |
| 870 | msgb_tv_fixed_put(msg, RSL_IE_REQ_REFERENCE, 3, (uint8_t *) &req_ref); |
| 871 | msgb_tv_put(msg, RSL_IE_ACCESS_DELAY, acc_delay); |
| 872 | |
| 873 | return rslms_sendmsg(msg, le); |
| 874 | } |
| 875 | |
| 876 | static int l2_ph_chan_conf(struct msgb *msg, struct lapdm_entity *le, uint32_t frame_nr); |
| 877 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 878 | /*! Receive a PH-SAP primitive from L1 */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 879 | int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le) |
| 880 | { |
| 881 | struct osmo_phsap_prim *pp = (struct osmo_phsap_prim *) oph; |
| 882 | int rc = 0; |
| 883 | |
| 884 | if (oph->sap != SAP_GSM_PH) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 885 | LOGP(DLLAPD, LOGL_ERROR, "primitive for unknown SAP %u\n", |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 886 | oph->sap); |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 887 | rc = -ENODEV; |
| 888 | goto free; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | switch (oph->primitive) { |
| 892 | case PRIM_PH_DATA: |
| 893 | if (oph->operation != PRIM_OP_INDICATION) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 894 | LOGP(DLLAPD, LOGL_ERROR, "PH_DATA is not INDICATION %u\n", |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 895 | oph->operation); |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 896 | rc = -ENODEV; |
| 897 | goto free; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 898 | } |
| 899 | rc = l2_ph_data_ind(oph->msg, le, pp->u.data.chan_nr, |
| 900 | pp->u.data.link_id); |
| 901 | break; |
| 902 | case PRIM_PH_RTS: |
| 903 | if (oph->operation != PRIM_OP_INDICATION) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 904 | LOGP(DLLAPD, LOGL_ERROR, "PH_RTS is not INDICATION %u\n", |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 905 | oph->operation); |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 906 | rc = -ENODEV; |
| 907 | goto free; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 908 | } |
| 909 | rc = l2_ph_data_conf(oph->msg, le); |
| 910 | break; |
| 911 | case PRIM_PH_RACH: |
| 912 | switch (oph->operation) { |
| 913 | case PRIM_OP_INDICATION: |
| 914 | rc = l2_ph_rach_ind(le, pp->u.rach_ind.ra, pp->u.rach_ind.fn, |
| 915 | pp->u.rach_ind.acc_delay); |
| 916 | break; |
| 917 | case PRIM_OP_CONFIRM: |
| 918 | rc = l2_ph_chan_conf(oph->msg, le, pp->u.rach_ind.fn); |
| 919 | break; |
| 920 | default: |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 921 | rc = -EIO; |
| 922 | goto free; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 923 | } |
| 924 | break; |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 925 | default: |
| 926 | LOGP(DLLAPD, LOGL_ERROR, "Unknown primitive %u\n", |
| 927 | oph->primitive); |
| 928 | rc = -EINVAL; |
| 929 | goto free; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | return rc; |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 933 | |
| 934 | free: |
| 935 | msgb_free(oph->msg); |
| 936 | return rc; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | |
| 940 | /* L3 -> L2 / RSLMS -> LAPDm */ |
| 941 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 942 | /* Set LAPDm context for established connection */ |
| 943 | static int set_lapdm_context(struct lapdm_datalink *dl, uint8_t chan_nr, |
| 944 | uint8_t link_id, int n201, uint8_t sapi) |
| 945 | { |
| 946 | memset(&dl->mctx, 0, sizeof(dl->mctx)); |
| 947 | dl->mctx.dl = dl; |
| 948 | dl->mctx.chan_nr = chan_nr; |
| 949 | dl->mctx.link_id = link_id; |
| 950 | dl->dl.lctx.dl = &dl->dl; |
| 951 | dl->dl.lctx.n201 = n201; |
| 952 | dl->dl.lctx.sapi = sapi; |
| 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 957 | /* L3 requests establishment of data link */ |
| 958 | static int rslms_rx_rll_est_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 959 | { |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 960 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 961 | uint8_t chan_nr = rllh->chan_nr; |
| 962 | uint8_t link_id = rllh->link_id; |
| 963 | uint8_t sapi = rllh->link_id & 7; |
| 964 | struct tlv_parsed tv; |
| 965 | uint8_t length; |
Andreas.Eversberg | cbed327 | 2011-11-06 20:43:08 +0100 | [diff] [blame] | 966 | uint8_t n201 = (rllh->link_id & 0x40) ? N201_AB_SACCH : N201_AB_SDCCH; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 967 | struct osmo_dlsap_prim dp; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 968 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 969 | /* Set LAPDm context for established connection */ |
| 970 | set_lapdm_context(dl, chan_nr, link_id, n201, sapi); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 971 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 972 | rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg) - sizeof(*rllh)); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 973 | if (TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 974 | msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 975 | /* contention resolution establishment procedure */ |
| 976 | if (sapi != 0) { |
| 977 | /* According to clause 6, the contention resolution |
| 978 | * procedure is only permitted with SAPI value 0 */ |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 979 | LOGDL(&dl->dl, LOGL_ERROR, "SAPI != 0 but contention" |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 980 | "resolution (discarding)\n"); |
| 981 | msgb_free(msg); |
| 982 | return send_rll_simple(RSL_MT_REL_IND, &dl->mctx); |
| 983 | } |
| 984 | /* transmit a SABM command with the P bit set to "1". The SABM |
| 985 | * command shall contain the layer 3 message unit */ |
| 986 | length = TLVP_LEN(&tv, RSL_IE_L3_INFO); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 987 | } else { |
| 988 | /* normal establishment procedure */ |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 989 | msg->l3h = msg->l2h + sizeof(*rllh); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 990 | length = 0; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | /* check if the layer3 message length exceeds N201 */ |
Andreas.Eversberg | cbed327 | 2011-11-06 20:43:08 +0100 | [diff] [blame] | 994 | if (length > n201) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 995 | LOGDL(&dl->dl, LOGL_ERROR, "frame too large: %d > N201(%d) " |
Andreas.Eversberg | cbed327 | 2011-11-06 20:43:08 +0100 | [diff] [blame] | 996 | "(discarding)\n", length, n201); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 997 | msgb_free(msg); |
| 998 | return send_rll_simple(RSL_MT_REL_IND, &dl->mctx); |
| 999 | } |
| 1000 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1001 | /* Remove RLL header from msgb and set length to L3-info */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1002 | msgb_pull_to_l3(msg); |
| 1003 | msgb_trim(msg, length); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1004 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1005 | /* prepare prim */ |
| 1006 | osmo_prim_init(&dp.oph, 0, PRIM_DL_EST, PRIM_OP_REQUEST, msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1007 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1008 | /* send to L2 */ |
| 1009 | return lapd_recv_dlsap(&dp, &dl->dl.lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /* L3 requests transfer of unnumbered information */ |
| 1013 | static int rslms_rx_rll_udata_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 1014 | { |
Andreas.Eversberg | 816e178 | 2011-11-06 20:46:30 +0100 | [diff] [blame] | 1015 | struct lapdm_entity *le = dl->entity; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1016 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 1017 | uint8_t chan_nr = rllh->chan_nr; |
| 1018 | uint8_t link_id = rllh->link_id; |
| 1019 | uint8_t sapi = link_id & 7; |
| 1020 | struct tlv_parsed tv; |
Max | 777be2e | 2017-03-01 18:16:44 +0100 | [diff] [blame] | 1021 | int length, ui_bts; |
| 1022 | |
| 1023 | if (!le) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1024 | LOGDL(&dl->dl, LOGL_ERROR, "lapdm_datalink without entity error\n"); |
Max | 777be2e | 2017-03-01 18:16:44 +0100 | [diff] [blame] | 1025 | msgb_free(msg); |
| 1026 | return -EMLINK; |
| 1027 | } |
| 1028 | ui_bts = (le->mode == LAPDM_MODE_BTS && (link_id & 0x40)); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1029 | |
| 1030 | /* check if the layer3 message length exceeds N201 */ |
| 1031 | |
| 1032 | rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh)); |
| 1033 | |
| 1034 | if (TLVP_PRESENT(&tv, RSL_IE_TIMING_ADVANCE)) { |
Andreas.Eversberg | f1f80de | 2011-11-06 20:45:29 +0100 | [diff] [blame] | 1035 | le->ta = *TLVP_VAL(&tv, RSL_IE_TIMING_ADVANCE); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1036 | } |
| 1037 | if (TLVP_PRESENT(&tv, RSL_IE_MS_POWER)) { |
Andreas.Eversberg | f1f80de | 2011-11-06 20:45:29 +0100 | [diff] [blame] | 1038 | le->tx_power = *TLVP_VAL(&tv, RSL_IE_MS_POWER); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1039 | } |
| 1040 | if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1041 | LOGDL(&dl->dl, LOGL_ERROR, "unit data request without message error\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1042 | msgb_free(msg); |
| 1043 | return -EINVAL; |
| 1044 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1045 | msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1046 | length = TLVP_LEN(&tv, RSL_IE_L3_INFO); |
| 1047 | /* check if the layer3 message length exceeds N201 */ |
Andreas Eversberg | 5977db0 | 2013-06-12 09:34:51 +0200 | [diff] [blame] | 1048 | if (length + ((link_id & 0x40) ? 4 : 2) + !ui_bts > 23) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1049 | LOGDL(&dl->dl, LOGL_ERROR, "frame too large: %d > N201(%d) " |
Andreas Eversberg | 5977db0 | 2013-06-12 09:34:51 +0200 | [diff] [blame] | 1050 | "(discarding)\n", length, |
| 1051 | ((link_id & 0x40) ? 18 : 20) + ui_bts); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1052 | msgb_free(msg); |
| 1053 | return -EIO; |
| 1054 | } |
| 1055 | |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1056 | LOGDL(&dl->dl, LOGL_INFO, "sending unit data (tx_power=%d, ta=%d)\n", le->tx_power, le->ta); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1057 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1058 | /* Remove RLL header from msgb and set length to L3-info */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1059 | msgb_pull_to_l3(msg); |
| 1060 | msgb_trim(msg, length); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1061 | |
| 1062 | /* Push L1 + LAPDm header on msgb */ |
Andreas Eversberg | 5977db0 | 2013-06-12 09:34:51 +0200 | [diff] [blame] | 1063 | msg->l2h = msgb_push(msg, 2 + !ui_bts); |
| 1064 | msg->l2h[0] = LAPDm_ADDR(LAPDm_LPD_NORMAL, sapi, dl->dl.cr.loc2rem.cmd); |
| 1065 | msg->l2h[1] = LAPDm_CTRL_U(LAPDm_U_UI, 0); |
Andreas.Eversberg | 816e178 | 2011-11-06 20:46:30 +0100 | [diff] [blame] | 1066 | if (!ui_bts) |
Andreas Eversberg | 5977db0 | 2013-06-12 09:34:51 +0200 | [diff] [blame] | 1067 | msg->l2h[2] = LAPDm_LEN(length); |
| 1068 | if (link_id & 0x40) { |
| 1069 | msg->l2h = msgb_push(msg, 2); |
| 1070 | msg->l2h[0] = le->tx_power; |
| 1071 | msg->l2h[1] = le->ta; |
| 1072 | } |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1073 | |
| 1074 | /* Tramsmit */ |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1075 | return tx_ph_data_enqueue(dl, msg, chan_nr, link_id, 23); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | /* L3 requests transfer of acknowledged information */ |
| 1079 | static int rslms_rx_rll_data_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 1080 | { |
| 1081 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 1082 | struct tlv_parsed tv; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1083 | int length; |
| 1084 | struct osmo_dlsap_prim dp; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1085 | |
| 1086 | rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh)); |
| 1087 | if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1088 | LOGDL(&dl->dl, LOGL_ERROR, "data request without message error\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1089 | msgb_free(msg); |
| 1090 | return -EINVAL; |
| 1091 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1092 | msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO); |
| 1093 | length = TLVP_LEN(&tv, RSL_IE_L3_INFO); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1094 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1095 | /* Remove RLL header from msgb and set length to L3-info */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1096 | msgb_pull_to_l3(msg); |
| 1097 | msgb_trim(msg, length); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1098 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1099 | /* prepare prim */ |
| 1100 | osmo_prim_init(&dp.oph, 0, PRIM_DL_DATA, PRIM_OP_REQUEST, msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1101 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1102 | /* send to L2 */ |
| 1103 | return lapd_recv_dlsap(&dp, &dl->dl.lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | /* L3 requests suspension of data link */ |
| 1107 | static int rslms_rx_rll_susp_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 1108 | { |
| 1109 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 1110 | uint8_t sapi = rllh->link_id & 7; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1111 | struct osmo_dlsap_prim dp; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1112 | |
| 1113 | if (sapi != 0) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1114 | LOGDL(&dl->dl, LOGL_ERROR, "SAPI != 0 while suspending\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1115 | msgb_free(msg); |
| 1116 | return -EINVAL; |
| 1117 | } |
| 1118 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1119 | /* prepare prim */ |
| 1120 | osmo_prim_init(&dp.oph, 0, PRIM_DL_SUSP, PRIM_OP_REQUEST, msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1121 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1122 | /* send to L2 */ |
| 1123 | return lapd_recv_dlsap(&dp, &dl->dl.lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | /* L3 requests resume of data link */ |
| 1127 | static int rslms_rx_rll_res_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 1128 | { |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1129 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1130 | int msg_type = rllh->c.msg_type; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1131 | uint8_t chan_nr = rllh->chan_nr; |
| 1132 | uint8_t link_id = rllh->link_id; |
| 1133 | uint8_t sapi = rllh->link_id & 7; |
| 1134 | struct tlv_parsed tv; |
| 1135 | uint8_t length; |
Andreas.Eversberg | cbed327 | 2011-11-06 20:43:08 +0100 | [diff] [blame] | 1136 | uint8_t n201 = (rllh->link_id & 0x40) ? N201_AB_SACCH : N201_AB_SDCCH; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1137 | struct osmo_dlsap_prim dp; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1138 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1139 | /* Set LAPDm context for established connection */ |
| 1140 | set_lapdm_context(dl, chan_nr, link_id, n201, sapi); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1141 | |
| 1142 | rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh)); |
| 1143 | if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1144 | LOGDL(&dl->dl, LOGL_ERROR, "resume without message error\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1145 | msgb_free(msg); |
| 1146 | return send_rll_simple(RSL_MT_REL_IND, &dl->mctx); |
| 1147 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1148 | msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1149 | length = TLVP_LEN(&tv, RSL_IE_L3_INFO); |
| 1150 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1151 | /* Remove RLL header from msgb and set length to L3-info */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1152 | msgb_pull_to_l3(msg); |
| 1153 | msgb_trim(msg, length); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1154 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1155 | /* prepare prim */ |
| 1156 | osmo_prim_init(&dp.oph, 0, (msg_type == RSL_MT_RES_REQ) ? PRIM_DL_RES |
| 1157 | : PRIM_DL_RECON, PRIM_OP_REQUEST, msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1158 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1159 | /* send to L2 */ |
| 1160 | return lapd_recv_dlsap(&dp, &dl->dl.lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | /* L3 requests release of data link */ |
| 1164 | static int rslms_rx_rll_rel_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 1165 | { |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1166 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1167 | uint8_t mode = 0; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1168 | struct osmo_dlsap_prim dp; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1169 | |
| 1170 | /* get release mode */ |
| 1171 | if (rllh->data[0] == RSL_IE_RELEASE_MODE) |
| 1172 | mode = rllh->data[1] & 1; |
| 1173 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1174 | /* Pull rllh */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1175 | msgb_pull_to_l3(msg); |
Harald Welte | 973c3c3 | 2012-04-26 21:50:54 +0200 | [diff] [blame] | 1176 | |
| 1177 | /* 04.06 3.8.3: No information field is permitted with the DISC |
| 1178 | * command. */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1179 | msgb_trim(msg, 0); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1180 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1181 | /* prepare prim */ |
| 1182 | osmo_prim_init(&dp.oph, 0, PRIM_DL_REL, PRIM_OP_REQUEST, msg); |
| 1183 | dp.u.rel_req.mode = mode; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1184 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1185 | /* send to L2 */ |
| 1186 | return lapd_recv_dlsap(&dp, &dl->dl.lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | /* L3 requests channel in idle state */ |
| 1190 | static int rslms_rx_chan_rqd(struct lapdm_channel *lc, struct msgb *msg) |
| 1191 | { |
| 1192 | struct abis_rsl_cchan_hdr *cch = msgb_l2(msg); |
| 1193 | void *l1ctx = lc->lapdm_dcch.l1_ctx; |
| 1194 | struct osmo_phsap_prim pp; |
| 1195 | |
| 1196 | osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_RACH, |
| 1197 | PRIM_OP_REQUEST, NULL); |
| 1198 | |
| 1199 | if (msgb_l2len(msg) < sizeof(*cch) + 4 + 2 + 2) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1200 | LOGP(DLLAPD, LOGL_ERROR, "Message too short for CHAN RQD!\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1201 | return -EINVAL; |
| 1202 | } |
| 1203 | if (cch->data[0] != RSL_IE_REQ_REFERENCE) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1204 | LOGP(DLLAPD, LOGL_ERROR, "Missing REQ REFERENCE IE\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1205 | return -EINVAL; |
| 1206 | } |
| 1207 | pp.u.rach_req.ra = cch->data[1]; |
| 1208 | pp.u.rach_req.offset = ((cch->data[2] & 0x7f) << 8) | cch->data[3]; |
| 1209 | pp.u.rach_req.is_combined_ccch = cch->data[2] >> 7; |
| 1210 | |
| 1211 | if (cch->data[4] != RSL_IE_ACCESS_DELAY) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1212 | LOGP(DLLAPD, LOGL_ERROR, "Missing ACCESS_DELAY IE\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1213 | return -EINVAL; |
| 1214 | } |
| 1215 | /* TA = 0 - delay */ |
| 1216 | pp.u.rach_req.ta = 0 - cch->data[5]; |
| 1217 | |
| 1218 | if (cch->data[6] != RSL_IE_MS_POWER) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1219 | LOGP(DLLAPD, LOGL_ERROR, "Missing MS POWER IE\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1220 | return -EINVAL; |
| 1221 | } |
| 1222 | pp.u.rach_req.tx_power = cch->data[7]; |
| 1223 | |
| 1224 | msgb_free(msg); |
| 1225 | |
| 1226 | return lc->lapdm_dcch.l1_prim_cb(&pp.oph, l1ctx); |
| 1227 | } |
| 1228 | |
| 1229 | /* L1 confirms channel request */ |
| 1230 | static int l2_ph_chan_conf(struct msgb *msg, struct lapdm_entity *le, uint32_t frame_nr) |
| 1231 | { |
| 1232 | struct abis_rsl_cchan_hdr *ch; |
| 1233 | struct gsm_time tm; |
| 1234 | struct gsm48_req_ref *ref; |
| 1235 | |
| 1236 | gsm_fn2gsmtime(&tm, frame_nr); |
| 1237 | |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1238 | msgb_pull_to_l3(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1239 | msg->l2h = msgb_push(msg, sizeof(*ch) + sizeof(*ref)); |
| 1240 | ch = (struct abis_rsl_cchan_hdr *)msg->l2h; |
| 1241 | rsl_init_cchan_hdr(ch, RSL_MT_CHAN_CONF); |
| 1242 | ch->chan_nr = RSL_CHAN_RACH; |
| 1243 | ch->data[0] = RSL_IE_REQ_REFERENCE; |
| 1244 | ref = (struct gsm48_req_ref *) (ch->data + 1); |
| 1245 | ref->t1 = tm.t1; |
| 1246 | ref->t2 = tm.t2; |
| 1247 | ref->t3_low = tm.t3 & 0x7; |
| 1248 | ref->t3_high = tm.t3 >> 3; |
Pau Espin Pedrol | a99e110 | 2017-12-08 14:30:47 +0100 | [diff] [blame] | 1249 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1250 | return rslms_sendmsg(msg, le); |
| 1251 | } |
| 1252 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1253 | /* incoming RSLms RLL message from L3 */ |
| 1254 | static int rslms_rx_rll(struct msgb *msg, struct lapdm_channel *lc) |
| 1255 | { |
| 1256 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 1257 | int msg_type = rllh->c.msg_type; |
| 1258 | uint8_t sapi = rllh->link_id & 7; |
| 1259 | struct lapdm_entity *le; |
| 1260 | struct lapdm_datalink *dl; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1261 | int rc = 0; |
| 1262 | |
| 1263 | if (msgb_l2len(msg) < sizeof(*rllh)) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1264 | LOGP(DLLAPD, LOGL_ERROR, "Message too short for RLL hdr!\n"); |
Andreas.Eversberg | a42b699 | 2011-11-06 20:31:47 +0100 | [diff] [blame] | 1265 | msgb_free(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1266 | return -EINVAL; |
| 1267 | } |
| 1268 | |
| 1269 | if (rllh->link_id & 0x40) |
| 1270 | le = &lc->lapdm_acch; |
| 1271 | else |
| 1272 | le = &lc->lapdm_dcch; |
| 1273 | |
Harald Welte | 1a87c1b | 2015-12-14 15:26:07 +0100 | [diff] [blame] | 1274 | /* 4.1.1.5 / 4.1.1.6 / 4.1.1.7 all only exist on MS side, not |
| 1275 | * BTS side */ |
| 1276 | if (le->mode == LAPDM_MODE_BTS) { |
| 1277 | switch (msg_type) { |
| 1278 | case RSL_MT_SUSP_REQ: |
| 1279 | case RSL_MT_RES_REQ: |
| 1280 | case RSL_MT_RECON_REQ: |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1281 | LOGP(DLLAPD, LOGL_NOTICE, "(%s) RLL Message '%s' unsupported in BTS side LAPDm\n", |
Harald Welte | 1a87c1b | 2015-12-14 15:26:07 +0100 | [diff] [blame] | 1282 | lc->name, rsl_msg_name(msg_type)); |
| 1283 | msgb_free(msg); |
| 1284 | return -EINVAL; |
| 1285 | break; |
| 1286 | default: |
| 1287 | break; |
| 1288 | } |
| 1289 | } |
| 1290 | |
Holger Hans Peter Freyther | c620604 | 2014-01-23 15:00:55 +0100 | [diff] [blame] | 1291 | /* G.2.1 No action shall be taken on frames containing an unallocated |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1292 | * SAPI. |
| 1293 | */ |
Daniel Willmann | 55405fb | 2014-03-26 13:45:17 +0100 | [diff] [blame] | 1294 | dl = lapdm_datalink_for_sapi(le, sapi); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1295 | if (!dl) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1296 | LOGP(DLLAPD, LOGL_ERROR, "No instance for SAPI %d!\n", sapi); |
Andreas.Eversberg | a42b699 | 2011-11-06 20:31:47 +0100 | [diff] [blame] | 1297 | msgb_free(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1298 | return -EINVAL; |
| 1299 | } |
| 1300 | |
Daniel Willmann | e523392 | 2012-12-25 23:15:50 +0100 | [diff] [blame] | 1301 | switch (msg_type) { |
Daniel Willmann | e523392 | 2012-12-25 23:15:50 +0100 | [diff] [blame] | 1302 | case RSL_MT_DATA_REQ: |
| 1303 | case RSL_MT_SUSP_REQ: |
| 1304 | case RSL_MT_REL_REQ: |
| 1305 | /* This is triggered in abnormal error conditions where |
| 1306 | * set_lapdm_context() was not called for the channel earlier. */ |
| 1307 | if (!dl->dl.lctx.dl) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1308 | LOGP(DLLAPD, LOGL_NOTICE, "(%s) RLL Message '%s' received without LAPDm context. (sapi %d)\n", |
Daniel Willmann | e523392 | 2012-12-25 23:15:50 +0100 | [diff] [blame] | 1309 | lc->name, rsl_msg_name(msg_type), sapi); |
| 1310 | msgb_free(msg); |
| 1311 | return -EINVAL; |
| 1312 | } |
| 1313 | break; |
| 1314 | default: |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1315 | LOGP(DLLAPD, LOGL_INFO, "(%s) RLL Message '%s' received. (sapi %d)\n", |
Daniel Willmann | e523392 | 2012-12-25 23:15:50 +0100 | [diff] [blame] | 1316 | lc->name, rsl_msg_name(msg_type), sapi); |
| 1317 | } |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1318 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1319 | switch (msg_type) { |
| 1320 | case RSL_MT_UNIT_DATA_REQ: |
| 1321 | rc = rslms_rx_rll_udata_req(msg, dl); |
| 1322 | break; |
| 1323 | case RSL_MT_EST_REQ: |
| 1324 | rc = rslms_rx_rll_est_req(msg, dl); |
| 1325 | break; |
| 1326 | case RSL_MT_DATA_REQ: |
| 1327 | rc = rslms_rx_rll_data_req(msg, dl); |
| 1328 | break; |
| 1329 | case RSL_MT_SUSP_REQ: |
| 1330 | rc = rslms_rx_rll_susp_req(msg, dl); |
| 1331 | break; |
| 1332 | case RSL_MT_RES_REQ: |
| 1333 | rc = rslms_rx_rll_res_req(msg, dl); |
| 1334 | break; |
| 1335 | case RSL_MT_RECON_REQ: |
| 1336 | rc = rslms_rx_rll_res_req(msg, dl); |
| 1337 | break; |
| 1338 | case RSL_MT_REL_REQ: |
| 1339 | rc = rslms_rx_rll_rel_req(msg, dl); |
| 1340 | break; |
| 1341 | default: |
| 1342 | LOGP(DLLAPD, LOGL_NOTICE, "Message unsupported.\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1343 | msgb_free(msg); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1344 | rc = -EINVAL; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1345 | } |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1346 | |
| 1347 | return rc; |
| 1348 | } |
| 1349 | |
| 1350 | /* incoming RSLms COMMON CHANNEL message from L3 */ |
| 1351 | static int rslms_rx_com_chan(struct msgb *msg, struct lapdm_channel *lc) |
| 1352 | { |
| 1353 | struct abis_rsl_cchan_hdr *cch = msgb_l2(msg); |
| 1354 | int msg_type = cch->c.msg_type; |
| 1355 | int rc = 0; |
| 1356 | |
| 1357 | if (msgb_l2len(msg) < sizeof(*cch)) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1358 | LOGP(DLLAPD, LOGL_ERROR, "Message too short for COM CHAN hdr!\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1359 | return -EINVAL; |
| 1360 | } |
| 1361 | |
| 1362 | switch (msg_type) { |
| 1363 | case RSL_MT_CHAN_RQD: |
| 1364 | /* create and send RACH request */ |
| 1365 | rc = rslms_rx_chan_rqd(lc, msg); |
| 1366 | break; |
| 1367 | default: |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1368 | LOGP(DLLAPD, LOGL_NOTICE, "Unknown COMMON CHANNEL msg %d!\n", |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1369 | msg_type); |
| 1370 | msgb_free(msg); |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
| 1374 | return rc; |
| 1375 | } |
| 1376 | |
Harald Welte | 7023aa0 | 2019-05-19 12:17:06 +0200 | [diff] [blame] | 1377 | /*! Receive a RSLms \ref msgb from Layer 3. 'msg' ownership is transferred, |
| 1378 | * i.e. caller must not free it */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1379 | int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc) |
| 1380 | { |
| 1381 | struct abis_rsl_common_hdr *rslh = msgb_l2(msg); |
| 1382 | int rc = 0; |
| 1383 | |
| 1384 | if (msgb_l2len(msg) < sizeof(*rslh)) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1385 | LOGP(DLLAPD, LOGL_ERROR, "Message too short RSL hdr!\n"); |
Harald Welte | 7023aa0 | 2019-05-19 12:17:06 +0200 | [diff] [blame] | 1386 | msgb_free(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1387 | return -EINVAL; |
| 1388 | } |
| 1389 | |
| 1390 | switch (rslh->msg_discr & 0xfe) { |
| 1391 | case ABIS_RSL_MDISC_RLL: |
| 1392 | rc = rslms_rx_rll(msg, lc); |
| 1393 | break; |
| 1394 | case ABIS_RSL_MDISC_COM_CHAN: |
| 1395 | rc = rslms_rx_com_chan(msg, lc); |
| 1396 | break; |
| 1397 | default: |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1398 | LOGP(DLLAPD, LOGL_ERROR, "unknown RSLms message " |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1399 | "discriminator 0x%02x", rslh->msg_discr); |
| 1400 | msgb_free(msg); |
| 1401 | return -EINVAL; |
| 1402 | } |
| 1403 | |
| 1404 | return rc; |
| 1405 | } |
| 1406 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1407 | /*! Set the \ref lapdm_mode of a LAPDm entity */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1408 | int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode) |
| 1409 | { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1410 | int i; |
| 1411 | enum lapd_mode lm; |
| 1412 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1413 | switch (mode) { |
| 1414 | case LAPDM_MODE_MS: |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1415 | lm = LAPD_MODE_USER; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1416 | break; |
| 1417 | case LAPDM_MODE_BTS: |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1418 | lm = LAPD_MODE_NETWORK; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1419 | break; |
| 1420 | default: |
| 1421 | return -EINVAL; |
| 1422 | } |
| 1423 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1424 | for (i = 0; i < ARRAY_SIZE(le->datalink); i++) { |
| 1425 | lapd_set_mode(&le->datalink[i].dl, lm); |
| 1426 | } |
| 1427 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1428 | le->mode = mode; |
| 1429 | |
| 1430 | return 0; |
| 1431 | } |
| 1432 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1433 | /*! Set the \ref lapdm_mode of a LAPDm channel*/ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1434 | int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode) |
| 1435 | { |
| 1436 | int rc; |
| 1437 | |
| 1438 | rc = lapdm_entity_set_mode(&lc->lapdm_dcch, mode); |
| 1439 | if (rc < 0) |
| 1440 | return rc; |
| 1441 | |
| 1442 | return lapdm_entity_set_mode(&lc->lapdm_acch, mode); |
| 1443 | } |
| 1444 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1445 | /*! Set the L1 callback and context of a LAPDm channel */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1446 | void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx) |
| 1447 | { |
| 1448 | lc->lapdm_dcch.l1_prim_cb = cb; |
| 1449 | lc->lapdm_acch.l1_prim_cb = cb; |
| 1450 | lc->lapdm_dcch.l1_ctx = ctx; |
| 1451 | lc->lapdm_acch.l1_ctx = ctx; |
| 1452 | } |
| 1453 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1454 | /*! Set the L3 callback and context of a LAPDm channel */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1455 | void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx) |
| 1456 | { |
| 1457 | lc->lapdm_dcch.l3_cb = cb; |
| 1458 | lc->lapdm_acch.l3_cb = cb; |
| 1459 | lc->lapdm_dcch.l3_ctx = ctx; |
| 1460 | lc->lapdm_acch.l3_ctx = ctx; |
| 1461 | } |
| 1462 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1463 | /*! Reset an entire LAPDm entity and all its datalinks */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1464 | void lapdm_entity_reset(struct lapdm_entity *le) |
| 1465 | { |
| 1466 | struct lapdm_datalink *dl; |
| 1467 | int i; |
| 1468 | |
| 1469 | for (i = 0; i < ARRAY_SIZE(le->datalink); i++) { |
| 1470 | dl = &le->datalink[i]; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1471 | lapd_dl_reset(&dl->dl); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1472 | } |
| 1473 | } |
| 1474 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1475 | /*! Reset a LAPDm channel with all its entities */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1476 | void lapdm_channel_reset(struct lapdm_channel *lc) |
| 1477 | { |
| 1478 | lapdm_entity_reset(&lc->lapdm_dcch); |
| 1479 | lapdm_entity_reset(&lc->lapdm_acch); |
| 1480 | } |
| 1481 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1482 | /*! Set the flags of a LAPDm entity */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1483 | void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags) |
| 1484 | { |
| 1485 | le->flags = flags; |
| 1486 | } |
| 1487 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1488 | /*! Set the flags of all LAPDm entities in a LAPDm channel */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1489 | void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags) |
| 1490 | { |
| 1491 | lapdm_entity_set_flags(&lc->lapdm_dcch, flags); |
| 1492 | lapdm_entity_set_flags(&lc->lapdm_acch, flags); |
| 1493 | } |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 1494 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 1495 | /*! @} */ |