summaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/msgb.h
Commit message (Collapse)AuthorAgeFilesLines
* msgb_put: more elaborate logging of head/tailroom failureNeels Hofmeyr2019-11-241-3/+12
| | | | Change-Id: I55b68098e1037c74ebe5faa86e34bd4494f5b726
* msgb: Allow size==headroom in msgb_alloc_headroom*()Pau Espin Pedrol2019-09-261-2/+2
| | | | | | | | | Nothinh really forbids this case, it's totally fine allocating all space of msgb as headroom. osmo-pcu actually does that in gprs_rlcmac_ul_tbf::snd_ul_ud(). Related: OS#4029 Change-Id: Ibe05d08e3169a2603e891f76682a3b352a93ec7a
* Add _c versions of functions that otherwise return static buffersHarald Welte2019-04-101-0/+26
| | | | | | | | | | | | | | We have a habit of returning static buffers from some functions, particularly when generating some kind of string values. This is convenient in terms of memory management, but it comes at the expense of not being thread-safe, and not allowing for two calls of the related function within one printf() statement. Let's introduce _c suffix versions of those functions where the caller passes in a talloc context from which the output buffer shall be allocated. Change-Id: I8481c19b68ff67cfa22abb93c405ebcfcb0ab19b
* Add _buf() functions to bypass static string buffersHarald Welte2019-04-031-0/+1
| | | | | | | | | | | | | | | We have a number of static buffers in use in libosmo*. This means the related functions are not usable in a thread-safe way. While we so far don't have many multi-threaded programs in the osmocom universe, the static buffers also prevent us from calling the same e.g. string-ify function twice within a single printf() call. Let's make sure there's an alternative function in all those cases, where the user can pass in a caller-allocated buffer + size, and make the 'classic' function with the static buffer a wrapper around that _buf() variant. Change-Id: Ibf85f79e93244f53b2684ff6f1095c5b41203e05
* core/msgb.h: fix incorrect Doxygen parameter descriptionVadim Yanitskiy2019-03-271-5/+5
| | | | | | | | | | | | | | | | | | | | | core/msgb.h:414: warning: argument 'msgb' of command @param is not found in the argument list of msgb_pull_to_l2(struct msgb *msg) core/msgb.h:399: warning: argument 'msgb' of command @param is not found in the argument list of msgb_pull_to_l3(struct msgb *msg) core/msgb.h:351: warning: argument 'msgb' of command @param is not found in the argument list of msgb_push_u16(struct msgb *msg, uint16_t word) core/msgb.h:361: warning: argument 'msgb' of command @param is not found in the argument list of msgb_push_u32(struct msgb *msg, uint32_t word) core/msgb.h:341: warning: argument 'msgb' of command @param is not found in the argument list of msgb_push_u8(struct msgb *msg, uint8_t word) Change-Id: I5d660933ecfa89c631319eccf9e3d5c1986ec8ff
* core/msgb.h: drop meaningless parameter of msgb_eq_* helpersVadim Yanitskiy2019-03-271-5/+5
| | | | | | | | | | | | | | | | | | | Thanks to the following Doxygen warning: msgb.h:XXX: warning: The following parameters of msgb_eq_l2(msg1, msgb2, len) are not documented: parameter 'msgb2' parameter 'len' it was discovered that parameter 'len' is not required at all. It basically doesn't make any sense to pass any length value, because it can be calculated using msgb_length(). Let's drop this parameter. Given that this part of the API was broken so far (see I1079d629abdb8770eef6be7341e586a933cd9cca), it should be more or less safe to do this. Change-Id: Icd9b72eb6bfa9628ff1ed2f948b57058551a4328
* core/msgb.h: fix dead msgb2 reference in msgb_eq_* helpersVadim Yanitskiy2019-03-271-5/+5
| | | | | | | | | | | | | | | | | | | | | | Neither Doxygen documentation of the msgb data comparison helpers, nor their actual definitions does refer msgb2. Instead, 'msg2' is referenced in both cases. This was discovered while investigating the following Doxygen warnings: msgb.h:XXX: warning: argument 'msg2' of command @param is not found in the argument list of msgb_eq(msg1, msgb2, len) msgb.h:XXX: warning: The following parameters of msgb_eq_l2(msg1, msgb2, len) are not documented: parameter 'msgb2' parameter 'len' Due to this bug it was impossible to use the affected macros, because 'msg2' was not listed in their parameters. Having the unit test coverage would spot this bug at the beginning! Change-Id: I1079d629abdb8770eef6be7341e586a933cd9cca
* Rename msgb_wrap_with_TL()Max2019-01-211-1/+1
| | | | | | | | | | | | | | | This resolves an issue introduced in 84fb5bb6a09a6a358f98c654c84c3b99a0f24eef when msgb_wrap_with_TL() was introduced as an inline function with *exactly the same name* as in osmo-msc.git and openbsc.git. We *NEVER* do something like this. Functions moved from applications to library *MUST* always be renamed. This has been the case for almost a decade now. With this subsequent change we make sure the libosmocore function has a different name and doesn't clash. After this commit, old openbsc.git and osmo-bsc.git should again build fine. Change-Id: If1e851ac605c8d2fde3da565b0bd674ea6350c2e
* msgb: add test helpersMax2018-12-121-0/+139
| | | | | | | | 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
* Update msgb Lx helpersMax2018-12-031-1/+17
| | | | | | | | | * add missing L1 and L4 hexdump * add msgb_l4() for consistency and convert msgb_sms() into simple alias Those will be used in follow-up patches for msgb debug/test helpers. Change-Id: I8d6dd1b1ff3aa98a452711c692ca7dee0449203b
* Move msgb_push helpers to public headerMax2018-11-191-0/+9
| | | | | | | | | | The msgb_wrap_with_TL() is generally useful so it make sense to make it public to facilitate code re-use. Other helpers can be implemented as trivial wrappers over existing tlv.h functions. Update headers and code accordingly. Change-Id: I37e91d031fba28cf1c6735b8069b0265746f55e6
* core/msgb.h: introduce msgb_l4len() helperVadim Yanitskiy2018-11-071-0/+12
| | | | | | | | | | There is already a group of similar functions for L1, L2 and L3, but L4 was missing. The L4 is usually used for parsing of complex L3 messages, such as SS/USSD and SMS. This change introduces a similar halper for L4. Change-Id: I755f2d654bbdad2a8b4f94df9023bdd370b07ae6
* msgb: Introduce msgb_{de,en}queue_count APIsPau Espin Pedrol2018-08-171-0/+34
| | | | | | | | | | It's a common pattern having a list of msgb and having to maintain its size (for instance, to limit the maximum size of the list). Having the counter updated at the same time that the msgb is enqueued or dequeued helps avoiding introducing new bugs by forgetting to update the size counter at the right places. Change-Id: I33b501e89a8f29e4aa121696bcbb13d4b83db40f
* msgb: msgb_pull: Abort when pulling more than avail sizePau Espin Pedrol2018-04-111-0/+3
| | | | Change-Id: I512ff2035ae7a929e6c96df82938cc1ddbcc4e2a
* msgb: msgb_get: Drop unneeded tmp varPau Espin Pedrol2018-04-111-2/+1
| | | | Change-Id: I27bb2ab59408c9cd1363b3b5acb2263128c55732
* osmo_msgbdump_{l2,l3}(): Proper typecastHarald Welte2018-02-091-2/+2
| | | | | | | | | | | | This avoids compiler warnings like /tmp/work/sysmobts_v2-poky-linux-gnueabi/osmo-pcu/0.4+gitAUTOINC+4c112dc5a6-r1.18/recipe-sysroot/usr/include/osmocom/core/msgb.h: In function 'const char* msgb_hexdump_l2(const msgb*)': error: invalid conversion from 'void*' to 'const unsigned char*' [-fpermissive] return osmo_hexdump(msgb_l2(msg), msgb_l2len(msg)); which we've been getting in osmo-pcu builds on some platforms. Change-Id: I0ec652a1a569ec1507d8411cf1ef87afabcca799
* msgb: Add msgb_hexdump_{l2,l3}() to dump l2 or l3 part of message bufferHarald Welte2018-02-091-0/+14
| | | | Change-Id: I98e85397fb541ee0fd711f2e1852f63f3bb87359
* msgb: add inline msgb_queue_free()Neels Hofmeyr2017-11-201-0/+9
| | | | | Related: Iaad35f03e3bdfabf3ba82b16e563c0a5d1f03639 (libosmo-netif) Change-Id: Ia291832ca445d4071f0ed9a01730d945ff691cf7
* add function msgb_printf() to print formatted text into msg bufPhilipp Maier2017-10-221-0/+1
| | | | | | | | | | | 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
* doxygen: unify use of \file across the boardNeels Hofmeyr2017-06-231-3/+1
| | | | | | | | | | | | | | | | | 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
* doxygen: enable AUTOBRIEF, drop \briefNeels Hofmeyr2017-06-231-48/+48
| | | | | | | | | | 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
* update/extend doxygen documentationHarald Welte2017-06-121-7/+1
| | | | | | | | | 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
* msgb: Add msgb_pull_to_l2() analogous to msgb_pull_to_l3()Harald Welte2017-04-151-0/+15
| | | | | | | Introduce msgb_pull_to_l2() which pulls (removes) any msgb contents in front of the L2 header (msg->l2h). Change-Id: I7786a1b30f9e7eaa3dcdb3cbb2a85a126588f6cd
* msgb: add msgb_push_u{8,16,32}() functionsHarald Welte2016-11-111-0/+30
| | | | | | | Those work analoguous to msgb_put_*() but pre-pend the given value into the msg headroom, rather than appending it to the end. Change-Id: I7de63e9d04c2d2b678f1f20eef37f9be2c4f5ec2
* msgb: add msgb_talloc_ctx_init(), deprecate msgb_set_talloc_ctx()Neels Hofmeyr2016-09-271-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* fix error msg: msgb_put(): say "msgb_put", not "msgb_push"Neels Hofmeyr2016-09-091-1/+1
| | | | Change-Id: I72f31ebad693f98eb088a99b83aeb10cf9acc29e
* msgb: Assert len >= 0 in msgb_trimJacob Erlbeck2016-01-151-0/+2
| | | | | | | | | | | Currently msgb_trim only checks for len > data_len and returns -1 in that case, allowing the caller to fix it somehow. Using a negative length will always lead to a corrupt msgb, but this is not being checked. This commit adds a check for len < 0 and a conditional call to MSGB_ABORT. Sponsored-by: On-Waves ehf
* msgb: Add msgb_test_invariant functionJacob Erlbeck2015-12-211-0/+40
| | | | | | This adds a function that verifies whether a mgsb is consistent. Sponsored-by: On-Waves ehf
* msgb: Add msgb_resize_area and msgb_copyJacob Erlbeck2015-12-211-0/+3
| | | | | | | | | | | | | | | 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
* msgb: make msgb_get() finally work as expectedHarald Welte2014-10-261-1/+1
|
* core: Add generic LE/BE load/store uint type convertors and use them in msgbMax2014-06-161-10/+13
| | | | | Submitted-by: Max <max.suraev@fairwaves.co> Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* include: Switch to #pragma once patternSylvain Munaut2014-06-161-4/+1
| | | | Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* ladpm: Fix msgb handling and SAPI=3 establishment delayJacob Erlbeck2014-03-101-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* msgb: Add msgb_hexdump() functionJacob Erlbeck2014-03-041-0/+1
| | | | | | | | | | | | 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
* misc: Doxygen tweaks: fixed some typos and minor errorsKaterina Barone-Adesi2013-02-151-1/+1
| | | | | Doxygen generates quite a lot of warnings on libosmocore. Some of them are obvious typos - this patch aims to fix such low-hanging fruit.
* msgb: fix msgb_pull_u*()Steve Markgraf2012-11-141-3/+3
| | | | | | | | msgb_pull returns a pointer to the new begin of the buffer, unlike msgb_get(), where those functions were originally taken from. Signed-off-by: Steve Markgraf <steve@steve-m.de>
* msgb: msgb_get() is supposed to get bytes from END, msgb_pull() from HEADHarald Welte2012-09-081-3/+34
| | | | | | msgb_get() has been wrong all the time, despite the documentation being correct. If you've used the broken msgb_get() before, you have to change your code now, sorry.
* doc: Fix the Doxygen section endingsSylvain Munaut2012-04-181-1/+1
| | | | Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* msgb_trim(): actually trim to an absolute length, as the comment statesHarald Welte2012-01-141-5/+3
| | | | | The previous commit introduced a new msgb_trim() but the implementation differed from the specification.
* msgb: introduce msgb_trim() and msgb_l3trim() to trim msgb'sHarald Welte2012-01-141-0/+28
|
* some more doxygen work (include the notion of modules)Harald Welte2011-08-171-49/+6
|
* start to add doxygen documentation to libosmocore headersHarald Welte2011-08-161-25/+209
|
* mkae the new 'void *dst' member part of a union with the trx pointerHarald Welte2011-07-181-3/+4
| | | | | this ensures struct msgb is the same size as before, which will ensure binary compatibility
* msgb: add ->dst attribute to store routing informationPablo Neira Ayuso2011-07-181-0/+3
| | | | | | | | | | This patch adds a new attribute to msgb objects. This new attribute will store a pointer to the routing information, in the case of the A-bis link, this will be used to store e1inp_sign_link instead of struct gsm_bts_trx. This deprecates msg->trx, that can be removed once all application are ported to use msg->dst.
* add msgb_set_talloc_ctx() to set the talloc context for msgb allocationsHarald Welte2011-06-291-0/+2
|
* utils: use namespace prefix osmo_*Pablo Neira Ayuso2011-05-071-1/+1
| | | | | | | | | | | | Summary of changes: s/bcd2char/osmo_bcd2char/g s/char2bcd/osmo_char2bcd/g s/hexparse/osmo_hexparse/g s/hexdump/osmo_hexdump/g s/hexdump_nospc/osmo_hexdump_nospc/g s/ubit_dump/osmo_ubit_dump/g s/static_assert/osmo_static_assert/g
* include: reorganize headers file to include/osmocom/[gsm|core]Pablo Neira Ayuso2011-03-231-0/+197
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>