Commit Graph

67 Commits

Author SHA1 Message Date
Andreas Eversberg 285f3693de Add flag to enable RTS based polling
RTS based polling in LAPDm code is disabled by default. Make libosmogsm
stay compatible with existing applications that do not use RTS based
polling.

This patch fixes the issue that LAPDM_ENT_F_POLLING_ONLY did enable RTS
based polling too, which breaks existing applications like older
versions of osmo-bts.

Change-Id: I2a75c192bbc24e85bfc1656b2be21cea7a92814a
2023-11-29 14:19:48 +01:00
Andreas Eversberg bd2b897b72 LAPDm: Add a flag to enable suppression of subsequent REJ frame
This behaviour was default in earlier versions of LAPDm/LAPD. Because it
is only required for osmocom-bb, a flag is added to enable it there.

Related: OS#5969
Change-Id: I93994dbbd1fc2c9edb8f3015c6b18ecd0fce0565
2023-11-27 16:25:53 +00:00
Andreas Eversberg f51f916e1c LAPDm: Add an extra queue for UI frames
The extra queue is used to transmit the UI frame only when there is no
frame in the regular TX queue. This allows to give LAPD frames prioity
over UI frame.

Related: OS#4074
Change-Id: I00c8ee73be8b7c564a4dee3fca3e893484f567da
2023-11-27 16:25:53 +00:00
Andreas Eversberg 2d7119d85b LAPDm: Add support for RTS based polling
The lower layer must set the 'POLLING_ONLY' flag and provide frame
number when polling a frame. If T200 is pending, it is started with a
timeout frame number in advance to given frame number.

The lower layer must call lapdm_t200_fn() after a frame has been
received or if a frame has not been received. Also it must be called
after a TCH frame has been received. LAPDm uses this to check the T200
timeout condition.

A new function is used to set the frame number based timeout values.

Related: OS#4074
Change-Id: I6ebe83f829d7751ea9de1d90eb478c7a628db64c
2023-11-27 16:25:53 +00:00
Andreas Eversberg 1bb0b99552 LAPD: Always update N(R) in pending TX frames if V(R) is incremented
The outcome of the update function is still used to indicate if an RR
frame must be sent or not. Only if there is no I frame in the TX queue,
RR frame must be sent.

Related: OS#4074
Change-Id: I71676c709878105bfd18b9370fecc61b92796a6f
2023-11-15 21:28:22 +00:00
Andreas Eversberg 16ad6c29fe LAPDM: Use correct offset to short header on recevied frame
The offset of the short header on main DCCH is 0, not 2.

Change-Id: I8345776768fdf2a700b2ca1d117f9ef4b15777cc
2023-09-12 10:42:48 +00:00
Pau Espin 45ab0d7335 lapdm: Update public lapdm_msg_ctx upon CCCH data ind
This allows uses accessing the updated fields such as fn from the l3_cb
when receiving a msg from CCCH, eg: "le->datalink[DL_SAPI0].mctx.fn;"

Related: OS#3626
Change-Id: Icabc3759c47b0f7cfe61f1b7a96f08f36714262e
2023-08-24 13:48:19 +00:00
Pau Espin 06da40bdb3 Revert "lapdm: Append RSL_IE_OSMO_ABS_FRAME_NUMBER to RSLms msgs towards upper layers"
This reverts commit d981794113.

osmo-bts is forwarding the msgbs as they come from lapdm to the RSL on
the wire, which means we end up sending the osmocom-specific IEs on the
wire, something which was not envisioned when adding this IE.

Change-Id: I0ab0d5b545b4862e72eb1842edd07ca2e4955311
Related: OS#6142
2023-08-23 17:13:34 +00:00
Pau Espin d981794113 lapdm: Append RSL_IE_OSMO_ABS_FRAME_NUMBER to RSLms msgs towards upper layers
This makes it possible to track GSM time in the upper layers.
The existing RSL_IE_FRAME_NUMBER and RSL_IE_STARTNG_TIME cannot be used
there, since those are 16bit fields containing Relative FN values.

The IE needs to be added before the L3_INFO one, because user code
usually assumes the msgb->l3 pointing to L3_INFO value extends until the
end of the message, using msgb3_len(msg). Regarding having an extra IE
at the middle, it's not a big problem since the libosmocore version
submitting this commit to the upper layers is the same which will also
be parsing it through rsl_tlv_parse() later on by the app.

