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 | |
Vadim Yanitskiy | 29ecabe | 2020-08-27 02:12:23 +0700 | [diff] [blame] | 339 | data = msgb_put(msg, pad_len); /* TODO: random padding */ |
| 340 | memset(data, GSM_MACBLOCK_PADDING, pad_len); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 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 | |
Vadim Yanitskiy | 776c5b1 | 2020-08-27 20:58:49 +0700 | [diff] [blame] | 383 | /* Dequeue a Downlink message for DCCH (dedicated channel) */ |
| 384 | static struct msgb *tx_dequeue_dcch_msgb(struct lapdm_entity *le) |
| 385 | { |
| 386 | struct msgb *msg; |
| 387 | |
| 388 | /* SAPI=0 always has higher priority than SAPI=3 */ |
| 389 | msg = msgb_dequeue(&le->datalink[DL_SAPI0].dl.tx_queue); |
| 390 | if (msg == NULL) /* no SAPI=0 messages, dequeue SAPI=3 (if any) */ |
| 391 | msg = msgb_dequeue(&le->datalink[DL_SAPI3].dl.tx_queue); |
| 392 | |
| 393 | return msg; |
| 394 | } |
| 395 | |
| 396 | /* Dequeue a Downlink message for ACCH (associated channel) */ |
| 397 | static struct msgb *tx_dequeue_acch_msgb(struct lapdm_entity *le) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 398 | { |
| 399 | struct lapdm_datalink *dl; |
| 400 | int last = le->last_tx_dequeue; |
| 401 | int i = last, n = ARRAY_SIZE(le->datalink); |
| 402 | struct msgb *msg = NULL; |
| 403 | |
| 404 | /* round-robin dequeue */ |
| 405 | do { |
| 406 | /* next */ |
| 407 | i = (i + 1) % n; |
| 408 | dl = &le->datalink[i]; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 409 | if ((msg = msgb_dequeue(&dl->dl.tx_queue))) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 410 | break; |
| 411 | } while (i != last); |
| 412 | |
| 413 | if (msg) { |
| 414 | /* Set last dequeue position */ |
| 415 | le->last_tx_dequeue = i; |
| 416 | } |
| 417 | |
| 418 | return msg; |
| 419 | } |
| 420 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 421 | /*! 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] | 422 | * a osmo_phsap_prim */ |
| 423 | int lapdm_phsap_dequeue_prim(struct lapdm_entity *le, struct osmo_phsap_prim *pp) |
| 424 | { |
| 425 | struct msgb *msg; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 426 | uint8_t pad; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 427 | |
Vadim Yanitskiy | 776c5b1 | 2020-08-27 20:58:49 +0700 | [diff] [blame] | 428 | /* Dequeue depending on channel type: DCCH or ACCH. |
| 429 | * See 3GPP TS 44.005, section 4.2.2 "Priority". */ |
| 430 | if (le == &le->lapdm_ch->lapdm_dcch) |
| 431 | msg = tx_dequeue_dcch_msgb(le); |
| 432 | else |
| 433 | msg = tx_dequeue_acch_msgb(le); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 434 | if (!msg) |
| 435 | return -ENODEV; |
| 436 | |
| 437 | /* if we have a message, send PH-DATA.req */ |
| 438 | osmo_prim_init(&pp->oph, SAP_GSM_PH, PRIM_PH_DATA, |
| 439 | PRIM_OP_REQUEST, msg); |
| 440 | |
| 441 | /* Pull chan_nr and link_id */ |
| 442 | pp->u.data.chan_nr = *msg->data; |
| 443 | msgb_pull(msg, 1); |
| 444 | pp->u.data.link_id = *msg->data; |
| 445 | msgb_pull(msg, 1); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 446 | pad = *msg->data; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 447 | msgb_pull(msg, 1); |
| 448 | |
| 449 | /* Pad the frame, we can transmit now */ |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 450 | lapdm_pad_msgb(msg, pad); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | /* get next frame from the tx queue. because the ms has multiple datalinks, |
| 456 | * each datalink's queue is read round-robin. |
| 457 | */ |
| 458 | static int l2_ph_data_conf(struct msgb *msg, struct lapdm_entity *le) |
| 459 | { |
| 460 | struct osmo_phsap_prim pp; |
| 461 | |
| 462 | /* we may send again */ |
| 463 | le->tx_pending = 0; |
| 464 | |
| 465 | /* free confirm message */ |
| 466 | if (msg) |
| 467 | msgb_free(msg); |
| 468 | |
| 469 | if (lapdm_phsap_dequeue_prim(le, &pp) < 0) { |
| 470 | /* no message in all queues */ |
| 471 | |
| 472 | /* If user didn't request PH-EMPTY_FRAME.req, abort */ |
| 473 | if (!(le->flags & LAPDM_ENT_F_EMPTY_FRAME)) |
| 474 | return 0; |
| 475 | |
| 476 | /* otherwise, send PH-EMPTY_FRAME.req */ |
| 477 | osmo_prim_init(&pp.oph, SAP_GSM_PH, |
| 478 | PRIM_PH_EMPTY_FRAME, |
| 479 | PRIM_OP_REQUEST, NULL); |
| 480 | } else { |
| 481 | le->tx_pending = 1; |
| 482 | } |
| 483 | |
| 484 | return le->l1_prim_cb(&pp.oph, le->l1_ctx); |
| 485 | } |
| 486 | |
Harald Welte | 542301b | 2018-04-19 16:11:14 +0200 | [diff] [blame] | 487 | /* Is a given msg_type "transparent" as per TS 48.058 Section 8.1 */ |
| 488 | static int rsl_is_transparent(uint8_t msg_type) |
| 489 | { |
| 490 | switch (msg_type) { |
| 491 | case RSL_MT_DATA_IND: |
| 492 | case RSL_MT_UNIT_DATA_IND: |
| 493 | return 1; |
| 494 | case RSL_MT_DATA_REQ: |
| 495 | case RSL_MT_UNIT_DATA_REQ: |
| 496 | return 1; |
| 497 | default: |
| 498 | return 0; |
| 499 | } |
| 500 | } |
| 501 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 502 | /* Create RSLms various RSLms messages */ |
| 503 | static int send_rslms_rll_l3(uint8_t msg_type, struct lapdm_msg_ctx *mctx, |
| 504 | struct msgb *msg) |
| 505 | { |
Harald Welte | 542301b | 2018-04-19 16:11:14 +0200 | [diff] [blame] | 506 | int transparent = rsl_is_transparent(msg_type); |
| 507 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 508 | /* Add the RSL + RLL header */ |
Harald Welte | 542301b | 2018-04-19 16:11:14 +0200 | [diff] [blame] | 509 | 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] | 510 | |
| 511 | /* send off the RSLms message to L3 */ |
| 512 | return rslms_sendmsg(msg, mctx->dl->entity); |
| 513 | } |
| 514 | |
| 515 | /* Take a B4 format message from L1 and create RSLms UNIT DATA IND */ |
| 516 | static int send_rslms_rll_l3_ui(struct lapdm_msg_ctx *mctx, struct msgb *msg) |
| 517 | { |
| 518 | uint8_t l3_len = msg->tail - (uint8_t *)msgb_l3(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 519 | |
| 520 | /* Add the RSL + RLL header */ |
| 521 | msgb_tv16_push(msg, RSL_IE_L3_INFO, l3_len); |
Harald Welte | d977f5f | 2018-05-08 21:53:28 +0200 | [diff] [blame] | 522 | |
Harald Welte | f1bdf78 | 2018-05-08 22:03:20 +0200 | [diff] [blame] | 523 | /* Add two non-standard IEs carrying MS power and TA values for B4 (SACCH) */ |
| 524 | if (mctx->lapdm_fmt == LAPDm_FMT_B4) { |
| 525 | msgb_tv_push(msg, RSL_IE_MS_POWER, mctx->tx_power_ind); |
| 526 | msgb_tv_push(msg, RSL_IE_TIMING_ADVANCE, mctx->ta_ind); |
| 527 | } |
Harald Welte | d977f5f | 2018-05-08 21:53:28 +0200 | [diff] [blame] | 528 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 529 | rsl_rll_push_hdr(msg, RSL_MT_UNIT_DATA_IND, mctx->chan_nr, |
| 530 | mctx->link_id, 1); |
Pau Espin Pedrol | a99e110 | 2017-12-08 14:30:47 +0100 | [diff] [blame] | 531 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 532 | return rslms_sendmsg(msg, mctx->dl->entity); |
| 533 | } |
| 534 | |
| 535 | static int send_rll_simple(uint8_t msg_type, struct lapdm_msg_ctx *mctx) |
| 536 | { |
| 537 | struct msgb *msg; |
Harald Welte | 542301b | 2018-04-19 16:11:14 +0200 | [diff] [blame] | 538 | int transparent = rsl_is_transparent(msg_type); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 539 | |
Harald Welte | 542301b | 2018-04-19 16:11:14 +0200 | [diff] [blame] | 540 | 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] | 541 | |
| 542 | /* send off the RSLms message to L3 */ |
| 543 | return rslms_sendmsg(msg, mctx->dl->entity); |
| 544 | } |
| 545 | |
| 546 | static int rsl_rll_error(uint8_t cause, struct lapdm_msg_ctx *mctx) |
| 547 | { |
| 548 | struct msgb *msg; |
| 549 | |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 550 | 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] | 551 | 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] | 552 | msgb_tlv_put(msg, RSL_IE_RLM_CAUSE, 1, &cause); |
| 553 | return rslms_sendmsg(msg, mctx->dl->entity); |
| 554 | } |
| 555 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 556 | /* DLSAP L2 -> L3 (RSLms) */ |
| 557 | static int send_rslms_dlsap(struct osmo_dlsap_prim *dp, |
| 558 | struct lapd_msg_ctx *lctx) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 559 | { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 560 | struct lapd_datalink *dl = lctx->dl; |
| 561 | struct lapdm_datalink *mdl = |
| 562 | container_of(dl, struct lapdm_datalink, dl); |
| 563 | struct lapdm_msg_ctx *mctx = &mdl->mctx; |
| 564 | uint8_t rll_msg = 0; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 565 | |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 566 | switch (OSMO_PRIM_HDR(&dp->oph)) { |
| 567 | case OSMO_PRIM(PRIM_DL_EST, PRIM_OP_INDICATION): |
| 568 | rll_msg = RSL_MT_EST_IND; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 569 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 570 | case OSMO_PRIM(PRIM_DL_EST, PRIM_OP_CONFIRM): |
| 571 | rll_msg = RSL_MT_EST_CONF; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 572 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 573 | case OSMO_PRIM(PRIM_DL_DATA, PRIM_OP_INDICATION): |
| 574 | rll_msg = RSL_MT_DATA_IND; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 575 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 576 | case OSMO_PRIM(PRIM_DL_UNIT_DATA, PRIM_OP_INDICATION): |
| 577 | return send_rslms_rll_l3_ui(mctx, dp->oph.msg); |
| 578 | case OSMO_PRIM(PRIM_DL_REL, PRIM_OP_INDICATION): |
| 579 | rll_msg = RSL_MT_REL_IND; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 580 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 581 | case OSMO_PRIM(PRIM_DL_REL, PRIM_OP_CONFIRM): |
| 582 | rll_msg = RSL_MT_REL_CONF; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 583 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 584 | case OSMO_PRIM(PRIM_DL_SUSP, PRIM_OP_CONFIRM): |
| 585 | rll_msg = RSL_MT_SUSP_CONF; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 586 | break; |
Andreas Eversberg | 78122ab | 2011-09-27 12:06:55 +0200 | [diff] [blame] | 587 | case OSMO_PRIM(PRIM_MDL_ERROR, PRIM_OP_INDICATION): |
| 588 | rsl_rll_error(dp->u.error_ind.cause, mctx); |
| 589 | if (dp->oph.msg) |
| 590 | msgb_free(dp->oph.msg); |
| 591 | return 0; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 592 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 593 | |
| 594 | if (!rll_msg) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 595 | LOGDL(dl, LOGL_ERROR, "Unsupported op %d, prim %d. Please " |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 596 | "fix!\n", dp->oph.primitive, dp->oph.operation); |
| 597 | return -EINVAL; |
| 598 | } |
| 599 | |
| 600 | if (!dp->oph.msg) |
| 601 | return send_rll_simple(rll_msg, mctx); |
| 602 | |
| 603 | return send_rslms_rll_l3(rll_msg, mctx, dp->oph.msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 604 | } |
| 605 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 606 | /* send a data frame to layer 1 */ |
| 607 | 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] | 608 | { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 609 | uint8_t l3_len = msg->tail - msg->data; |
| 610 | struct lapd_datalink *dl = lctx->dl; |
| 611 | struct lapdm_datalink *mdl = |
| 612 | container_of(dl, struct lapdm_datalink, dl); |
| 613 | struct lapdm_msg_ctx *mctx = &mdl->mctx; |
| 614 | int format = lctx->format; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 615 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 616 | /* prepend l2 header */ |
| 617 | msg->l2h = msgb_push(msg, 3); |
| 618 | msg->l2h[0] = LAPDm_ADDR(lctx->lpd, lctx->sapi, lctx->cr); |
| 619 | /* EA is set here too */ |
| 620 | switch (format) { |
| 621 | case LAPD_FORM_I: |
| 622 | msg->l2h[1] = LAPDm_CTRL_I(lctx->n_recv, lctx->n_send, |
| 623 | lctx->p_f); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 624 | break; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 625 | case LAPD_FORM_S: |
| 626 | 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] | 627 | break; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 628 | case LAPD_FORM_U: |
| 629 | msg->l2h[1] = LAPDm_CTRL_U(lctx->s_u, lctx->p_f); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 630 | break; |
| 631 | default: |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 632 | msgb_free(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 633 | return -EINVAL; |
| 634 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 635 | msg->l2h[2] = LAPDm_LEN(l3_len); /* EL is set here too */ |
| 636 | if (lctx->more) |
| 637 | msg->l2h[2] |= LAPDm_MORE; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 638 | |
Andreas.Eversberg | f1f80de | 2011-11-06 20:45:29 +0100 | [diff] [blame] | 639 | /* add ACCH header with last indicated tx-power and TA */ |
| 640 | if ((mctx->link_id & 0x40)) { |
| 641 | struct lapdm_entity *le = mdl->entity; |
| 642 | |
| 643 | msg->l2h = msgb_push(msg, 2); |
| 644 | msg->l2h[0] = le->tx_power; |
| 645 | msg->l2h[1] = le->ta; |
| 646 | } |
| 647 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 648 | return tx_ph_data_enqueue(mctx->dl, msg, mctx->chan_nr, mctx->link_id, |
| 649 | 23); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 650 | } |
| 651 | |
Daniel Willmann | 3dc4e16 | 2014-03-20 19:24:48 +0100 | [diff] [blame] | 652 | static int update_pending_frames(struct lapd_msg_ctx *lctx) |
| 653 | { |
| 654 | struct lapd_datalink *dl = lctx->dl; |
| 655 | struct msgb *msg; |
| 656 | int rc = -1; |
| 657 | |
| 658 | llist_for_each_entry(msg, &dl->tx_queue, list) { |
| 659 | if (LAPDm_CTRL_is_I(msg->l2h[1])) { |
| 660 | msg->l2h[1] = LAPDm_CTRL_I(dl->v_recv, LAPDm_CTRL_I_Ns(msg->l2h[1]), |
| 661 | LAPDm_CTRL_PF_BIT(msg->l2h[1])); |
| 662 | rc = 0; |
| 663 | } else if (LAPDm_CTRL_is_S(msg->l2h[1])) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 664 | 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] | 665 | } |
| 666 | } |
| 667 | |
| 668 | return rc; |
| 669 | } |
| 670 | |
Harald Welte | 1284c3e | 2018-05-01 18:11:02 +0200 | [diff] [blame] | 671 | /* determine if receiving a given LAPDm message is not permitted */ |
| 672 | static int lapdm_rx_not_permitted(const struct lapdm_entity *le, |
| 673 | const struct lapd_msg_ctx *lctx) |
| 674 | { |
| 675 | /* we currently only implement SABM related checks here */ |
| 676 | if (lctx->format != LAPD_FORM_U || lctx->s_u != LAPD_U_SABM) |
| 677 | return 0; |
| 678 | |
| 679 | if (le->mode == LAPDM_MODE_BTS) { |
| 680 | if (le == &le->lapdm_ch->lapdm_acch) { |
| 681 | /* no contention resolution on SACCH */ |
| 682 | if (lctx->length > 0) |
| 683 | return RLL_CAUSE_SABM_INFO_NOTALL; |
| 684 | } else { |
| 685 | switch (lctx->sapi) { |
Harald Welte | 1284c3e | 2018-05-01 18:11:02 +0200 | [diff] [blame] | 686 | case 3: |
| 687 | /* SAPI3 doesn't support contention resolution */ |
| 688 | if (lctx->length > 0) |
| 689 | return RLL_CAUSE_SABM_INFO_NOTALL; |
| 690 | break; |
Harald Welte | b82a407 | 2018-05-09 16:31:16 +0200 | [diff] [blame] | 691 | default: |
| 692 | break; |
Harald Welte | 1284c3e | 2018-05-01 18:11:02 +0200 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | } else if (le->mode == LAPDM_MODE_MS) { |
| 696 | /* contention resolution (L3 present) is only sent by MS, but |
| 697 | * never received by it */ |
| 698 | if (lctx->length > 0) |
| 699 | return RLL_CAUSE_SABM_INFO_NOTALL; |
| 700 | } |
| 701 | return 0; |
| 702 | } |
| 703 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 704 | /* input into layer2 (from layer 1) */ |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 705 | static int l2_ph_data_ind(struct msgb *msg, struct lapdm_entity *le, |
| 706 | uint8_t chan_nr, uint8_t link_id) |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 707 | { |
| 708 | uint8_t cbits = chan_nr >> 3; |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 709 | 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] | 710 | struct lapdm_msg_ctx mctx; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 711 | struct lapd_msg_ctx lctx; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 712 | int rc = 0; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 713 | int n201; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 714 | |
| 715 | /* when we reach here, we have a msgb with l2h pointing to the raw |
| 716 | * 23byte mac block. The l1h has already been purged. */ |
| 717 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 718 | memset(&mctx, 0, sizeof(mctx)); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 719 | mctx.chan_nr = chan_nr; |
| 720 | mctx.link_id = link_id; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 721 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 722 | /* check for L1 chan_nr/link_id and determine LAPDm hdr format */ |
| 723 | if (cbits == 0x10 || cbits == 0x12) { |
| 724 | /* Format Bbis is used on BCCH and CCCH(PCH, NCH and AGCH) */ |
| 725 | mctx.lapdm_fmt = LAPDm_FMT_Bbis; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 726 | n201 = N201_Bbis; |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 727 | sapi = 0; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 728 | } else { |
| 729 | if (mctx.link_id & 0x40) { |
Harald Welte | 7ca604b | 2011-06-29 12:13:51 +0200 | [diff] [blame] | 730 | /* It was received from network on SACCH */ |
| 731 | |
Andreas.Eversberg | 816e178 | 2011-11-06 20:46:30 +0100 | [diff] [blame] | 732 | /* If UI on SACCH sent by BTS, lapdm_fmt must be B4 */ |
| 733 | if (le->mode == LAPDM_MODE_MS |
| 734 | && LAPDm_CTRL_is_U(msg->l2h[3]) |
| 735 | && LAPDm_CTRL_U_BITS(msg->l2h[3]) == 0) { |
Harald Welte | 7ca604b | 2011-06-29 12:13:51 +0200 | [diff] [blame] | 736 | mctx.lapdm_fmt = LAPDm_FMT_B4; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 737 | n201 = N201_B4; |
Harald Welte | 7ca604b | 2011-06-29 12:13:51 +0200 | [diff] [blame] | 738 | } else { |
| 739 | mctx.lapdm_fmt = LAPDm_FMT_B; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 740 | n201 = N201_AB_SACCH; |
Harald Welte | 7ca604b | 2011-06-29 12:13:51 +0200 | [diff] [blame] | 741 | } |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 742 | /* SACCH frames have a two-byte L1 header that |
| 743 | * OsmocomBB L1 doesn't strip */ |
| 744 | mctx.tx_power_ind = msg->l2h[0] & 0x1f; |
| 745 | mctx.ta_ind = msg->l2h[1]; |
| 746 | msgb_pull(msg, 2); |
| 747 | msg->l2h += 2; |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 748 | sapi = (msg->l2h[0] >> 2) & 7; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 749 | } else { |
| 750 | mctx.lapdm_fmt = LAPDm_FMT_B; |
Andreas.Eversberg | cbed327 | 2011-11-06 20:43:08 +0100 | [diff] [blame] | 751 | n201 = N201_AB_SDCCH; |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 752 | sapi = (msg->l2h[0] >> 2) & 7; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
Daniel Willmann | 55405fb | 2014-03-26 13:45:17 +0100 | [diff] [blame] | 756 | mctx.dl = lapdm_datalink_for_sapi(le, sapi); |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 757 | /* G.2.1 No action on frames containing an unallocated SAPI. */ |
| 758 | if (!mctx.dl) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 759 | LOGP(DLLAPD, LOGL_NOTICE, "Received frame for unsupported SAPI %d!\n", sapi); |
Harald Welte | 6420774 | 2011-06-27 23:32:14 +0200 | [diff] [blame] | 760 | msgb_free(msg); |
| 761 | return -EIO; |
| 762 | } |
| 763 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 764 | switch (mctx.lapdm_fmt) { |
| 765 | case LAPDm_FMT_A: |
| 766 | case LAPDm_FMT_B: |
| 767 | case LAPDm_FMT_B4: |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 768 | lctx.dl = &mctx.dl->dl; |
| 769 | /* obtain SAPI from address field */ |
| 770 | mctx.link_id |= LAPDm_ADDR_SAPI(msg->l2h[0]); |
| 771 | /* G.2.3 EA bit set to "0" is not allowed in GSM */ |
| 772 | if (!LAPDm_ADDR_EA(msg->l2h[0])) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 773 | 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] | 774 | msgb_free(msg); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 775 | rsl_rll_error(RLL_CAUSE_FRM_UNIMPL, &mctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 776 | return -EINVAL; |
| 777 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 778 | /* adress field */ |
| 779 | lctx.lpd = LAPDm_ADDR_LPD(msg->l2h[0]); |
| 780 | lctx.sapi = LAPDm_ADDR_SAPI(msg->l2h[0]); |
| 781 | lctx.cr = LAPDm_ADDR_CR(msg->l2h[0]); |
| 782 | /* command field */ |
| 783 | if (LAPDm_CTRL_is_I(msg->l2h[1])) { |
| 784 | lctx.format = LAPD_FORM_I; |
| 785 | lctx.n_send = LAPDm_CTRL_I_Ns(msg->l2h[1]); |
| 786 | lctx.n_recv = LAPDm_CTRL_Nr(msg->l2h[1]); |
| 787 | } else if (LAPDm_CTRL_is_S(msg->l2h[1])) { |
| 788 | lctx.format = LAPD_FORM_S; |
| 789 | lctx.n_recv = LAPDm_CTRL_Nr(msg->l2h[1]); |
| 790 | lctx.s_u = LAPDm_CTRL_S_BITS(msg->l2h[1]); |
| 791 | } else if (LAPDm_CTRL_is_U(msg->l2h[1])) { |
| 792 | lctx.format = LAPD_FORM_U; |
| 793 | lctx.s_u = LAPDm_CTRL_U_BITS(msg->l2h[1]); |
| 794 | } else |
| 795 | lctx.format = LAPD_FORM_UKN; |
| 796 | lctx.p_f = LAPDm_CTRL_PF_BIT(msg->l2h[1]); |
| 797 | if (lctx.sapi != LAPDm_SAPI_NORMAL |
| 798 | && lctx.sapi != LAPDm_SAPI_SMS |
| 799 | && lctx.format == LAPD_FORM_U |
| 800 | && lctx.s_u == LAPDm_U_UI) { |
| 801 | /* 5.3.3 UI frames with invalid SAPI values shall be |
| 802 | * discarded |
| 803 | */ |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 804 | LOGDL(lctx.dl, LOGL_INFO, "sapi=%u (discarding)\n", lctx.sapi); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 805 | msgb_free(msg); |
| 806 | return 0; |
| 807 | } |
| 808 | if (mctx.lapdm_fmt == LAPDm_FMT_B4) { |
| 809 | lctx.n201 = n201; |
| 810 | lctx.length = n201; |
| 811 | lctx.more = 0; |
| 812 | msg->l3h = msg->l2h + 2; |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 813 | msgb_pull_to_l3(msg); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 814 | } else { |
| 815 | /* length field */ |
| 816 | if (!(msg->l2h[2] & LAPDm_EL)) { |
| 817 | /* G.4.1 If the EL bit is set to "0", an |
| 818 | * MDL-ERROR-INDICATION primitive with cause |
| 819 | * "frame not implemented" is sent to the |
| 820 | * mobile management entity. */ |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 821 | LOGDL(lctx.dl, LOGL_NOTICE, "we don't support multi-octet length\n"); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 822 | msgb_free(msg); |
| 823 | rsl_rll_error(RLL_CAUSE_FRM_UNIMPL, &mctx); |
| 824 | return -EINVAL; |
| 825 | } |
| 826 | lctx.n201 = n201; |
| 827 | lctx.length = msg->l2h[2] >> 2; |
| 828 | lctx.more = !!(msg->l2h[2] & LAPDm_MORE); |
| 829 | msg->l3h = msg->l2h + 3; |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 830 | msgb_pull_to_l3(msg); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 831 | } |
| 832 | /* store context for messages from lapd */ |
| 833 | memcpy(&mctx.dl->mctx, &mctx, sizeof(mctx.dl->mctx)); |
Harald Welte | 1284c3e | 2018-05-01 18:11:02 +0200 | [diff] [blame] | 834 | rc =lapdm_rx_not_permitted(le, &lctx); |
| 835 | if (rc > 0) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 836 | LOGDL(lctx.dl, LOGL_NOTICE, "received message not permitted\n"); |
Harald Welte | 1284c3e | 2018-05-01 18:11:02 +0200 | [diff] [blame] | 837 | msgb_free(msg); |
| 838 | rsl_rll_error(rc, &mctx); |
| 839 | return -EINVAL; |
| 840 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 841 | /* send to LAPD */ |
| 842 | rc = lapd_ph_data_ind(msg, &lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 843 | break; |
| 844 | case LAPDm_FMT_Bter: |
| 845 | /* FIXME */ |
| 846 | msgb_free(msg); |
| 847 | break; |
| 848 | case LAPDm_FMT_Bbis: |
| 849 | /* directly pass up to layer3 */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 850 | msg->l3h = msg->l2h; |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 851 | msgb_pull_to_l3(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 852 | rc = send_rslms_rll_l3(RSL_MT_UNIT_DATA_IND, &mctx, msg); |
| 853 | break; |
| 854 | default: |
| 855 | msgb_free(msg); |
| 856 | } |
| 857 | |
| 858 | return rc; |
| 859 | } |
| 860 | |
| 861 | /* input into layer2 (from layer 1) */ |
| 862 | static int l2_ph_rach_ind(struct lapdm_entity *le, uint8_t ra, uint32_t fn, uint8_t acc_delay) |
| 863 | { |
| 864 | struct abis_rsl_cchan_hdr *ch; |
| 865 | struct gsm48_req_ref req_ref; |
| 866 | struct gsm_time gt; |
| 867 | struct msgb *msg = msgb_alloc_headroom(512, 64, "RSL CHAN RQD"); |
| 868 | |
Jacob Erlbeck | d154f8b | 2015-04-09 14:22:21 +0200 | [diff] [blame] | 869 | if (!msg) |
| 870 | return -ENOMEM; |
| 871 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 872 | msg->l2h = msgb_push(msg, sizeof(*ch)); |
| 873 | ch = (struct abis_rsl_cchan_hdr *)msg->l2h; |
| 874 | rsl_init_cchan_hdr(ch, RSL_MT_CHAN_RQD); |
| 875 | ch->chan_nr = RSL_CHAN_RACH; |
| 876 | |
| 877 | /* generate a RSL CHANNEL REQUIRED message */ |
| 878 | gsm_fn2gsmtime(>, fn); |
| 879 | req_ref.ra = ra; |
| 880 | req_ref.t1 = gt.t1; /* FIXME: modulo? */ |
| 881 | req_ref.t2 = gt.t2; |
| 882 | req_ref.t3_low = gt.t3 & 7; |
| 883 | req_ref.t3_high = gt.t3 >> 3; |
| 884 | |
| 885 | msgb_tv_fixed_put(msg, RSL_IE_REQ_REFERENCE, 3, (uint8_t *) &req_ref); |
| 886 | msgb_tv_put(msg, RSL_IE_ACCESS_DELAY, acc_delay); |
| 887 | |
| 888 | return rslms_sendmsg(msg, le); |
| 889 | } |
| 890 | |
| 891 | static int l2_ph_chan_conf(struct msgb *msg, struct lapdm_entity *le, uint32_t frame_nr); |
| 892 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 893 | /*! Receive a PH-SAP primitive from L1 */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 894 | int lapdm_phsap_up(struct osmo_prim_hdr *oph, struct lapdm_entity *le) |
| 895 | { |
| 896 | struct osmo_phsap_prim *pp = (struct osmo_phsap_prim *) oph; |
| 897 | int rc = 0; |
| 898 | |
| 899 | if (oph->sap != SAP_GSM_PH) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 900 | LOGP(DLLAPD, LOGL_ERROR, "primitive for unknown SAP %u\n", |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 901 | oph->sap); |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 902 | rc = -ENODEV; |
| 903 | goto free; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | switch (oph->primitive) { |
| 907 | case PRIM_PH_DATA: |
| 908 | if (oph->operation != PRIM_OP_INDICATION) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 909 | LOGP(DLLAPD, LOGL_ERROR, "PH_DATA is not INDICATION %u\n", |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 910 | oph->operation); |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 911 | rc = -ENODEV; |
| 912 | goto free; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 913 | } |
| 914 | rc = l2_ph_data_ind(oph->msg, le, pp->u.data.chan_nr, |
| 915 | pp->u.data.link_id); |
| 916 | break; |
| 917 | case PRIM_PH_RTS: |
| 918 | if (oph->operation != PRIM_OP_INDICATION) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 919 | LOGP(DLLAPD, LOGL_ERROR, "PH_RTS is not INDICATION %u\n", |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 920 | oph->operation); |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 921 | rc = -ENODEV; |
| 922 | goto free; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 923 | } |
| 924 | rc = l2_ph_data_conf(oph->msg, le); |
| 925 | break; |
| 926 | case PRIM_PH_RACH: |
| 927 | switch (oph->operation) { |
| 928 | case PRIM_OP_INDICATION: |
| 929 | rc = l2_ph_rach_ind(le, pp->u.rach_ind.ra, pp->u.rach_ind.fn, |
| 930 | pp->u.rach_ind.acc_delay); |
| 931 | break; |
| 932 | case PRIM_OP_CONFIRM: |
| 933 | rc = l2_ph_chan_conf(oph->msg, le, pp->u.rach_ind.fn); |
| 934 | break; |
| 935 | default: |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 936 | rc = -EIO; |
| 937 | goto free; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 938 | } |
| 939 | break; |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 940 | default: |
| 941 | LOGP(DLLAPD, LOGL_ERROR, "Unknown primitive %u\n", |
| 942 | oph->primitive); |
| 943 | rc = -EINVAL; |
| 944 | goto free; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | return rc; |
Andreas Eversberg | b36ad2d | 2013-02-05 12:01:32 +0100 | [diff] [blame] | 948 | |
| 949 | free: |
| 950 | msgb_free(oph->msg); |
| 951 | return rc; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | |
| 955 | /* L3 -> L2 / RSLMS -> LAPDm */ |
| 956 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 957 | /* Set LAPDm context for established connection */ |
| 958 | static int set_lapdm_context(struct lapdm_datalink *dl, uint8_t chan_nr, |
| 959 | uint8_t link_id, int n201, uint8_t sapi) |
| 960 | { |
| 961 | memset(&dl->mctx, 0, sizeof(dl->mctx)); |
| 962 | dl->mctx.dl = dl; |
| 963 | dl->mctx.chan_nr = chan_nr; |
| 964 | dl->mctx.link_id = link_id; |
| 965 | dl->dl.lctx.dl = &dl->dl; |
| 966 | dl->dl.lctx.n201 = n201; |
| 967 | dl->dl.lctx.sapi = sapi; |
| 968 | |
| 969 | return 0; |
| 970 | } |
| 971 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 972 | /* L3 requests establishment of data link */ |
| 973 | static int rslms_rx_rll_est_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 974 | { |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 975 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 976 | uint8_t chan_nr = rllh->chan_nr; |
| 977 | uint8_t link_id = rllh->link_id; |
| 978 | uint8_t sapi = rllh->link_id & 7; |
| 979 | struct tlv_parsed tv; |
| 980 | uint8_t length; |
Andreas.Eversberg | cbed327 | 2011-11-06 20:43:08 +0100 | [diff] [blame] | 981 | uint8_t n201 = (rllh->link_id & 0x40) ? N201_AB_SACCH : N201_AB_SDCCH; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 982 | struct osmo_dlsap_prim dp; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 983 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 984 | /* Set LAPDm context for established connection */ |
| 985 | set_lapdm_context(dl, chan_nr, link_id, n201, sapi); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 986 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 987 | rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg) - sizeof(*rllh)); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 988 | if (TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 989 | msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 990 | /* contention resolution establishment procedure */ |
| 991 | if (sapi != 0) { |
| 992 | /* According to clause 6, the contention resolution |
| 993 | * procedure is only permitted with SAPI value 0 */ |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 994 | LOGDL(&dl->dl, LOGL_ERROR, "SAPI != 0 but contention" |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 995 | "resolution (discarding)\n"); |
| 996 | msgb_free(msg); |
| 997 | return send_rll_simple(RSL_MT_REL_IND, &dl->mctx); |
| 998 | } |
| 999 | /* transmit a SABM command with the P bit set to "1". The SABM |
| 1000 | * command shall contain the layer 3 message unit */ |
| 1001 | length = TLVP_LEN(&tv, RSL_IE_L3_INFO); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1002 | } else { |
| 1003 | /* normal establishment procedure */ |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1004 | msg->l3h = msg->l2h + sizeof(*rllh); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1005 | length = 0; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /* check if the layer3 message length exceeds N201 */ |
Andreas.Eversberg | cbed327 | 2011-11-06 20:43:08 +0100 | [diff] [blame] | 1009 | if (length > n201) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1010 | LOGDL(&dl->dl, LOGL_ERROR, "frame too large: %d > N201(%d) " |
Andreas.Eversberg | cbed327 | 2011-11-06 20:43:08 +0100 | [diff] [blame] | 1011 | "(discarding)\n", length, n201); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1012 | msgb_free(msg); |
| 1013 | return send_rll_simple(RSL_MT_REL_IND, &dl->mctx); |
| 1014 | } |
| 1015 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1016 | /* Remove RLL header from msgb and set length to L3-info */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1017 | msgb_pull_to_l3(msg); |
| 1018 | msgb_trim(msg, length); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1019 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1020 | /* prepare prim */ |
| 1021 | 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] | 1022 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1023 | /* send to L2 */ |
| 1024 | return lapd_recv_dlsap(&dp, &dl->dl.lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /* L3 requests transfer of unnumbered information */ |
| 1028 | static int rslms_rx_rll_udata_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 1029 | { |
Andreas.Eversberg | 816e178 | 2011-11-06 20:46:30 +0100 | [diff] [blame] | 1030 | struct lapdm_entity *le = dl->entity; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1031 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 1032 | uint8_t chan_nr = rllh->chan_nr; |
| 1033 | uint8_t link_id = rllh->link_id; |
| 1034 | uint8_t sapi = link_id & 7; |
| 1035 | struct tlv_parsed tv; |
Max | 777be2e | 2017-03-01 18:16:44 +0100 | [diff] [blame] | 1036 | int length, ui_bts; |
| 1037 | |
| 1038 | if (!le) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1039 | LOGDL(&dl->dl, LOGL_ERROR, "lapdm_datalink without entity error\n"); |
Max | 777be2e | 2017-03-01 18:16:44 +0100 | [diff] [blame] | 1040 | msgb_free(msg); |
| 1041 | return -EMLINK; |
| 1042 | } |
| 1043 | ui_bts = (le->mode == LAPDM_MODE_BTS && (link_id & 0x40)); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1044 | |
| 1045 | /* check if the layer3 message length exceeds N201 */ |
| 1046 | |
| 1047 | rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh)); |
| 1048 | |
| 1049 | if (TLVP_PRESENT(&tv, RSL_IE_TIMING_ADVANCE)) { |
Andreas.Eversberg | f1f80de | 2011-11-06 20:45:29 +0100 | [diff] [blame] | 1050 | le->ta = *TLVP_VAL(&tv, RSL_IE_TIMING_ADVANCE); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1051 | } |
| 1052 | if (TLVP_PRESENT(&tv, RSL_IE_MS_POWER)) { |
Andreas.Eversberg | f1f80de | 2011-11-06 20:45:29 +0100 | [diff] [blame] | 1053 | le->tx_power = *TLVP_VAL(&tv, RSL_IE_MS_POWER); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1054 | } |
| 1055 | if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1056 | LOGDL(&dl->dl, LOGL_ERROR, "unit data request without message error\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1057 | msgb_free(msg); |
| 1058 | return -EINVAL; |
| 1059 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1060 | msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1061 | length = TLVP_LEN(&tv, RSL_IE_L3_INFO); |
| 1062 | /* check if the layer3 message length exceeds N201 */ |
Andreas Eversberg | 5977db0 | 2013-06-12 09:34:51 +0200 | [diff] [blame] | 1063 | if (length + ((link_id & 0x40) ? 4 : 2) + !ui_bts > 23) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1064 | LOGDL(&dl->dl, LOGL_ERROR, "frame too large: %d > N201(%d) " |
Andreas Eversberg | 5977db0 | 2013-06-12 09:34:51 +0200 | [diff] [blame] | 1065 | "(discarding)\n", length, |
| 1066 | ((link_id & 0x40) ? 18 : 20) + ui_bts); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1067 | msgb_free(msg); |
| 1068 | return -EIO; |
| 1069 | } |
| 1070 | |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1071 | 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] | 1072 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1073 | /* Remove RLL header from msgb and set length to L3-info */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1074 | msgb_pull_to_l3(msg); |
| 1075 | msgb_trim(msg, length); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1076 | |
| 1077 | /* Push L1 + LAPDm header on msgb */ |
Andreas Eversberg | 5977db0 | 2013-06-12 09:34:51 +0200 | [diff] [blame] | 1078 | msg->l2h = msgb_push(msg, 2 + !ui_bts); |
| 1079 | msg->l2h[0] = LAPDm_ADDR(LAPDm_LPD_NORMAL, sapi, dl->dl.cr.loc2rem.cmd); |
| 1080 | msg->l2h[1] = LAPDm_CTRL_U(LAPDm_U_UI, 0); |
Andreas.Eversberg | 816e178 | 2011-11-06 20:46:30 +0100 | [diff] [blame] | 1081 | if (!ui_bts) |
Andreas Eversberg | 5977db0 | 2013-06-12 09:34:51 +0200 | [diff] [blame] | 1082 | msg->l2h[2] = LAPDm_LEN(length); |
| 1083 | if (link_id & 0x40) { |
| 1084 | msg->l2h = msgb_push(msg, 2); |
| 1085 | msg->l2h[0] = le->tx_power; |
| 1086 | msg->l2h[1] = le->ta; |
| 1087 | } |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1088 | |
| 1089 | /* Tramsmit */ |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1090 | return tx_ph_data_enqueue(dl, msg, chan_nr, link_id, 23); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | /* L3 requests transfer of acknowledged information */ |
| 1094 | static int rslms_rx_rll_data_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 1095 | { |
| 1096 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 1097 | struct tlv_parsed tv; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1098 | int length; |
| 1099 | struct osmo_dlsap_prim dp; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1100 | |
| 1101 | rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh)); |
| 1102 | if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1103 | LOGDL(&dl->dl, LOGL_ERROR, "data request without message error\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1104 | msgb_free(msg); |
| 1105 | return -EINVAL; |
| 1106 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1107 | msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO); |
| 1108 | length = TLVP_LEN(&tv, RSL_IE_L3_INFO); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1109 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1110 | /* Remove RLL header from msgb and set length to L3-info */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1111 | msgb_pull_to_l3(msg); |
| 1112 | msgb_trim(msg, length); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1113 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1114 | /* prepare prim */ |
| 1115 | 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] | 1116 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1117 | /* send to L2 */ |
| 1118 | return lapd_recv_dlsap(&dp, &dl->dl.lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | /* L3 requests suspension of data link */ |
| 1122 | static int rslms_rx_rll_susp_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 1123 | { |
| 1124 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 1125 | uint8_t sapi = rllh->link_id & 7; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1126 | struct osmo_dlsap_prim dp; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1127 | |
| 1128 | if (sapi != 0) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1129 | LOGDL(&dl->dl, LOGL_ERROR, "SAPI != 0 while suspending\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1130 | msgb_free(msg); |
| 1131 | return -EINVAL; |
| 1132 | } |
| 1133 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1134 | /* prepare prim */ |
| 1135 | 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] | 1136 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1137 | /* send to L2 */ |
| 1138 | return lapd_recv_dlsap(&dp, &dl->dl.lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /* L3 requests resume of data link */ |
| 1142 | static int rslms_rx_rll_res_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 1143 | { |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1144 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1145 | int msg_type = rllh->c.msg_type; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1146 | uint8_t chan_nr = rllh->chan_nr; |
| 1147 | uint8_t link_id = rllh->link_id; |
| 1148 | uint8_t sapi = rllh->link_id & 7; |
| 1149 | struct tlv_parsed tv; |
| 1150 | uint8_t length; |
Andreas.Eversberg | cbed327 | 2011-11-06 20:43:08 +0100 | [diff] [blame] | 1151 | uint8_t n201 = (rllh->link_id & 0x40) ? N201_AB_SACCH : N201_AB_SDCCH; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1152 | struct osmo_dlsap_prim dp; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1153 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1154 | /* Set LAPDm context for established connection */ |
| 1155 | set_lapdm_context(dl, chan_nr, link_id, n201, sapi); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1156 | |
| 1157 | rsl_tlv_parse(&tv, rllh->data, msgb_l2len(msg)-sizeof(*rllh)); |
| 1158 | if (!TLVP_PRESENT(&tv, RSL_IE_L3_INFO)) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1159 | LOGDL(&dl->dl, LOGL_ERROR, "resume without message error\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1160 | msgb_free(msg); |
| 1161 | return send_rll_simple(RSL_MT_REL_IND, &dl->mctx); |
| 1162 | } |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1163 | msg->l3h = (uint8_t *) TLVP_VAL(&tv, RSL_IE_L3_INFO); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1164 | length = TLVP_LEN(&tv, RSL_IE_L3_INFO); |
| 1165 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1166 | /* Remove RLL header from msgb and set length to L3-info */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1167 | msgb_pull_to_l3(msg); |
| 1168 | msgb_trim(msg, length); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1169 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1170 | /* prepare prim */ |
| 1171 | osmo_prim_init(&dp.oph, 0, (msg_type == RSL_MT_RES_REQ) ? PRIM_DL_RES |
| 1172 | : PRIM_DL_RECON, PRIM_OP_REQUEST, msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1173 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1174 | /* send to L2 */ |
| 1175 | return lapd_recv_dlsap(&dp, &dl->dl.lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | /* L3 requests release of data link */ |
| 1179 | static int rslms_rx_rll_rel_req(struct msgb *msg, struct lapdm_datalink *dl) |
| 1180 | { |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1181 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1182 | uint8_t mode = 0; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1183 | struct osmo_dlsap_prim dp; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1184 | |
| 1185 | /* get release mode */ |
| 1186 | if (rllh->data[0] == RSL_IE_RELEASE_MODE) |
| 1187 | mode = rllh->data[1] & 1; |
| 1188 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1189 | /* Pull rllh */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1190 | msgb_pull_to_l3(msg); |
Harald Welte | 973c3c3 | 2012-04-26 21:50:54 +0200 | [diff] [blame] | 1191 | |
| 1192 | /* 04.06 3.8.3: No information field is permitted with the DISC |
| 1193 | * command. */ |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1194 | msgb_trim(msg, 0); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1195 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1196 | /* prepare prim */ |
| 1197 | osmo_prim_init(&dp.oph, 0, PRIM_DL_REL, PRIM_OP_REQUEST, msg); |
| 1198 | dp.u.rel_req.mode = mode; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1199 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1200 | /* send to L2 */ |
| 1201 | return lapd_recv_dlsap(&dp, &dl->dl.lctx); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /* L3 requests channel in idle state */ |
| 1205 | static int rslms_rx_chan_rqd(struct lapdm_channel *lc, struct msgb *msg) |
| 1206 | { |
| 1207 | struct abis_rsl_cchan_hdr *cch = msgb_l2(msg); |
| 1208 | void *l1ctx = lc->lapdm_dcch.l1_ctx; |
| 1209 | struct osmo_phsap_prim pp; |
| 1210 | |
| 1211 | osmo_prim_init(&pp.oph, SAP_GSM_PH, PRIM_PH_RACH, |
| 1212 | PRIM_OP_REQUEST, NULL); |
| 1213 | |
| 1214 | if (msgb_l2len(msg) < sizeof(*cch) + 4 + 2 + 2) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1215 | LOGP(DLLAPD, LOGL_ERROR, "Message too short for CHAN RQD!\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1216 | return -EINVAL; |
| 1217 | } |
| 1218 | if (cch->data[0] != RSL_IE_REQ_REFERENCE) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1219 | LOGP(DLLAPD, LOGL_ERROR, "Missing REQ REFERENCE IE\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1220 | return -EINVAL; |
| 1221 | } |
| 1222 | pp.u.rach_req.ra = cch->data[1]; |
| 1223 | pp.u.rach_req.offset = ((cch->data[2] & 0x7f) << 8) | cch->data[3]; |
| 1224 | pp.u.rach_req.is_combined_ccch = cch->data[2] >> 7; |
| 1225 | |
| 1226 | if (cch->data[4] != RSL_IE_ACCESS_DELAY) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1227 | LOGP(DLLAPD, LOGL_ERROR, "Missing ACCESS_DELAY IE\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1228 | return -EINVAL; |
| 1229 | } |
| 1230 | /* TA = 0 - delay */ |
| 1231 | pp.u.rach_req.ta = 0 - cch->data[5]; |
| 1232 | |
| 1233 | if (cch->data[6] != RSL_IE_MS_POWER) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1234 | LOGP(DLLAPD, LOGL_ERROR, "Missing MS POWER IE\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1235 | return -EINVAL; |
| 1236 | } |
| 1237 | pp.u.rach_req.tx_power = cch->data[7]; |
| 1238 | |
| 1239 | msgb_free(msg); |
| 1240 | |
| 1241 | return lc->lapdm_dcch.l1_prim_cb(&pp.oph, l1ctx); |
| 1242 | } |
| 1243 | |
| 1244 | /* L1 confirms channel request */ |
| 1245 | static int l2_ph_chan_conf(struct msgb *msg, struct lapdm_entity *le, uint32_t frame_nr) |
| 1246 | { |
| 1247 | struct abis_rsl_cchan_hdr *ch; |
| 1248 | struct gsm_time tm; |
| 1249 | struct gsm48_req_ref *ref; |
| 1250 | |
| 1251 | gsm_fn2gsmtime(&tm, frame_nr); |
| 1252 | |
Jacob Erlbeck | 8dac415 | 2014-01-28 11:03:11 +0100 | [diff] [blame] | 1253 | msgb_pull_to_l3(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1254 | msg->l2h = msgb_push(msg, sizeof(*ch) + sizeof(*ref)); |
| 1255 | ch = (struct abis_rsl_cchan_hdr *)msg->l2h; |
| 1256 | rsl_init_cchan_hdr(ch, RSL_MT_CHAN_CONF); |
| 1257 | ch->chan_nr = RSL_CHAN_RACH; |
| 1258 | ch->data[0] = RSL_IE_REQ_REFERENCE; |
| 1259 | ref = (struct gsm48_req_ref *) (ch->data + 1); |
| 1260 | ref->t1 = tm.t1; |
| 1261 | ref->t2 = tm.t2; |
| 1262 | ref->t3_low = tm.t3 & 0x7; |
| 1263 | ref->t3_high = tm.t3 >> 3; |
Pau Espin Pedrol | a99e110 | 2017-12-08 14:30:47 +0100 | [diff] [blame] | 1264 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1265 | return rslms_sendmsg(msg, le); |
| 1266 | } |
| 1267 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1268 | /* incoming RSLms RLL message from L3 */ |
| 1269 | static int rslms_rx_rll(struct msgb *msg, struct lapdm_channel *lc) |
| 1270 | { |
| 1271 | struct abis_rsl_rll_hdr *rllh = msgb_l2(msg); |
| 1272 | int msg_type = rllh->c.msg_type; |
| 1273 | uint8_t sapi = rllh->link_id & 7; |
| 1274 | struct lapdm_entity *le; |
| 1275 | struct lapdm_datalink *dl; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1276 | int rc = 0; |
| 1277 | |
| 1278 | if (msgb_l2len(msg) < sizeof(*rllh)) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1279 | LOGP(DLLAPD, LOGL_ERROR, "Message too short for RLL hdr!\n"); |
Andreas.Eversberg | a42b699 | 2011-11-06 20:31:47 +0100 | [diff] [blame] | 1280 | msgb_free(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1281 | return -EINVAL; |
| 1282 | } |
| 1283 | |
| 1284 | if (rllh->link_id & 0x40) |
| 1285 | le = &lc->lapdm_acch; |
| 1286 | else |
| 1287 | le = &lc->lapdm_dcch; |
| 1288 | |
Harald Welte | 1a87c1b | 2015-12-14 15:26:07 +0100 | [diff] [blame] | 1289 | /* 4.1.1.5 / 4.1.1.6 / 4.1.1.7 all only exist on MS side, not |
| 1290 | * BTS side */ |
| 1291 | if (le->mode == LAPDM_MODE_BTS) { |
| 1292 | switch (msg_type) { |
| 1293 | case RSL_MT_SUSP_REQ: |
| 1294 | case RSL_MT_RES_REQ: |
| 1295 | case RSL_MT_RECON_REQ: |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1296 | 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] | 1297 | lc->name, rsl_msg_name(msg_type)); |
| 1298 | msgb_free(msg); |
| 1299 | return -EINVAL; |
| 1300 | break; |
| 1301 | default: |
| 1302 | break; |
| 1303 | } |
| 1304 | } |
| 1305 | |
Holger Hans Peter Freyther | c620604 | 2014-01-23 15:00:55 +0100 | [diff] [blame] | 1306 | /* 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] | 1307 | * SAPI. |
| 1308 | */ |
Daniel Willmann | 55405fb | 2014-03-26 13:45:17 +0100 | [diff] [blame] | 1309 | dl = lapdm_datalink_for_sapi(le, sapi); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1310 | if (!dl) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1311 | LOGP(DLLAPD, LOGL_ERROR, "No instance for SAPI %d!\n", sapi); |
Andreas.Eversberg | a42b699 | 2011-11-06 20:31:47 +0100 | [diff] [blame] | 1312 | msgb_free(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1313 | return -EINVAL; |
| 1314 | } |
| 1315 | |
Daniel Willmann | e523392 | 2012-12-25 23:15:50 +0100 | [diff] [blame] | 1316 | switch (msg_type) { |
Daniel Willmann | e523392 | 2012-12-25 23:15:50 +0100 | [diff] [blame] | 1317 | case RSL_MT_DATA_REQ: |
| 1318 | case RSL_MT_SUSP_REQ: |
| 1319 | case RSL_MT_REL_REQ: |
| 1320 | /* This is triggered in abnormal error conditions where |
| 1321 | * set_lapdm_context() was not called for the channel earlier. */ |
| 1322 | if (!dl->dl.lctx.dl) { |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1323 | 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] | 1324 | lc->name, rsl_msg_name(msg_type), sapi); |
| 1325 | msgb_free(msg); |
| 1326 | return -EINVAL; |
| 1327 | } |
| 1328 | break; |
| 1329 | default: |
Harald Welte | 00b2faf | 2020-05-02 19:56:36 +0200 | [diff] [blame] | 1330 | LOGP(DLLAPD, LOGL_INFO, "(%s) RLL Message '%s' received. (sapi %d)\n", |
Daniel Willmann | e523392 | 2012-12-25 23:15:50 +0100 | [diff] [blame] | 1331 | lc->name, rsl_msg_name(msg_type), sapi); |
| 1332 | } |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1333 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1334 | switch (msg_type) { |
| 1335 | case RSL_MT_UNIT_DATA_REQ: |
| 1336 | rc = rslms_rx_rll_udata_req(msg, dl); |
| 1337 | break; |
| 1338 | case RSL_MT_EST_REQ: |
| 1339 | rc = rslms_rx_rll_est_req(msg, dl); |
| 1340 | break; |
| 1341 | case RSL_MT_DATA_REQ: |
| 1342 | rc = rslms_rx_rll_data_req(msg, dl); |
| 1343 | break; |
| 1344 | case RSL_MT_SUSP_REQ: |
| 1345 | rc = rslms_rx_rll_susp_req(msg, dl); |
| 1346 | break; |
| 1347 | case RSL_MT_RES_REQ: |
| 1348 | rc = rslms_rx_rll_res_req(msg, dl); |
| 1349 | break; |
| 1350 | case RSL_MT_RECON_REQ: |
| 1351 | rc = rslms_rx_rll_res_req(msg, dl); |
| 1352 | break; |
| 1353 | case RSL_MT_REL_REQ: |
| 1354 | rc = rslms_rx_rll_rel_req(msg, dl); |
| 1355 | break; |
| 1356 | default: |
| 1357 | LOGP(DLLAPD, LOGL_NOTICE, "Message unsupported.\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1358 | msgb_free(msg); |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1359 | rc = -EINVAL; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1360 | } |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1361 | |
| 1362 | return rc; |
| 1363 | } |
| 1364 | |
| 1365 | /* incoming RSLms COMMON CHANNEL message from L3 */ |
| 1366 | static int rslms_rx_com_chan(struct msgb *msg, struct lapdm_channel *lc) |
| 1367 | { |
| 1368 | struct abis_rsl_cchan_hdr *cch = msgb_l2(msg); |
| 1369 | int msg_type = cch->c.msg_type; |
| 1370 | int rc = 0; |
| 1371 | |
| 1372 | if (msgb_l2len(msg) < sizeof(*cch)) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1373 | LOGP(DLLAPD, LOGL_ERROR, "Message too short for COM CHAN hdr!\n"); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1374 | return -EINVAL; |
| 1375 | } |
| 1376 | |
| 1377 | switch (msg_type) { |
| 1378 | case RSL_MT_CHAN_RQD: |
| 1379 | /* create and send RACH request */ |
| 1380 | rc = rslms_rx_chan_rqd(lc, msg); |
| 1381 | break; |
| 1382 | default: |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1383 | LOGP(DLLAPD, LOGL_NOTICE, "Unknown COMMON CHANNEL msg %d!\n", |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1384 | msg_type); |
| 1385 | msgb_free(msg); |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
| 1389 | return rc; |
| 1390 | } |
| 1391 | |
Harald Welte | 7023aa0 | 2019-05-19 12:17:06 +0200 | [diff] [blame] | 1392 | /*! Receive a RSLms \ref msgb from Layer 3. 'msg' ownership is transferred, |
| 1393 | * i.e. caller must not free it */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1394 | int lapdm_rslms_recvmsg(struct msgb *msg, struct lapdm_channel *lc) |
| 1395 | { |
| 1396 | struct abis_rsl_common_hdr *rslh = msgb_l2(msg); |
| 1397 | int rc = 0; |
| 1398 | |
| 1399 | if (msgb_l2len(msg) < sizeof(*rslh)) { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1400 | LOGP(DLLAPD, LOGL_ERROR, "Message too short RSL hdr!\n"); |
Harald Welte | 7023aa0 | 2019-05-19 12:17:06 +0200 | [diff] [blame] | 1401 | msgb_free(msg); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1402 | return -EINVAL; |
| 1403 | } |
| 1404 | |
| 1405 | switch (rslh->msg_discr & 0xfe) { |
| 1406 | case ABIS_RSL_MDISC_RLL: |
| 1407 | rc = rslms_rx_rll(msg, lc); |
| 1408 | break; |
| 1409 | case ABIS_RSL_MDISC_COM_CHAN: |
| 1410 | rc = rslms_rx_com_chan(msg, lc); |
| 1411 | break; |
| 1412 | default: |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1413 | LOGP(DLLAPD, LOGL_ERROR, "unknown RSLms message " |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1414 | "discriminator 0x%02x", rslh->msg_discr); |
| 1415 | msgb_free(msg); |
| 1416 | return -EINVAL; |
| 1417 | } |
| 1418 | |
| 1419 | return rc; |
| 1420 | } |
| 1421 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1422 | /*! Set the \ref lapdm_mode of a LAPDm entity */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1423 | int lapdm_entity_set_mode(struct lapdm_entity *le, enum lapdm_mode mode) |
| 1424 | { |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1425 | int i; |
| 1426 | enum lapd_mode lm; |
| 1427 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1428 | switch (mode) { |
| 1429 | case LAPDM_MODE_MS: |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1430 | lm = LAPD_MODE_USER; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1431 | break; |
| 1432 | case LAPDM_MODE_BTS: |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1433 | lm = LAPD_MODE_NETWORK; |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1434 | break; |
| 1435 | default: |
| 1436 | return -EINVAL; |
| 1437 | } |
| 1438 | |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1439 | for (i = 0; i < ARRAY_SIZE(le->datalink); i++) { |
| 1440 | lapd_set_mode(&le->datalink[i].dl, lm); |
| 1441 | } |
| 1442 | |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1443 | le->mode = mode; |
| 1444 | |
| 1445 | return 0; |
| 1446 | } |
| 1447 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1448 | /*! Set the \ref lapdm_mode of a LAPDm channel*/ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1449 | int lapdm_channel_set_mode(struct lapdm_channel *lc, enum lapdm_mode mode) |
| 1450 | { |
| 1451 | int rc; |
| 1452 | |
| 1453 | rc = lapdm_entity_set_mode(&lc->lapdm_dcch, mode); |
| 1454 | if (rc < 0) |
| 1455 | return rc; |
| 1456 | |
| 1457 | return lapdm_entity_set_mode(&lc->lapdm_acch, mode); |
| 1458 | } |
| 1459 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1460 | /*! Set the L1 callback and context of a LAPDm channel */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1461 | void lapdm_channel_set_l1(struct lapdm_channel *lc, osmo_prim_cb cb, void *ctx) |
| 1462 | { |
| 1463 | lc->lapdm_dcch.l1_prim_cb = cb; |
| 1464 | lc->lapdm_acch.l1_prim_cb = cb; |
| 1465 | lc->lapdm_dcch.l1_ctx = ctx; |
| 1466 | lc->lapdm_acch.l1_ctx = ctx; |
| 1467 | } |
| 1468 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1469 | /*! Set the L3 callback and context of a LAPDm channel */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1470 | void lapdm_channel_set_l3(struct lapdm_channel *lc, lapdm_cb_t cb, void *ctx) |
| 1471 | { |
| 1472 | lc->lapdm_dcch.l3_cb = cb; |
| 1473 | lc->lapdm_acch.l3_cb = cb; |
| 1474 | lc->lapdm_dcch.l3_ctx = ctx; |
| 1475 | lc->lapdm_acch.l3_ctx = ctx; |
| 1476 | } |
| 1477 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1478 | /*! Reset an entire LAPDm entity and all its datalinks */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1479 | void lapdm_entity_reset(struct lapdm_entity *le) |
| 1480 | { |
| 1481 | struct lapdm_datalink *dl; |
| 1482 | int i; |
| 1483 | |
| 1484 | for (i = 0; i < ARRAY_SIZE(le->datalink); i++) { |
| 1485 | dl = &le->datalink[i]; |
root | af48bed | 2011-09-26 11:23:06 +0200 | [diff] [blame] | 1486 | lapd_dl_reset(&dl->dl); |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1490 | /*! Reset a LAPDm channel with all its entities */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1491 | void lapdm_channel_reset(struct lapdm_channel *lc) |
| 1492 | { |
| 1493 | lapdm_entity_reset(&lc->lapdm_dcch); |
| 1494 | lapdm_entity_reset(&lc->lapdm_acch); |
| 1495 | } |
| 1496 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1497 | /*! Set the flags of a LAPDm entity */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1498 | void lapdm_entity_set_flags(struct lapdm_entity *le, unsigned int flags) |
| 1499 | { |
| 1500 | le->flags = flags; |
| 1501 | } |
| 1502 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 1503 | /*! Set the flags of all LAPDm entities in a LAPDm channel */ |
Harald Welte | 1f0b8c2 | 2011-06-27 10:51:37 +0200 | [diff] [blame] | 1504 | void lapdm_channel_set_flags(struct lapdm_channel *lc, unsigned int flags) |
| 1505 | { |
| 1506 | lapdm_entity_set_flags(&lc->lapdm_dcch, flags); |
| 1507 | lapdm_entity_set_flags(&lc->lapdm_acch, flags); |
| 1508 | } |
Harald Welte | 6bdf0b1 | 2011-08-17 18:22:08 +0200 | [diff] [blame] | 1509 | |
Sylvain Munaut | dca7d2c | 2012-04-18 21:53:23 +0200 | [diff] [blame] | 1510 | /*! @} */ |