Commit Graph

29 Commits

Author SHA1 Message Date
Max db038255eb msgb: add test helpers
It's often handy to compare certain msgb layer to a given array and
print the position where they differ. Add simple pretty-printer and
corresponding L* wrappers.

Change-Id: I3bc95f2f5ab6e3f4b502647fb3e0aaaf1f7c4cf5
2018-12-12 09:34:12 +00:00
Vadim Yanitskiy 10959cdea2 src/msgb.c: avoid using internal talloc API
An internal symbol '_talloc_zero' of talloc library was used
during a msgb allocation. This is not actually good because:

  - it may be removed or modified by talloc developers;
  - the behaviour may be changed by talloc developers;
  - it's marked as internal using 'underscore';
  - there is public API to do the same.

So, let's use the public API.

Change-Id: I1080c9071e997944cc0f9fc3716129e9395437ad
2018-03-09 04:14:31 +07:00
Vadim Yanitskiy b42330516f src/msgb.c: print an error if msgb allocation failed
Printing an error message when msgb allocation failed was initially
intended, but have been commented out for years. This would
facilitate the bug hunting process, especially on embedded
platforms with limited resources (e.g. amount of RAM).

The GLOBAL logging subsystem with FATAL level is used
for printing such messages.

Change-Id: I3e2d1beabd6936fc28a1ad664c083ff1698bb644
2018-03-09 04:07:51 +07:00
Vadim Yanitskiy 68b1e8e99c src/msgb.c: remove dead includes from OpenBSC
The MSGB API is not a part of OpenBSC anymore, so let's remove
dead includes, which were probably left here during the
migration process.

Change-Id: Ief562a6e5b220a84902f95862d67279f953ee726
2018-03-08 21:14:47 +07:00
Vadim Yanitskiy 8c8e6d7e53 src/msgb.c: cosmetic: fix spelling mistakes
Change-Id: I6b473aadaa22d95f2a8cc87580c638ccd7e531a4
2018-03-08 21:10:23 +07: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
Philipp Maier c5b47cc032 add function msgb_printf() to print formatted text into msg buf
In ASCII string based protocols it a printf() version that prints
directly to the message buffer may be useful.

Add function msgb_printf(), make sure that msg buffer bounderies
are not exceeded. If the end of the tail buffer is hit, return
with an error code.

Change-Id: I15e1af68616309555d0ed9ac5da027c9833d42e3
2017-10-22 20:09:26 +00: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
Neels Hofmeyr f45334be29 msgb: add msgb_talloc_ctx_init(), deprecate msgb_set_talloc_ctx()
So far each and every main() scope creates a msgb talloc context and either
passes it to msgb_set_talloc_ctx() or sets tall_msgb_ctx directly (by defining
it extern first).

Remove some code duplication: add one central function that creates the "msgb"
talloc context for all.

Most users of msgb employ a talloc_named_const(), but osmo-bts uses a
talloc_pool() instead. Offer both ways by means of the pool_size argument, and
for both ways make sure the context is called "msgb".

Suggest that msgb users should move to this new function: deprecate
msgb_set_talloc_ctx(). To be able to do so, include core/defs.h in msgb.h.

There's a tradeoff between hiding the msgb talloc context behind API that tries
to guess all use cases versus avoiding code dup. This patch opts against code
dup and boldly assumes that all future use is covered.

Also, the new function suggests to not access tall_msgb_ctx directly, which can
be considered a style improvement.

It seems that not all main scopes that use msgb actually initialize the msgb
ctx. As a fallback for these, explicitly initialize tall_msgb_ctx to NULL.