Related: OS#3626
Change-Id: Id62c18f49f270449067b25b7104eb8b47f1955ec
2023-08-21 14:34:55 +00:00
Pau Espin 1247aa1fc0 lapdm: Track fn of primitives in struct lapdm_msg_ctx
This field will be used in follow-up commits to provide FN information
in RSLms primitives towars upper layers. This is needed for instance on
the MS side when a CCCH_DATA.ind is received containing a TBF ImmAss
with a relative FN indicating the Starting Time. Without tracking FN
advance, the uppers layers are not capable of figuring out the absolute
FN of the TBF Starting time.

The struct lapdm_msg_ctx is not really used outside of libosmocore, so
we are safe extending it.

Related: OS#3626
Change-Id: Icf986f4202703eb452bedc1b749bb8ce0c73706f
2023-08-11 17:37:07 +02:00
Vadim Yanitskiy 9ec7749f01 lapdm: cosmetic: simplify lapdm_phsap_up(), use OSMO_PRIM[_HDR]
Change-Id: I87dedca0a38f290ae56649373dc9172433b8e4b1
Related: OS#3626
2023-07-10 09:53:00 +00:00
Andreas Eversberg cb72e74031 lapdm: Do not return an error when enqueuing a frame
If tx_ph_data_enqueue() is called, frames will be written into a queue,
if there is a pending frame or if polling of TX frames is used. In
this case the return value must be 0.

Sending a RSL_MT_UNIT_DATA_REQ from upper layer causes a call to
tx_ph_data_enqueue(). The return code is returned to the sender. The
sender must not get an error returned, if the message is enqueued.

Change-Id: Iaeaf7c66cb3cf5cc81bc8e15d468e8e7704c1407
2023-06-09 15:06:34 +00:00
Andreas Eversberg 0370018eae Add support for receiving Bter UI frames at lapdm.c
Similar to support of sending Bter frame, the same rules apply when
receiving them.

Change-Id: If04115884743455c7bf2b2bc5f7e49e74b6ffb60
2023-06-09 15:06:34 +00:00
Andreas Eversberg 6799741699 Add support for sending Bter UI frames at lapdm.c
Bter frames may be used on downlink of a main DCCH or SACCH channel.
It applies to SAPI 0 and UI frames only. It includes a short layer 2
header with 2 bits only. All other bits are used for the message. The
message size is 23 bytes on main DCCH and 21 bytes on SACCH.
The length of the L3 messsage is used to distinguish between Bter frames
and other (UI) frames.

Note that the L3 message header is different, so that the length of the
UI frame will determine which header is used.

Change-Id: Ia3a25c009d1ff09f83258bdb226a85b81466d7a1
2023-06-09 15:06:34 +00:00
Vadim Yanitskiy 64277a0217 doxygen: fix various typos in commands \param and \returns
Change-Id: If87cec3739449c6a54e24fb2cb81e746d8244da2
2023-02-28 18:48:56 +00:00
Oliver Smith 04bfb7165b treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I5050285e75cf120407a1d883e99b3c4bcae8ffd7
2021-12-14 12:44:03 +01:00
Pau Espin 16333bb58c lapdm: Drop log lines printing fmt=B
Change-Id: Ic8794ee66ddeb45ebcc7b9834f4d5e8321fd91f1
2020-10-21 11:54:23 +00:00
Vadim Yanitskiy 776c5b16ea lapdm: fix SAPI-0/SAPI-3 frame prioritization on DCCH
According to 3GPP TS 44.005, section 4.2.2 "Priority":

  a) on DCCH, a SAPI=0 frame always has higher priority than SAPI=3;
  b) on ACCH, the priority arrangement is more complex:
    b1) if a SAPI = 3 frame is awaiting transmission, two SAPI=0
        frames shall not be sent in consecutive SACCH frames;
    b2) on the network side (LAPDM_MODE_BTS), it must also be ensured
        that any SAPI=3 frame is followed by at least one SAPI=0 frame;
    b3) a SAPI = 0 frame may be repeated in the next SACCH period
        if the Repeated SACCH is supported (see 3GPP TS 44.006, section 11).

We definitely need to extend our testing coverage to ensure that
we implement b) correctly, but for now let's focus on DCCH:

  a) for DCCH, ensure that SAPI=0 frames preceed SAPI=3 ones;
  b) for ACCH, re-use the existing round-robin implementation.

Change-Id: Ia3780bce1222b312ae2fd2d21496a4d6c5ccb6e0
Related: SYS#5047, OS#4731
2020-08-27 22:10:54 +07:00
Vadim Yanitskiy 29ecabe7a2 lapdm_pad_msgb(): cosmetic: use GSM_MACBLOCK_PADDING
Change-Id: Ic2ff931ea4272903c440c7c5ea996dd84c2e470b
2020-08-27 19:35:13 +07:00
Harald Welte 00b2faf821 lapd/lapdm: print user-defined string name instead of (dl=%p)
At the moment we print the pointer address to identify the log lines
belonging to a specific connection. Since pointer addresses are
difficult to work with, a human readable ID should be printed instead.

