libosmocore 1.9.0.196-9975
Osmocom core library
msgb.h
Go to the documentation of this file.
1#pragma once
2
3/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#include <stdint.h>
20#include <osmocom/core/utils.h>
21#include <osmocom/core/bits.h>
22#include <osmocom/core/defs.h>
23
28#define MSGB_DEBUG
29
31struct msgb {
35 /* Part of which TRX logical channel we were received / transmitted */
36 /* FIXME: move them into the control buffer */
37 union {
38 void *dst;
39 struct gsm_bts_trx *trx;
40 };
41 struct gsm_lchan *lchan;
43 unsigned char *l1h;
44 unsigned char *l2h;
45 unsigned char *l3h;
46 unsigned char *l4h;
48 unsigned long cb[5];
50 uint16_t data_len;
51 uint16_t len;
53 unsigned char *head;
54 unsigned char *tail;
55 unsigned char *data;
56 unsigned char _data[0];
57};
58
59extern struct msgb *msgb_alloc_c(const void *ctx, uint16_t size, const char *name);
60extern struct msgb *msgb_alloc(uint16_t size, const char *name);
61extern void msgb_free(struct msgb *m);
62extern void msgb_enqueue(struct llist_head *queue, struct msgb *msg);
63extern struct msgb *msgb_dequeue(struct llist_head *queue);
64extern void msgb_reset(struct msgb *m);
65uint16_t msgb_length(const struct msgb *msg);
66extern const char *msgb_hexdump(const struct msgb *msg);
67char *msgb_hexdump_buf(char *buf, size_t buf_len, const struct msgb *msg);
68char *msgb_hexdump_c(const void *ctx, const struct msgb *msg);
69extern int msgb_resize_area(struct msgb *msg, uint8_t *area,
70 int old_size, int new_size);
71extern struct msgb *msgb_copy(const struct msgb *msg, const char *name);
72extern struct msgb *msgb_copy_c(const void *ctx, const struct msgb *msg, const char *name);
73extern struct msgb *msgb_copy_resize(const struct msgb *msg, uint16_t new_len, const char *name);
74extern struct msgb *msgb_copy_resize_c(const void *ctx, const struct msgb *msg, uint16_t new_len, const char *name);
75static int msgb_test_invariant(const struct msgb *msg) __attribute__((pure));
76
80static inline void msgb_queue_free(struct llist_head *queue)
81{
82 struct msgb *msg;
83 while ((msg = msgb_dequeue(queue))) msgb_free(msg);
84}
85
95static inline void msgb_enqueue_count(struct llist_head *queue, struct msgb *msg,
96 unsigned int *count)
97{
98 msgb_enqueue(queue, msg);
99 (*count)++;
100}
101
111static inline struct msgb *msgb_dequeue_count(struct llist_head *queue,
112 unsigned int *count)
113{
114 struct msgb *msg = msgb_dequeue(queue);
115 if (msg)
116 (*count)--;
117 return msg;
118}
119
120#ifdef MSGB_DEBUG
121#include <osmocom/core/panic.h>
122#define MSGB_ABORT(msg, fmt, args ...) do { \
123 osmo_panic("msgb(%p): " fmt, msg, ## args); \
124 } while(0)
125#else
126#define MSGB_ABORT(msg, fmt, args ...)
127#endif
128
130#define msgb_l1(m) ((void *)((m)->l1h))
132#define msgb_l2(m) ((void *)((m)->l2h))
134#define msgb_l3(m) ((void *)((m)->l3h))
136#define msgb_l4(m) ((void *)((m)->l4h))
138#define msgb_sms(m) msgb_l4(m)
139
147static inline unsigned int msgb_l1len(const struct msgb *msgb)
148{
150 return msgb->tail - (uint8_t *)msgb_l1(msgb);
151}
152
160static inline unsigned int msgb_l2len(const struct msgb *msgb)
161{
163 return msgb->tail - (uint8_t *)msgb_l2(msgb);
164}
165
173static inline unsigned int msgb_l3len(const struct msgb *msgb)
174{
176 return msgb->tail - (uint8_t *)msgb_l3(msgb);
177}
178
186static inline unsigned int msgb_l4len(const struct msgb *msgb)
187{
189 return msgb->tail - (uint8_t *)msgb_l4(msgb);
190}
191
199static inline unsigned int msgb_headlen(const struct msgb *msgb)
200{
201 return msgb->len - msgb->data_len;
202}
203
211static inline int msgb_tailroom(const struct msgb *msgb)
212{
213 return (msgb->head + msgb->data_len) - msgb->tail;
214}
215
223static inline int msgb_headroom(const struct msgb *msgb)
224{
225 return (msgb->data - msgb->head);
226}
227
240static inline unsigned char *msgb_put(struct msgb *msgb, unsigned int len)
241{
242 unsigned char *tmp = msgb->tail;
243 if (OSMO_UNLIKELY(msgb_tailroom(msgb) < (int) len))
244 MSGB_ABORT(msgb, "Not enough tailroom msgb_put"
245 " (allocated %u, head at %u, len %u, tailroom %u < want tailroom %u)\n",
246 msgb->data_len - sizeof(struct msgb),
247 msgb->head - msgb->_data,
248 msgb->len,
250 msgb->tail += len;
251 msgb->len += len;
252 return tmp;
253}
254
259static inline void msgb_put_u8(struct msgb *msgb, uint8_t word)
260{
261 uint8_t *space = msgb_put(msgb, 1);
262 space[0] = word & 0xFF;
263}
264
269static inline void msgb_put_u16(struct msgb *msgb, uint16_t word)
270{
271 uint8_t *space = msgb_put(msgb, 2);
272 osmo_store16be(word, space);
273}
274
279static inline void msgb_put_u32(struct msgb *msgb, uint32_t word)
280{
281 uint8_t *space = msgb_put(msgb, 4);
282 osmo_store32be(word, space);
283}
284
289static inline unsigned char *msgb_get(struct msgb *msgb, unsigned int len)
290{
292 MSGB_ABORT(msgb, "msgb too small to get %u (len %u)\n",
294 msgb->tail -= len;
295 msgb->len -= len;
296 return msgb->tail;
297}
298
303static inline uint8_t msgb_get_u8(struct msgb *msgb)
304{
305 uint8_t *space = msgb_get(msgb, 1);
306 return space[0];
307}
308
313static inline uint16_t msgb_get_u16(struct msgb *msgb)
314{
315 uint8_t *space = msgb_get(msgb, 2);
316 return osmo_load16be(space);
317}
318
323static inline uint32_t msgb_get_u32(struct msgb *msgb)
324{
325 uint8_t *space = msgb_get(msgb, 4);
326 return osmo_load32be(space);
327}
328
341static inline unsigned char *msgb_push(struct msgb *msgb, unsigned int len)
342{
343 if (OSMO_UNLIKELY(msgb_headroom(msgb) < (int) len))
344 MSGB_ABORT(msgb, "Not enough headroom msgb_push"
345 " (allocated %u, head at %u < want headroom %u, len %u, tailroom %u)\n",
346 msgb->data_len - sizeof(struct msgb),
347 msgb->head - msgb->_data,
348 len,
349 msgb->len,
351 msgb->data -= len;
352 msgb->len += len;
353 return msgb->data;
354}
355
360static inline void msgb_push_u8(struct msgb *msg, uint8_t word)
361{
362 uint8_t *space = msgb_push(msg, 1);
363 space[0] = word;
364}
365
370static inline void msgb_push_u16(struct msgb *msg, uint16_t word)
371{
372 uint16_t *space = (uint16_t *) msgb_push(msg, 2);
373 osmo_store16be(word, space);
374}
375
380static inline void msgb_push_u32(struct msgb *msg, uint32_t word)
381{
382 uint32_t *space = (uint32_t *) msgb_push(msg, 4);
383 osmo_store32be(word, space);
384}
385
386static inline unsigned char *msgb_push_tl(struct msgb *msgb, uint8_t tag)
387{
388 uint8_t *data = msgb_push(msgb, 2);
389
390 data[0] = tag;
391 data[1] = msgb->len - 2;
392 return data;
393}
394
404static inline unsigned char *msgb_pull(struct msgb *msgb, unsigned int len)
405{
407 MSGB_ABORT(msgb, "msgb too small to pull %u (len %u)\n",
409 msgb->len -= len;
410 return msgb->data += len;
411}
412
421static inline unsigned char *msgb_pull_to_l3(struct msgb *msg)
422{
423 unsigned char *ret = msgb_pull(msg, msg->l3h - msg->data);
424 msg->l1h = msg->l2h = NULL;
425 return ret;
426}
427
436static inline unsigned char *msgb_pull_to_l2(struct msgb *msg)
437{
438 unsigned char *ret = msgb_pull(msg, msg->l2h - msg->data);
439 msg->l1h = NULL;
440 return ret;
441}
442
447static inline uint8_t msgb_pull_u8(struct msgb *msgb)
448{
449 uint8_t *space = msgb_pull(msgb, 1) - 1;
450 return space[0];
451}
452
457static inline uint16_t msgb_pull_u16(struct msgb *msgb)
458{
459 uint8_t *space = msgb_pull(msgb, 2) - 2;
460 return osmo_load16be(space);
461}
462
467static inline uint32_t msgb_pull_u32(struct msgb *msgb)
468{
469 uint8_t *space = msgb_pull(msgb, 4) - 4;
470 return osmo_load32be(space);
471}
472
484static inline void msgb_reserve(struct msgb *msg, int len)
485{
486 msg->data += len;
487 msg->tail += len;
488}
489
495static inline int msgb_trim(struct msgb *msg, int len)
496{
497 if (OSMO_UNLIKELY(len < 0))
498 MSGB_ABORT(msg, "Negative length is not allowed\n");
499 if (OSMO_UNLIKELY(len > msg->data_len))
500 return -1;
501
502 msg->len = len;
503 msg->tail = msg->data + len;
504
505 return 0;
506}
507
513static inline int msgb_l3trim(struct msgb *msg, int l3len)
514{
515 return msgb_trim(msg, (msg->l3h - msg->data) + l3len);
516}
517
529static inline struct msgb *msgb_alloc_headroom_c(const void *ctx, uint16_t size, uint16_t headroom,
530 const char *name)
531{
532 OSMO_ASSERT(size >= headroom);
533
534 struct msgb *msg = msgb_alloc_c(ctx, size, name);
535 if (OSMO_LIKELY(msg))
536 msgb_reserve(msg, headroom);
537 return msg;
538}
539
540
551static inline struct msgb *msgb_alloc_headroom(uint16_t size, uint16_t headroom,
552 const char *name)
553{
554 OSMO_ASSERT(size >= headroom);
555
556 struct msgb *msg = msgb_alloc(size, name);
557 if (OSMO_LIKELY(msg))
558 msgb_reserve(msg, headroom);
559 return msg;
560}
561
566static inline int msgb_test_invariant(const struct msgb *msg)
567{
568 const unsigned char *lbound;
569 if (!msg || !msg->data || !msg->tail ||
570 (msg->data + msg->len != msg->tail) ||
571 (msg->data < msg->head) ||
572 (msg->tail > msg->head + msg->data_len))
573 return 0;
574
575 lbound = msg->head;
576
577 if (msg->l1h) {
578 if (msg->l1h < lbound)
579 return 0;
580 lbound = msg->l1h;
581 }
582 if (msg->l2h) {
583 if (msg->l2h < lbound)
584 return 0;
585 lbound = msg->l2h;
586 }
587 if (msg->l3h) {
588 if (msg->l3h < lbound)
589 return 0;
590 lbound = msg->l3h;
591 }
592 if (msg->l4h) {
593 if (msg->l4h < lbound)
594 return 0;
595 lbound = msg->l4h;
596 }
597
598 return lbound <= msg->head + msg->data_len;
599}
600
601
602/* msgb data comparison helpers */
603
610#define msgb_eq_data(msg, data, len) \
611 _msgb_eq(__FILE__, __LINE__, __func__, 0, msg, data, len, false)
612
619#define msgb_eq_l1_data(msg, data, len) \
620 _msgb_eq(__FILE__, __LINE__, __func__, 1, msg, data, len, false)
621
628#define msgb_eq_l2_data(msg, data, len) \
629 _msgb_eq(__FILE__, __LINE__, __func__, 2, msg, data, len, false)
630
637#define msgb_eq_l3_data(msg, data, len) \
638 _msgb_eq(__FILE__, __LINE__, __func__, 3, msg, data, len, false)
639
646#define msgb_eq_l4_data(msg, data, len) \
647 _msgb_eq(__FILE__, __LINE__, __func__, 4, msg, data, len, false)
648
649
650/* msgb test/debug helpers */
651
658#define msgb_eq_data_print(msg, data, len) \
659 _msgb_eq(__FILE__, __LINE__, __func__, 0, msg, data, len, true)
660
667#define msgb_eq_l1_data_print(msg, data, len) \
668 _msgb_eq(__FILE__, __LINE__, __func__, 1, msg, data, len, true)
669
676#define msgb_eq_l2_data_print(msg, data, len) \
677 _msgb_eq(__FILE__, __LINE__, __func__, 2, msg, data, len, true)
678
685#define msgb_eq_l3_data_print(msg, data, len) \
686 _msgb_eq(__FILE__, __LINE__, __func__, 3, msg, data, len, true)
687
688
695#define msgb_eq_l4_data_print(msg, data, len) \
696 _msgb_eq(__FILE__, __LINE__, __func__, 4, msg, data, len, true)
697
698bool _msgb_eq(const char *file, size_t line, const char *func, uint8_t level,
699 const struct msgb *msg, const uint8_t *data, size_t len, bool print);
700
701
702/* msgb data comparison */
703
709#define msgb_eq(msg1, msg2) msgb_eq_data(msg1, msgb_data(msg2), msgb_length(msg2))
710
716#define msgb_eq_l1(msg1, msg2) msgb_eq_l1_data(msg1, msgb_l1(msg2), msgb_l1len(msg2))
717
723#define msgb_eq_l2(msg1, msg2) msgb_eq_l2_data(msg1, msgb_l2(msg2), msgb_l2len(msg2))
724
730#define msgb_eq_l3(msg1, msg2) msgb_eq_l3_data(msg1, msgb_l3(msg2), msgb_l3len(msg2))
731
737#define msgb_eq_l4(msg1, msg2) msgb_eq_l4_data(msg1, msgb_l4(msg2), msgb_l4len(msg2))
738
739
740/* non inline functions to ease binding */
741
742uint8_t *msgb_data(const struct msgb *msg);
743
744void *msgb_talloc_ctx_init(void *root_ctx, unsigned int pool_size);
745void msgb_set_talloc_ctx(void *ctx) OSMO_DEPRECATED("Use msgb_talloc_ctx_init() instead");
746int msgb_printf(struct msgb *msgb, const char *format, ...);
747
748static inline const char *msgb_hexdump_l1(const struct msgb *msg)
749{
750 if (!msgb_l1(msg) || !(msgb_l1len(msg)))
751 return "[]";
752 return osmo_hexdump((const unsigned char *) msgb_l1(msg), msgb_l1len(msg));
753}
754
755static inline const char *msgb_hexdump_l2(const struct msgb *msg)
756{
757 if (!msgb_l2(msg) || !(msgb_l2len(msg)))
758 return "[]";
759 return osmo_hexdump((const unsigned char *) msgb_l2(msg), msgb_l2len(msg));
760}
761
762static inline const char *msgb_hexdump_l3(const struct msgb *msg)
763{
764 if (!msgb_l3(msg) || !(msgb_l3len(msg)))
765 return "[]";
766 return osmo_hexdump((const unsigned char*) msgb_l3(msg), msgb_l3len(msg));
767}
768
769static inline const char *msgb_hexdump_l4(const struct msgb *msg)
770{
771 if (!msgb_l4(msg) || !(msgb_l4len(msg)))
772 return "[]";
773 return osmo_hexdump((const unsigned char*) msgb_l4(msg), msgb_l4len(msg));
774}
775
static void osmo_store16be(uint16_t x, void *p)
store unaligned 16-bit integer (big-endian encoding)
Definition: bit16gen.h:121
static uint16_t osmo_load16be(const void *p)
load unaligned 16-bit integer (big-endian encoding)
Definition: bit16gen.h:108
static void osmo_store32be(uint32_t x, void *p)
store unaligned 32-bit integer (big-endian encoding)
Definition: bit32gen.h:121
static uint32_t osmo_load32be(const void *p)
load unaligned 32-bit integer (big-endian encoding)
Definition: bit32gen.h:108
Osmocom bit level support code.
General definitions that are meant to be included from header files.
const char * name
write Write running configuration to or terminal n Write configuration to the file(same as write file)\n") ALIAS(config_write_file
static size_t len(const char *str)
enum gsm0808_assignment_requirement __attribute__
Definition: log2.h:61
uint8_t data[0]
static unsigned char * msgb_pull(struct msgb *msgb, unsigned int len)
remove (pull) a header from the front of the message buffer
Definition: msgb.h:404
uint16_t msgb_length(const struct msgb *msg)
get length of message buffer
Definition: msgb.c:285
static uint8_t msgb_pull_u8(struct msgb *msgb)
remove uint8 from front of message
Definition: msgb.h:447
static int msgb_tailroom(const struct msgb *msgb)
determine how much tail room is left in msgb
Definition: msgb.h:211
void msgb_set_talloc_ctx(void *ctx) OSMO_DEPRECATED("Use msgb_talloc_ctx_init() instead")
Set the talloc context for msgb_alloc Deprecated, use msgb_talloc_ctx_init() instead.
Definition: msgb.c:294
static unsigned int msgb_l4len(const struct msgb *msgb)
determine length of L4 message
Definition: msgb.h:186
struct msgb * msgb_alloc(uint16_t size, const char *name)
Allocate a new message buffer from tall_msgb_ctx.
Definition: msgb.c:108
static void msgb_put_u32(struct msgb *msgb, uint32_t word)
append a uint32 value to the end of the message
Definition: msgb.h:279
static uint16_t msgb_pull_u16(struct msgb *msgb)
remove uint16 from front of message
Definition: msgb.h:457
static unsigned char * msgb_pull_to_l2(struct msgb *msg)
remove (pull) all headers in front of l2h from the message buffer.
Definition: msgb.h:436
static uint32_t msgb_get_u32(struct msgb *msgb)
remove uint32 from end of message
Definition: msgb.h:323
struct msgb * msgb_copy_c(const void *ctx, const struct msgb *msg, const char *name)
Copy an msgb.
Definition: msgb.c:383
static struct msgb * msgb_alloc_headroom(uint16_t size, uint16_t headroom, const char *name)
Allocate message buffer with specified headroom.
Definition: msgb.h:551
static int msgb_test_invariant(const struct msgb *msg) __attribute__((pure))
Check a message buffer for consistency.
Definition: msgb.h:566
static const char * msgb_hexdump_l3(const struct msgb *msg)
Definition: msgb.h:762
static unsigned int msgb_l3len(const struct msgb *msgb)
determine length of L3 message
Definition: msgb.h:173
char * msgb_hexdump_c(const void *ctx, const struct msgb *msg)
Return a dynamically allocated buffer containing a hexdump of the msg.
Definition: msgb.c:553
void msgb_reset(struct msgb *m)
Re-set all message buffer pointers.
Definition: msgb.c:164
static void msgb_push_u8(struct msgb *msg, uint8_t word)
prepend a uint8 value to the head of the message
Definition: msgb.h:360
static const char * msgb_hexdump_l4(const struct msgb *msg)
Definition: msgb.h:769
#define msgb_l1(m)
obtain L1 header of msgb
Definition: msgb.h:130
struct msgb * msgb_copy(const struct msgb *msg, const char *name)
Copy an msgb.
Definition: msgb.c:396
static unsigned char * msgb_push_tl(struct msgb *msgb, uint8_t tag)
Definition: msgb.h:386
static unsigned int msgb_l2len(const struct msgb *msgb)
determine length of L2 message
Definition: msgb.h:160
void * msgb_talloc_ctx_init(void *root_ctx, unsigned int pool_size)
Initialize a msgb talloc context for msgb_alloc.
Definition: msgb.c:307
static void msgb_push_u16(struct msgb *msg, uint16_t word)
prepend a uint16 value to the head of the message
Definition: msgb.h:370
static uint32_t msgb_pull_u32(struct msgb *msgb)
remove uint32 from front of message
Definition: msgb.h:467
static unsigned int msgb_l1len(const struct msgb *msgb)
determine length of L1 message
Definition: msgb.h:147
static const char * msgb_hexdump_l1(const struct msgb *msg)
Definition: msgb.h:748
static unsigned char * msgb_put(struct msgb *msgb, unsigned int len)
append data to end of message buffer
Definition: msgb.h:240
bool _msgb_eq(const char *file, size_t line, const char *func, uint8_t level, const struct msgb *msg, const uint8_t *data, size_t len, bool print)
Compare and print: check data in msgb against given data and print errors if any.
Definition: msgb.c:202
#define msgb_l4(m)
obtain L4 header of msgb
Definition: msgb.h:136
int msgb_printf(struct msgb *msgb, const char *format,...)
Print a string to the end of message buffer.
Definition: msgb.c:579
static void msgb_put_u16(struct msgb *msgb, uint16_t word)
append a uint16 value to the end of the message
Definition: msgb.h:269
static struct msgb * msgb_dequeue_count(struct llist_head *queue, unsigned int *count)
Dequeue message buffer from head of queue and decrement queue size counter.
Definition: msgb.h:111
char * msgb_hexdump_buf(char *buf, size_t buf_len, const struct msgb *msg)
fill user-provided buffer with hexdump of the msg.
Definition: msgb.c:461
const char * msgb_hexdump(const struct msgb *msg)
Return a (static) buffer containing a hexdump of the msg.
Definition: msgb.c:542
static struct msgb * msgb_alloc_headroom_c(const void *ctx, uint16_t size, uint16_t headroom, const char *name)
Allocate message buffer with specified headroom from specified talloc context.
Definition: msgb.h:529
uint8_t * msgb_data(const struct msgb *msg)
get pointer to data section of message buffer
Definition: msgb.c:184
static void msgb_queue_free(struct llist_head *queue)
Free all msgbs from a queue built with msgb_enqueue().
Definition: msgb.h:80
static int msgb_trim(struct msgb *msg, int len)
Trim the msgb to a given absolute length.
Definition: msgb.h:495
static uint8_t msgb_get_u8(struct msgb *msgb)
remove uint8 from end of message
Definition: msgb.h:303
static unsigned char * msgb_pull_to_l3(struct msgb *msg)
remove (pull) all headers in front of l3h from the message buffer.
Definition: msgb.h:421
static void msgb_push_u32(struct msgb *msg, uint32_t word)
prepend a uint32 value to the head of the message
Definition: msgb.h:380
int msgb_resize_area(struct msgb *msg, uint8_t *area, int old_size, int new_size)
Resize an area within an msgb.
Definition: msgb.c:414
struct msgb * msgb_copy_resize_c(const void *ctx, const struct msgb *msg, uint16_t new_len, const char *name)
Copy an msgb with memory reallocation.
Definition: msgb.c:326
static void msgb_put_u8(struct msgb *msgb, uint8_t word)
append a uint8 value to the end of the message
Definition: msgb.h:259
struct msgb * msgb_alloc_c(const void *ctx, uint16_t size, const char *name)
Allocate a new message buffer from given talloc context.
Definition: msgb.c:73
void msgb_enqueue(struct llist_head *queue, struct msgb *msg)
Enqueue message buffer to tail of a queue.
Definition: msgb.c:129
static unsigned char * msgb_get(struct msgb *msgb, unsigned int len)
remove data from end of message
Definition: msgb.h:289
static uint16_t msgb_get_u16(struct msgb *msgb)
remove uint16 from end of message
Definition: msgb.h:313
static void msgb_enqueue_count(struct llist_head *queue, struct msgb *msg, unsigned int *count)
Enqueue message buffer to tail of a queue and increment queue size counter.
Definition: msgb.h:95
static void msgb_reserve(struct msgb *msg, int len)
Increase headroom of empty msgb, reducing the tailroom.
Definition: msgb.h:484
#define msgb_l3(m)
obtain L3 header of msgb
Definition: msgb.h:134
static int msgb_l3trim(struct msgb *msg, int l3len)
Trim the msgb to a given layer3 length.
Definition: msgb.h:513
struct msgb * msgb_dequeue(struct llist_head *queue)
Dequeue message buffer from head of queue.
Definition: msgb.c:141
void msgb_free(struct msgb *m)
Release given message buffer.
Definition: msgb.c:117
struct msgb * msgb_copy_resize(const struct msgb *msg, uint16_t new_len, const char *name)
Copy an msgb with memory reallocation.
Definition: msgb.c:369
static unsigned int msgb_headlen(const struct msgb *msgb)
determine the length of the header
Definition: msgb.h:199
static const char * msgb_hexdump_l2(const struct msgb *msg)
Definition: msgb.h:755
#define msgb_l2(m)
obtain L2 header of msgb
Definition: msgb.h:132
#define MSGB_ABORT(msg, fmt, args ...)
Definition: msgb.h:122
static unsigned char * msgb_push(struct msgb *msgb, unsigned int len)
prepend (push) some data to start of message
Definition: msgb.h:341
static int msgb_headroom(const struct msgb *msgb)
determine the amount of headroom in msgb
Definition: msgb.h:223
#define OSMO_UNLIKELY(exp)
Definition: utils.h:47
#define OSMO_ASSERT(exp)
Helper macro to terminate when an assertion fails.
Definition: utils.h:113
#define OSMO_LIKELY(exp)
Branch prediction optimizations.
Definition: utils.h:46
#define OSMO_DEPRECATED(text)
Set the deprecated attribute with a message.
Definition: defs.h:41
char * osmo_hexdump(const unsigned char *buf, int len)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:394
uint8_t msg[0]
uint8_t level
logging level
Definition: gsmtap.h:6
Simple doubly linked list implementation.
(double) linked list header structure
Definition: linuxlist.h:46
Osmocom message buffer.
Definition: msgb.h:31
unsigned long cb[5]
control buffer
Definition: msgb.h:48
unsigned char * l2h
pointer to A-bis layer 2 header: OML, RSL(RLL), NS
Definition: msgb.h:44
uint16_t len
length of bytes used in msgb
Definition: msgb.h:51
unsigned char * data
start of message in buffer
Definition: msgb.h:55
void * dst
reference of origin/destination
Definition: msgb.h:38
struct gsm_lchan * lchan
logical channel
Definition: msgb.h:41
unsigned char _data[0]
optional immediate data array
Definition: msgb.h:56
unsigned char * l3h
pointer to Layer 3 header.
Definition: msgb.h:45
unsigned char * tail
end of message in buffer
Definition: msgb.h:54
struct gsm_bts_trx * trx
Definition: msgb.h:39
unsigned char * l4h
pointer to layer 4 header
Definition: msgb.h:46
uint16_t data_len
length of underlying data array
Definition: msgb.h:50
struct llist_head list
linked list header
Definition: msgb.h:32
unsigned char * head
start of underlying memory buffer
Definition: msgb.h:53
unsigned char * l1h
pointer to Layer1 header (if any)
Definition: msgb.h:43