Change-Id: I747fbbf977c4d2c868c8dead64cfc5fd86eb8d4c
2016-09-27 11:46:38 +02:00
Max d826f1771c Fix potential segfault in msg_dequeue
Change-Id: I06e9c5ba3e00c73a4e52d2583ce3492f236275ce
2016-06-23 20:00:33 +00:00
Harald Welte 2d2e2cca0d Update doxygen annotations in libosmocore
This adds and improves doxygen API descriptions all over libosmocore,
reducing the 'white spots' that don't have any documentation.
2016-05-05 18:49:27 +02:00
Neels Hofmeyr 42fff58a45 Fix some recently added formats on 64bit
86ec311896 adds compiler warnings on 64bit. The build is clean otherwise,
so let's keep it that way.
2015-12-24 16:17:21 +01:00
Jacob Erlbeck 86ec311896 msgb: Let msgb_hexdump be more tolerant
This patch makes msgb_hexdump accept out of range lXh pointers and
shows info about them instead of aborting the dump entirely.

Sponsored-by: On-Waves ehf
2015-12-21 16:14:50 +01:00
Jacob Erlbeck cdd05f0ed4 msgb: Add msgb_resize_area and msgb_copy
These functions originate from openbsc/src/gprs but are generic
msgb helper functions.

  msgb_copy:  This function allocates a new msgb, copies the data
              buffer of msg, and adjusts the pointers (incl. l1h-l4h)
              accordingly.

  msgb_resize_area:
              This resizes a sub area of the msgb data and adjusts the
              pointers (incl. l1h-l4h) accordingly.

Sponsored-by: On-Waves ehf
2015-12-21 16:14:23 +01:00
Jacob Erlbeck baa225ed86 msgb: Add msgb_hexdump() function
This function works like osmo_hexdump() and returns a static buffer
containing hex bytes along with markers for the layers.

Note that it uses osmo_hexdump() internally, thus a call to
msgb_hexdump() invalidates the buffer that has been returned by an
earlier call to osmo_hexdump(). In short: don't mix them in a single
call printf().

Sponsored-by: On-Waves ehf
2014-03-04 13:30:12 +01:00
Katerina Barone-Adesi c28c6a02d2 misc: Doxygen tweaks: fixed some typos and minor errors
Doxygen generates quite a lot of warnings on libosmocore. Some of them
are obvious typos - this patch aims to fix such low-hanging fruit.
2013-02-15 13:27:59 +01: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
Harald Welte ba6988bd89 some more doxygen work (include the notion of modules) 2011-08-17 17:14:11 +02:00
Harald Welte 9e1f0604b5 add msgb_set_talloc_ctx() to set the talloc context for msgb allocations 2011-06-29 18:46:10 +02:00
Holger Hans Peter Freyther 28dbfe9bf7 misc: Remove the sys/types.h include from various files
We used this include for the u_int{8,16,32}_t types but we do
not need this anymore.
2011-04-18 16:57:04 +02:00
Pablo Neira Ayuso 8341934844 include: reorganize headers file to include/osmocom/[gsm|core]
This patch moves all GSM-specific definitions to include/osmocom/gsm.
Moreover, the headers in include/osmocore/ have been moved to
include/osmocom/core.

This has been proposed by Harald Welte and Sylvain Munaunt.

Tested with `make distcheck'.

Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2011-03-23 18:09:28 +01:00
Holger Hans Peter Freyther acffb60c1a msgb: Add non-inlined helper functions to ease with language bindings
It is easier from languages that dlopen libosmocore to have a function
to access this data than to poke at the bytes of the struct directly. Add
copyright for this method and the reset method I did earlier this year.
2010-10-18 18:22:31 +02:00
Harald Welte 95df5c0179 msgb: initialize cb[] to zero during msgb_reset() 2010-05-01 23:53:26 +02:00
Harald Welte bb77c9d6cc msgb: remove smsh, llch, tlli and gmmh
This is a lot of GSM/GPRS specific stuff in struct msgb which we want
to avoid.  The 'control buffer' will replace them.
2010-04-30 14:26:12 +02:00
Harald Welte 3120ac3f78 remove the unneeded bts_link pointer from msgb 2010-04-30 14:19:48 +02:00
Sylvain Munaut 17a5a28202 msgb.c: Style cleanup in initialization
Don't assign the same var twice & init all from the same source.
2010-02-24 22:57:46 +01:00
Harald Welte ec8b4501c7 intial checkin of the libosmocore project 2010-02-20 20:34:29 +01:00