e.g. "This is LAPD instance for SAPI3 on bts0/trx1/ts5/lchan3"

Change-Id: Ie6742843fff809edffcac24c4dce4edf66bc71be
Closes: OS#1938
2020-06-08 21:16:54 +02:00
Harald Welte 20de6207c2 lapdm: Allow user to specify T200 values; Use correct N200 values
TS 04.06 specifies a N200 re-transmission counter that depends on the
channel type, which we didn't care about at all so far.  Let's have the
caller tell us the channel type so we can internally look up the correct
N200 value for it.

At the same time, permit the user to specify T200 re-transmission timer
values for each SAPI on both DCCH and ACCH, which is required at least
in the BTS as per GSM TS 12.21.  Also, extend the timer resolution of
the API from seconds to milli-seconds, which is more applicable as
particularly on the FACCH the recommended values are in the 200ms range.

Change-Id: I90fdc4dd4720d4e02213197c894eb0a55a39158c
Related: OS#3906
Related: OS#2294
Related: OS#4037
2019-06-05 10:01:20 +00:00
Harald Welte 2e78f900cf lapdm: Don't truncate L3 payload at 200 bytes length
3GPP TS 04.06 is quite clear that the [segmented] L3 payload can be as
long as 251 bytes.  Our libosmocore lapdm implementation truncated
already at 200 bytes :(

Change-Id: I6769986f27dda1d429ed7b2e32c36d34663acba9
Closes: OS#4035
2019-06-02 08:17:59 +00:00
Harald Welte 7023aa0af9 lapdm_rslms_recvmsg: Fix memory leak in error path
The caller of lapdm_rslms_recvmsg() (e.g. osmo-bts/src/common/rsl.c)
assumes the message ownership is transferred.  However, in one of the
two error paths, msgb_free() was not called and hence we had a memory
leak.

Also clarify the msgb ownership transfer in a comment.

Related: OS#3750
Change-Id: Id60cb45e50bfc89224d97df6c68fcd2949751895
2019-05-19 12:19:02 +02:00
Pau Espin 1eb270bda8 gsm: lapdm.c: Add missing new line char in notice log string
Change-Id: I92c78ea01570dc1f4be11b113c07f0aa3b342c8f
2018-06-18 19:23:11 +02:00
Harald Welte b82a407a49 lapdm: don't enforce contention resolution on SAPI0/DCCH
In Change-Id: I8c2c103cdc7f9a45d7b2080c572f559fc3db58e4 we introduced
a check to enforce contention resolution always being used in
MS-originated LAPDm establishment on the main DCCH / SAPI0.  This is
only required after RACH request (IMM.ASS.) and not after a normal
assignment command which was sent already via a dedicated channel.

Hence, we cannot enforce a strict requirement for contention resolution
in those cases.

We *could* use the RSL Channel Activation type as a constraint on
whether or not to enforce contention-resoluiton-only LAPDm
establishment, but this is out of the scope of the LAPDm code but would
have to be done inside OsmoBTS.

Related: OS#3252
Change-Id: Id903492ee90809fe98defcf4abc0419b8150069f
2018-05-09 16:33:42 +02:00
Harald Welte f1bdf781ac lapdm: send_rslms_rll_l3_ui(): Don't include B4/SACCH IE unless needed
The RSL_IE_MS_POWER / RSL_IE_TIMING_ADVANCE is how we communicate
the SACCH L1 header values on the MS side between LAPDm and L3 (which
is a non-standard use of RSL).

However, those IEs only maek sense on the SACCH, where we have B4 frame
format and where we actually have a L1 header containing related
information.  Let's make sure to skip those IEs on regular RLL UNIT DATA
INDICATION happening on other channel types.

Change-Id: I6f13e02192531479287f71de674d17ca2ceabdc6
Closes: OS#3249
2018-05-08 23:33:32 +02:00
Harald Welte d977f5fe08 lapdm: cleanup: send_rslms_rll_l3_ui(): Use msgb_tv_push()
This is a purely cosmetic clean-up to use the msgb_tv_push() API
to pre-pend a Tag-Value IE to a msgb, rather than the existing
open-coding approach.

Change-Id: I19bbfa1e327a617685ed11d4182e533df33215cb
2018-05-08 20:35:11 +00:00
Harald Welte 1284c3e961 lapdm: Implement SABM related constraints
* MO SAPI0 establishment *must always* have L3 payload for contention
  resolution
* SAPI3 establishment *must never* use contention resolution
* MT establish must never use contention resolution

Change-Id: I8c2c103cdc7f9a45d7b2080c572f559fc3db58e4
Closes: OS#2370
2018-05-08 18:53:38 +00:00
Harald Welte 3e8c520ad1 lapdm: Fix back-pointer from lapdm_entity to lapdm_channel
It seems that during all those years it has never been noted that
the back-pointer from the lapdm_entity to the lapdm_channel was
never initialized.  Let's fix that.

Change-Id: Iaca66cd6a2c9f315561e365b51163927868fc346
2018-05-04 20:59:46 +02:00
Harald Welte 542301b067 RSL/LAPDm: Not all RLL message are "transparent"
3GPP TS 48.058 has a very clear definition of which messages are
"transparent" and hence have the T-bit == 1.  This is *not* just
all RLL messages, but basically only RLL_DATA.{ind,req} and
RLL_UNITDATA.{ind,req}.  All other messages are non-transparent.

Change-Id: I9f83654af189d818563d799bf623325b7fee8e70
Closes: OS#3188
2018-04-19 15:09:32 +00:00
Pau Espin 9dd3bf0cb4 Fix malformed Abis/RSL messages with extra L3 Information field
Some Abis/RSL messages such as "Release Indication" contained 3 extra
bytes from an L3 Information header which should not be there according
to specs in GSM 08.58 (section 8.3 "Radio link layer management
messages"). Other RSL messages were affected by the same issue, except
for "Establish Indication", which had already a workaround in
send_rslms_dlsap.

This commit fixes the issue in a generic way, removes the "Establish
Indication" and fixes the test accounting for the bug, as it otherwise
fails after applying the changes.

Fixes: OS#1635, OS#2336

Change-Id: Ibb116214e8b1798d65a8b0917150496a3c14f344
2017-12-10 14:44:19 +00:00
Pau Espin a99e110106 cosmetic: Fix trailing whitespace
Change-Id: I0c7a414789f8ce6516369327430f71164e2cbd94
2017-12-10 14:07:54 +00:00
Harald Welte e08da97570 Fix/Update copyright notices; Add SPDX annotation
Let's fix some erroneous/accidential references to wrong license,
update copyright information where applicable and introduce a
SPDX-License-Identifier to all files.

Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
2017-11-13 01:35:12 +09:00
Neels Hofmeyr 17518fe393 doxygen: unify use of \file across the board
Considering the various styles and implications found in the sources, edit
scores of files to follow the same API doc guidelines around the doxygen
grouping and the \file tag.

Many files now show a short description in the generated API doc that was so
far only available as C comment.

The guidelines and reasoning behind it is documented at
https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation

In some instances, remove file comments and add to the corresponding group
instead, to be shared among several files (e.g. bitvec).

Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23 00:18:23 +00:00
Neels Hofmeyr 87e4550585 doxygen: enable AUTOBRIEF, drop \brief
Especially for short descriptions, it is annoying to have to type \brief for
every single API doc.

Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes
the first sentence of an API doc as the brief description.

Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
2017-06-23 00:18:22 +00:00
Harald Welte 96e2a00d7a update/extend doxygen documentation
It's a pity that even with this patch we still are fare away from having
the whole API documented.  However, at least we have a more solid
foundation.  Updates not only extend the documentation, but also make
sure it is rendered properly in the doxygen HTML.

Change-Id: I1344bd1a6869fb00de7c1899a8db93bba9bafce3
2017-06-12 21:55:54 +00:00
Harald Welte 95871dadbd use osmo_{htonl,htons,ntohl,ntohs}() functions all over libosmocore
This gets us one step closer to fixing the embedded build

Change-Id: I3fc2639b6ade9ab138766987eceab7ec9498fdc7
2017-05-15 13:42:03 +02:00
Max 777be2e734 Check for proper lapdm_datalink entity
Previously lapdm_datalink->entity->mode was dereferenced without
checking if correct entity is present. This might lead to
segfault. Check it explicitly before dereferencing, log error and
gracefully return if necessary.

Change-Id: I0361e3731e86712b415a370cab1128d611988f56
Related: OS#1898
2017-03-02 14:10:06 +00:00
Max adef12a349 Add strings with PH primitive names
It's useful debugging helper while troubleshooting L1-related issues.

Change-Id: Id7a6d478fd725c51f54ad746bdf9b9095579ff77
Reviewed-on: https://gerrit.osmocom.org/117
Tested-by: Jenkins Builder
Reviewed-by: Max <msuraev@sysmocom.de>
Reviewed-by: Holger Freyther <holger@freyther.de>
2016-05-30 21:21:20 +00:00
Harald Welte 1a87c1b189 LaPDm: Refuse SUSPEND/RESUME/RECONNECT in BTS mode
The primitives for SUSPEND, RESUME and RECONNECT are only permitted on
the MS side of the LAPDm link, not on the BTS side.  So we should check
for this and reject, accordingly.
2015-12-19 17:06:57 +01:00
Jacob Erlbeck d154f8bda2 msgb: Check the return value of msgb_alloc (Coverity)
In some places, the return value of msgb_alloc/msgb_alloc_headroom
is not checked before it is dereferenced.

This commit adds NULL checks to return with -ENOMEM from the calling
functions if the alloc function has failed.

Fixes: Coverity CID 1249692, 1293376
Sponsored-by: On-Waves ehf
2015-04-10 08:44:15 +02:00
Daniel Willmann 3dc4e16786 gsm/lapdm: Prevent LAPD tx_queue from filling up in polling mode
If LAPDm receives an I-Frame while there already is an I-Frame in the
tx_queue the code generates an additional RR (to acknowledge the
received I-Frame). Instead, N(R) of the I-Frame in the tx_queue should
be updated to ACK the data.
2014-03-26 18:11:07 +01:00
Daniel Willmann 55405fb40b lapdm: Make lapdm_datalink_for_sapi public
This API allows you to get the lapdm_datalink for a SAPI. It's needed in
the lapdm_test, so make it public.
2014-03-26 13:52:27 +01:00
Jacob Erlbeck 8dac4159ad ladpm: Fix msgb handling and SAPI=3 establishment delay
Currently it takes 3s to establish a SAPI 3 SACCH connection with
osmo-bts. This is due to the fact, that a broken SABME request is
sent first and and is ignored by the MS. Then, after a T200 timeout
(2s) the SABME command is sent again (this time correctly) and
answered by the MS.

The first SABME message is broken (it has a length field of 3 and
ends with 3 bytes from the tail of the original RSL message),
because of it is expected throughout lapdm.c that msg buffers
containing RSL have msg->l2h == msg->data. Some abis input drivers
fulfill this but IPA doesn't, thus the 3 bytes of the IPA header
are still part of the msg and confuse length computation.

Since internal fields of the msg are modified directly, this is
difficult to see.

This patch adds a new function msgb_pull_to_l3() that explicitely
skips over all headers prepending L3 and therefore resets l1h and
l2h. This function is then used instead of msgb_pull_l2h() which
only worked correctly when msg->l2h == msg->data. In addition,
code manipulating msg->tail and msg->len directly has been replaced
by calls to msgb_trim().

Note that this patch does not fix all issues of this case in the LADP
related code.

Ticket: SYS#192
Sponsored-by: On-Waves ehf
2014-03-10 14:57:26 +01:00
Holger Hans Peter Freyther c620604dfc lapdm: Fix typo in the comment 2014-01-23 15:00:55 +01:00
Andreas Eversberg 5977db0faf LAPDm: Allow sending unit data on DCCH
It is used to transfer PHYSICAL INFORMATION message to the MS.
2013-07-06 23:36:16 +02:00
Andreas Eversberg b36ad2debe Fix of potential memory leaks at lapdm.c 2013-04-06 23:24:10 +02:00
Daniel Willmann e523392c2c lapd: Check in rslms_rx_rll() if lapdm context was initialized earlier
This was found while implementing handover on a sysmobts. When we
receive a channel release request for a channel that was never really
activated (set_lapdm_context() was not called) we segfault in
lapd_recv_dlsap().

We now return early with -EINVAL in rslms_rx_rll() if we receive a
message that assumes set_lapdm_context() was already called.

These are:
* RSL_MT_UNIT_DATA_REQ
* RSL_MT_DATA_REQ
* RSL_MT_SUSP_REQ
* RSL_MT_REL_REQ

A test case was added to trigger the issue.
2012-12-26 10:48:01 +01:00
Harald Welte 973c3c3f24 LAPDm: Ensure there is no payload in DISC frames
When we send DISC frames (especially generated from RSL), we don't want
any remaining bytes from the RSL message showing up as bogus DISC
payload.
2012-04-26 22:15:12 +02:00
Sylvain Munaut dca7d2caaa doc: Fix the Doxygen section endings
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2012-04-18 21:53:23 +02:00