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