libosmocore  1.5.1
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  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  */
21 
22 #include <stdint.h>
23 #include <osmocom/core/linuxlist.h>
24 #include <osmocom/core/utils.h>
25 #include <osmocom/core/bits.h>
26 #include <osmocom/core/defs.h>
27 
32 #define MSGB_DEBUG
33 
35 struct msgb {
36  struct llist_head list;
39  /* Part of which TRX logical channel we were received / transmitted */
40  /* FIXME: move them into the control buffer */
41  union {
42  void *dst;
43  struct gsm_bts_trx *trx;
44  };
45  struct gsm_lchan *lchan;
47  unsigned char *l1h;
48  unsigned char *l2h;
49  unsigned char *l3h;
50  unsigned char *l4h;
52  unsigned long cb[5];
54  uint16_t data_len;
55  uint16_t len;
57  unsigned char *head;
58  unsigned char *tail;
59  unsigned char *data;
60  unsigned char _data[0];
61 };
62 
63 extern struct msgb *msgb_alloc_c(const void *ctx, uint16_t size, const char *name);
64 extern struct msgb *msgb_alloc(uint16_t size, const char *name);
65 extern void msgb_free(struct msgb *m);
66 extern void msgb_enqueue(struct llist_head *queue, struct msgb *msg);
67 extern struct msgb *msgb_dequeue(struct llist_head *queue);
68 extern void msgb_reset(struct msgb *m);
69 uint16_t msgb_length(const struct msgb *msg);
70 extern const char *msgb_hexdump(const struct msgb *msg);
71 char *msgb_hexdump_buf(char *buf, size_t buf_len, const struct msgb *msg);
72 char *msgb_hexdump_c(const void *ctx, const struct msgb *msg);
73 extern int msgb_resize_area(struct msgb *msg, uint8_t *area,
74  int old_size, int new_size);
75 extern struct msgb *msgb_copy(const struct msgb *msg, const char *name);
76 extern struct msgb *msgb_copy_c(const void *ctx, const struct msgb *msg, const char *name);
77 static int msgb_test_invariant(const struct msgb *msg) __attribute__((pure));
78 
82 static inline void msgb_queue_free(struct llist_head *queue)
83 {
84  struct msgb *msg;
85  while ((msg = msgb_dequeue(queue))) msgb_free(msg);
86 }
87 
97 static inline void msgb_enqueue_count(struct llist_head *queue, struct msgb *msg,
98  unsigned int *count)
99 {
100  msgb_enqueue(queue, msg);
101  (*count)++;
102 }
103 
113 static inline struct msgb *msgb_dequeue_count(struct llist_head *queue,
114  unsigned int *count)
115 {
116  struct msgb *msg = msgb_dequeue(queue);
117  if (msg)
118  (*count)--;
119  return msg;
120 }
121 
122 #ifdef MSGB_DEBUG
123 #include <osmocom/core/panic.h>
124 #define MSGB_ABORT(msg, fmt, args ...) do { \
125  osmo_panic("msgb(%p): " fmt, msg, ## args); \
126  } while(0)
127 #else
128 #define MSGB_ABORT(msg, fmt, args ...)
129 #endif
130 
132 #define msgb_l1(m) ((void *)(m->l1h))
133 
134 #define msgb_l2(m) ((void *)(m->l2h))
135 
136 #define msgb_l3(m) ((void *)(m->l3h))
137 
138 #define msgb_l4(m) ((void *)(m->l4h))
139 
140 #define msgb_sms(m) msgb_l4(m)
141 
149 static inline unsigned int msgb_l1len(const struct msgb *msgb)
150 {
151  return msgb->tail - (uint8_t *)msgb_l1(msgb);
152 }
153 
161 static inline unsigned int msgb_l2len(const struct msgb *msgb)
162 {
163  return msgb->tail - (uint8_t *)msgb_l2(msgb);
164 }
165 
173 static inline unsigned int msgb_l3len(const struct msgb *msgb)
174 {
175  return msgb->tail - (uint8_t *)msgb_l3(msgb);
176 }
177 
185 static inline unsigned int msgb_l4len(const struct msgb *msgb)
186 {
187  return msgb->tail - (uint8_t *)msgb_sms(msgb);
188 }
189 
197 static inline unsigned int msgb_headlen(const struct msgb *msgb)
198 {
199  return msgb->len - msgb->data_len;
200 }
201 
209 static inline int msgb_tailroom(const struct msgb *msgb)
210 {
211  return (msgb->head + msgb->data_len) - msgb->tail;
212 }
213 
221 static inline int msgb_headroom(const struct msgb *msgb)
222 {
223  return (msgb->data - msgb->head);
224 }
225 
238 static inline unsigned char *msgb_put(struct msgb *msgb, unsigned int len)
239 {
240  unsigned char *tmp = msgb->tail;
241  if (msgb_tailroom(msgb) < (int) len)
242  MSGB_ABORT(msgb, "Not enough tailroom msgb_put"
243  " (allocated %u, head at %u, len %u, tailroom %u < want tailroom %u)\n",
244  msgb->data_len - sizeof(struct msgb),
245  msgb->head - msgb->_data,
246  msgb->len,
248  msgb->tail += len;
249  msgb->len += len;
250  return tmp;
251 }
252 
257 static inline void msgb_put_u8(struct msgb *msgb, uint8_t word)
258 {
259  uint8_t *space = msgb_put(msgb, 1);
260  space[0] = word & 0xFF;
261 }
262 
267 static inline void msgb_put_u16(struct msgb *msgb, uint16_t word)
268 {
269  uint8_t *space = msgb_put(msgb, 2);
270  osmo_store16be(word, space);
271 }
272 
277 static inline void msgb_put_u32(struct msgb *msgb, uint32_t word)
278 {
279  uint8_t *space = msgb_put(msgb, 4);
280  osmo_store32be(word, space);
281 }
282 
287 static inline unsigned char *msgb_get(struct msgb *msgb, unsigned int len)
288 {
289  if (msgb_length(msgb) < len)
290  MSGB_ABORT(msgb, "msgb too small to get %u (len %u)\n",
291  len, msgb_length(msgb));
292  msgb->tail -= len;
293  msgb->len -= len;
294  return msgb->tail;
295 }
296 
301 static inline uint8_t msgb_get_u8(struct msgb *msgb)
302 {
303  uint8_t *space = msgb_get(msgb, 1);
304  return space[0];
305 }
306 
311 static inline uint16_t msgb_get_u16(struct msgb *msgb)
312 {
313  uint8_t *space = msgb_get(msgb, 2);
314  return osmo_load16be(space);
315 }
316 
321 static inline uint32_t msgb_get_u32(struct msgb *msgb)
322 {
323  uint8_t *space = msgb_get(msgb, 4);
324  return osmo_load32be(space);
325 }
326 
339 static inline unsigned char *msgb_push(struct msgb *msgb, unsigned int len)
340 {
341  if (msgb_headroom(msgb) < (int) len)
342  MSGB_ABORT(msgb, "Not enough headroom msgb_push"
343  " (allocated %u, head at %u < want headroom %u, len %u, tailroom %u)\n",
344  msgb->data_len - sizeof(struct msgb),
345  msgb->head - msgb->_data,
346  len,
347  msgb->len,
349  msgb->data -= len;
350  msgb->len += len;
351  return msgb->data;
352 }
353 
358 static inline void msgb_push_u8(struct msgb *msg, uint8_t word)
359 {
360  uint8_t *space = msgb_push(msg, 1);
361  space[0] = word;
362 }
363 
368 static inline void msgb_push_u16(struct msgb *msg, uint16_t word)
369 {
370  uint16_t *space = (uint16_t *) msgb_push(msg, 2);
371  osmo_store16be(word, space);
372 }
373 
378 static inline void msgb_push_u32(struct msgb *msg, uint32_t word)
379 {
380  uint32_t *space = (uint32_t *) msgb_push(msg, 4);
381  osmo_store32be(word, space);
382 }
383 
384 static inline unsigned char *msgb_push_tl(struct msgb *msgb, uint8_t tag)
385 {
386  uint8_t *data = msgb_push(msgb, 2);
387 
388  data[0] = tag;
389  data[1] = msgb->len - 2;
390  return data;
391 }
392 
402 static inline unsigned char *msgb_pull(struct msgb *msgb, unsigned int len)
403 {
404  if (msgb_length(msgb) < len)
405  MSGB_ABORT(msgb, "msgb too small to pull %u (len %u)\n",
406  len, msgb_length(msgb));
407  msgb->len -= len;
408  return msgb->data += len;
409 }
410 
419 static inline unsigned char *msgb_pull_to_l3(struct msgb *msg)
420 {
421  unsigned char *ret = msgb_pull(msg, msg->l3h - msg->data);
422  msg->l1h = msg->l2h = NULL;
423  return ret;
424 }
425 
434 static inline unsigned char *msgb_pull_to_l2(struct msgb *msg)
435 {
436  unsigned char *ret = msgb_pull(msg, msg->l2h - msg->data);
437  msg->l1h = NULL;
438  return ret;
439 }
440 
445 static inline uint8_t msgb_pull_u8(struct msgb *msgb)
446 {
447  uint8_t *space = msgb_pull(msgb, 1) - 1;
448  return space[0];
449 }
450 
455 static inline uint16_t msgb_pull_u16(struct msgb *msgb)
456 {
457  uint8_t *space = msgb_pull(msgb, 2) - 2;
458  return osmo_load16be(space);
459 }
460 
465 static inline uint32_t msgb_pull_u32(struct msgb *msgb)
466 {
467  uint8_t *space = msgb_pull(msgb, 4) - 4;
468  return osmo_load32be(space);
469 }
470 
482 static inline void msgb_reserve(struct msgb *msg, int len)
483 {
484  msg->data += len;
485  msg->tail += len;
486 }
487 
493 static inline int msgb_trim(struct msgb *msg, int len)
494 {
495  if (len < 0)
496  MSGB_ABORT(msg, "Negative length is not allowed\n");
497  if (len > msg->data_len)
498  return -1;
499 
500  msg->len = len;
501  msg->tail = msg->data + len;
502 
503  return 0;
504 }
505 
511 static inline int msgb_l3trim(struct msgb *msg, int l3len)
512 {
513  return msgb_trim(msg, (msg->l3h - msg->data) + l3len);
514 }
515 
527 static inline struct msgb *msgb_alloc_headroom_c(const void *ctx, int size, int headroom,
528  const char *name)
529 {
530  osmo_static_assert(size >= headroom, headroom_bigger);
531 
532  struct msgb *msg = msgb_alloc_c(ctx, size, name);
533  if (msg)
534  msgb_reserve(msg, headroom);
535  return msg;
536 }
537 
538 
549 static inline struct msgb *msgb_alloc_headroom(int size, int headroom,
550  const char *name)
551 {
552  osmo_static_assert(size >= headroom, headroom_bigger);
553 
554  struct msgb *msg = msgb_alloc(size, name);
555  if (msg)
556  msgb_reserve(msg, headroom);
557  return msg;
558 }
559 
564 static inline int msgb_test_invariant(const struct msgb *msg)
565 {
566  const unsigned char *lbound;
567  if (!msg || !msg->data || !msg->tail ||
568  (msg->data + msg->len != msg->tail) ||
569  (msg->data < msg->head) ||
570  (msg->tail > msg->head + msg->data_len))
571  return 0;
572 
573  lbound = msg->head;
574 
575  if (msg->l1h) {
576  if (msg->l1h < lbound)
577  return 0;
578  lbound = msg->l1h;
579  }
580  if (msg->l2h) {
581  if (msg->l2h < lbound)
582  return 0;
583  lbound = msg->l2h;
584  }
585  if (msg->l3h) {
586  if (msg->l3h < lbound)
587  return 0;
588  lbound = msg->l3h;
589  }
590  if (msg->l4h) {
591  if (msg->l4h < lbound)
592  return 0;
593  lbound = msg->l4h;
594  }
595 
596  return lbound <= msg->head + msg->data_len;
597 }
598 
599 
600 /* msgb data comparison helpers */
601 
608 #define msgb_eq_data(msg, data, len) \
609  _msgb_eq(__FILE__, __LINE__, __func__, 0, msg, data, len, false)
610 
617 #define msgb_eq_l1_data(msg, data, len) \
618  _msgb_eq(__FILE__, __LINE__, __func__, 1, msg, data, len, false)
619 
626 #define msgb_eq_l2_data(msg, data, len) \
627  _msgb_eq(__FILE__, __LINE__, __func__, 2, msg, data, len, false)
628 
635 #define msgb_eq_l3_data(msg, data, len) \
636  _msgb_eq(__FILE__, __LINE__, __func__, 3, msg, data, len, false)
637 
644 #define msgb_eq_l4_data(msg, data, len) \
645  _msgb_eq(__FILE__, __LINE__, __func__, 4, msg, data, len, false)
646 
647 
648 /* msgb test/debug helpers */
649 
656 #define msgb_eq_data_print(msg, data, len) \
657  _msgb_eq(__FILE__, __LINE__, __func__, 0, msg, data, len, true)
658 
665 #define msgb_eq_l1_data_print(msg, data, len) \
666  _msgb_eq(__FILE__, __LINE__, __func__, 1, msg, data, len, true)
667 
674 #define msgb_eq_l2_data_print(msg, data, len) \
675  _msgb_eq(__FILE__, __LINE__, __func__, 2, msg, data, len, true)
676 
683 #define msgb_eq_l3_data_print(msg, data, len) \
684  _msgb_eq(__FILE__, __LINE__, __func__, 3, msg, data, len, true)
685 
686 
693 #define msgb_eq_l4_data_print(msg, data, len) \
694  _msgb_eq(__FILE__, __LINE__, __func__, 4, msg, data, len, true)
695 
696 bool _msgb_eq(const char *file, size_t line, const char *func, uint8_t level,
697  const struct msgb *msg, const uint8_t *data, size_t len, bool print);
698 
699 
700 /* msgb data comparison */
701 
707 #define msgb_eq(msg1, msg2) msgb_eq_data(msg1, msgb_data(msg2), msgb_length(msg2))
708 
714 #define msgb_eq_l1(msg1, msg2) msgb_eq_l1_data(msg1, msgb_l1(msg2), msgb_l1len(msg2))
715 
721 #define msgb_eq_l2(msg1, msg2) msgb_eq_l2_data(msg1, msgb_l2(msg2), msgb_l2len(msg2))
722 
728 #define msgb_eq_l3(msg1, msg2) msgb_eq_l3_data(msg1, msgb_l3(msg2), msgb_l3len(msg2))
729 
735 #define msgb_eq_l4(msg1, msg2) msgb_eq_l4_data(msg1, msgb_l4(msg2), msgb_l4len(msg2))
736 
737 
738 /* non inline functions to ease binding */
739 
740 uint8_t *msgb_data(const struct msgb *msg);
741 
742 void *msgb_talloc_ctx_init(void *root_ctx, unsigned int pool_size);
743 void msgb_set_talloc_ctx(void *ctx) OSMO_DEPRECATED("Use msgb_talloc_ctx_init() instead");
744 int msgb_printf(struct msgb *msgb, const char *format, ...);
745 
746 static inline const char *msgb_hexdump_l1(const struct msgb *msg)
747 {
748  if (!msgb_l1(msg) || !(msgb_l1len(msg)))
749  return "[]";
750  return osmo_hexdump((const unsigned char *) msgb_l1(msg), msgb_l1len(msg));
751 }
752 
753 static inline const char *msgb_hexdump_l2(const struct msgb *msg)
754 {
755  if (!msgb_l2(msg) || !(msgb_l2len(msg)))
756  return "[]";
757  return osmo_hexdump((const unsigned char *) msgb_l2(msg), msgb_l2len(msg));
758 }
759 
760 static inline const char *msgb_hexdump_l3(const struct msgb *msg)
761 {
762  if (!msgb_l3(msg) || !(msgb_l3len(msg)))
763  return "[]";
764  return osmo_hexdump((const unsigned char*) msgb_l3(msg), msgb_l3len(msg));
765 }
766 
767 static inline const char *msgb_hexdump_l4(const struct msgb *msg)
768 {
769  if (!msgb_l4(msg) || !(msgb_l4len(msg)))
770  return "[]";
771  return osmo_hexdump((const unsigned char*) msgb_l4(msg), msgb_l4len(msg));
772 }
773 
msgb::list
struct llist_head list
linked list header
Definition: msgb.h:36
msgb_hexdump_buf
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:431
msgb::l3h
unsigned char * l3h
pointer to Layer 3 header.
Definition: msgb.h:49
msgb_hexdump_l1
static const char * msgb_hexdump_l1(const struct msgb *msg)
Definition: msgb.h:746
msgb_test_invariant
static int msgb_test_invariant(const struct msgb *msg) __attribute__((pure))
Check a message buffer for consistency.
Definition: msgb.h:564
msgb_pull_u16
static uint16_t msgb_pull_u16(struct msgb *msgb)
remove uint16 from front of message
Definition: msgb.h:455
OSMO_DEPRECATED
#define OSMO_DEPRECATED(text)
Set the deprecated attribute with a message.
Definition: defs.h:41
msgb_hexdump_l2
static const char * msgb_hexdump_l2(const struct msgb *msg)
Definition: msgb.h:753
len
static size_t len(const char *str)
msgb_l3trim
static int msgb_l3trim(struct msgb *msg, int l3len)
Trim the msgb to a given layer3 length.
Definition: msgb.h:511
msgb_put
static unsigned char * msgb_put(struct msgb *msgb, unsigned int len)
append data to end of message buffer
Definition: msgb.h:238
msgb_copy_c
struct msgb * msgb_copy_c(const void *ctx, const struct msgb *msg, const char *name)
Copy an msgb.
Definition: msgb.c:329
msgb::data
unsigned char * data
start of message in buffer
Definition: msgb.h:59
msgb_alloc_headroom
static struct msgb * msgb_alloc_headroom(int size, int headroom, const char *name)
Allocate message buffer with specified headroom.
Definition: msgb.h:549
msgb_l4len
static unsigned int msgb_l4len(const struct msgb *msgb)
determine length of L4 message
Definition: msgb.h:185
__attribute__
struct gsm48_classmark3 __attribute__
fls64 - find last set bit in a 64-bit word @x: the word to search
Definition: log2.h:61
msgb_pull_u8
static uint8_t msgb_pull_u8(struct msgb *msgb)
remove uint8 from front of message
Definition: msgb.h:445
msg
uint8_t msg[0]
msgb_hexdump_l3
static const char * msgb_hexdump_l3(const struct msgb *msg)
Definition: msgb.h:760
msgb_alloc_c
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:77
msgb_tailroom
static int msgb_tailroom(const struct msgb *msgb)
determine how much tail room is left in msgb
Definition: msgb.h:209
msgb::cb
unsigned long cb[5]
control buffer
Definition: msgb.h:52
msgb_set_talloc_ctx
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:298
name
const char * name
msgb_pull_u32
static uint32_t msgb_pull_u32(struct msgb *msgb)
remove uint32 from front of message
Definition: msgb.h:465
msgb_push_tl
static unsigned char * msgb_push_tl(struct msgb *msgb, uint8_t tag)
Definition: msgb.h:384
msgb::len
uint16_t len
length of bytes used in msgb
Definition: msgb.h:55
msgb_get_u8
static uint8_t msgb_get_u8(struct msgb *msgb)
remove uint8 from end of message
Definition: msgb.h:301
msgb_talloc_ctx_init
void * msgb_talloc_ctx_init(void *root_ctx, unsigned int pool_size)
Initialize a msgb talloc context for msgb_alloc.
Definition: msgb.c:311
msgb_enqueue_count
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:97
msgb_l1
#define msgb_l1(m)
obtain L1 header of msgb
Definition: msgb.h:132
msgb_length
uint16_t msgb_length(const struct msgb *msg)
get length of message buffer
Definition: msgb.c:289
level
uint8_t level
logging level
Definition: gsmtap.h:6
bits.h
msgb_hexdump_c
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:523
data
uint8_t data[0]
osmo_load16be
static uint16_t osmo_load16be(const void *p)
load unaligned 16-bit integer (big-endian encoding)
Definition: bit16gen.h:112
msgb
Osmocom message buffer.
Definition: msgb.h:35
msgb_push
static unsigned char * msgb_push(struct msgb *msgb, unsigned int len)
prepend (push) some data to start of message
Definition: msgb.h:339
msgb_reserve
static void msgb_reserve(struct msgb *msg, int len)
Increase headroom of empty msgb, reducing the tailroom.
Definition: msgb.h:482
msgb_l3len
static unsigned int msgb_l3len(const struct msgb *msgb)
determine length of L3 message
Definition: msgb.h:173
msgb_resize_area
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:384
msgb::trx
struct gsm_bts_trx * trx
Definition: msgb.h:43
msgb::l1h
unsigned char * l1h
pointer to Layer1 header (if any)
Definition: msgb.h:47
utils.h
msgb_push_u16
static void msgb_push_u16(struct msgb *msg, uint16_t word)
prepend a uint16 value to the head of the message
Definition: msgb.h:368
msgb_free
void msgb_free(struct msgb *m)
Release given message buffer.
Definition: msgb.c:121
msgb_pull_to_l2
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:434
msgb_get_u32
static uint32_t msgb_get_u32(struct msgb *msgb)
remove uint32 from end of message
Definition: msgb.h:321
osmo_static_assert
#define osmo_static_assert(exp, name)
Definition: utils.h:73
msgb_headlen
static unsigned int msgb_headlen(const struct msgb *msgb)
determine the length of the header
Definition: msgb.h:197
msgb_pull_to_l3
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:419
msgb_alloc_headroom_c
static struct msgb * msgb_alloc_headroom_c(const void *ctx, int size, int headroom, const char *name)
Allocate message buffer with specified headroom from specified talloc context.
Definition: msgb.h:527
msgb_l1len
static unsigned int msgb_l1len(const struct msgb *msgb)
determine length of L1 message
Definition: msgb.h:149
msgb::tail
unsigned char * tail
end of message in buffer
Definition: msgb.h:58
msgb::l4h
unsigned char * l4h
pointer to layer 4 header
Definition: msgb.h:50
msgb_dequeue_count
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:113
msgb_put_u32
static void msgb_put_u32(struct msgb *msgb, uint32_t word)
append a uint32 value to the end of the message
Definition: msgb.h:277
llist_head
(double) linked list header structure
Definition: linuxlist.h:46
msgb_push_u8
static void msgb_push_u8(struct msgb *msg, uint8_t word)
prepend a uint8 value to the head of the message
Definition: msgb.h:358
msgb_trim
static int msgb_trim(struct msgb *msg, int len)
Trim the msgb to a given absolute length.
Definition: msgb.h:493
msgb_l2len
static unsigned int msgb_l2len(const struct msgb *msgb)
determine length of L2 message
Definition: msgb.h:161
osmo_load32be
static uint32_t osmo_load32be(const void *p)
load unaligned 32-bit integer (big-endian encoding)
Definition: bit32gen.h:112
_msgb_eq
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:206
msgb_put_u16
static void msgb_put_u16(struct msgb *msgb, uint16_t word)
append a uint16 value to the end of the message
Definition: msgb.h:267
msgb_copy
struct msgb * msgb_copy(const struct msgb *msg, const char *name)
Copy an msgb.
Definition: msgb.c:366
msgb_sms
#define msgb_sms(m)
obtain SMS header of msgb
Definition: msgb.h:140
msgb_hexdump_l4
static const char * msgb_hexdump_l4(const struct msgb *msg)
Definition: msgb.h:767
msgb_reset
void msgb_reset(struct msgb *m)
Re-set all message buffer pointers.
Definition: msgb.c:168
msgb_hexdump
const char * msgb_hexdump(const struct msgb *msg)
Return a (static) buffer containing a hexdump of the msg.
Definition: msgb.c:512
msgb_get_u16
static uint16_t msgb_get_u16(struct msgb *msgb)
remove uint16 from end of message
Definition: msgb.h:311
msgb::lchan
struct gsm_lchan * lchan
logical channel
Definition: msgb.h:45
osmo_store16be
static void osmo_store16be(uint16_t x, void *p)
store unaligned 16-bit integer (big-endian encoding)
Definition: bit16gen.h:125
msgb_l4
#define msgb_l4(m)
obtain L4 header of msgb
Definition: msgb.h:138
msgb_l3
#define msgb_l3(m)
obtain L3 header of msgb
Definition: msgb.h:136
msgb::l2h
unsigned char * l2h
pointer to A-bis layer 2 header: OML, RSL(RLL), NS
Definition: msgb.h:48
msgb::data_len
uint16_t data_len
length of underlying data array
Definition: msgb.h:54
file
write Write running configuration to or terminal n Write configuration to the file(same as write file)\n") ALIAS(config_write_file
osmo_store32be
static void osmo_store32be(uint32_t x, void *p)
store unaligned 32-bit integer (big-endian encoding)
Definition: bit32gen.h:125
msgb_pull
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:402
msgb_data
uint8_t * msgb_data(const struct msgb *msg)
get pointer to data section of message buffer
Definition: msgb.c:188
msgb_queue_free
static void msgb_queue_free(struct llist_head *queue)
Free all msgbs from a queue built with msgb_enqueue().
Definition: msgb.h:82
MSGB_ABORT
#define MSGB_ABORT(msg, fmt, args ...)
Definition: msgb.h:124
panic.h
msgb_l2
#define msgb_l2(m)
obtain L2 header of msgb
Definition: msgb.h:134
defs.h
msgb_push_u32
static void msgb_push_u32(struct msgb *msg, uint32_t word)
prepend a uint32 value to the head of the message
Definition: msgb.h:378
msgb::dst
void * dst
reference of origin/destination
Definition: msgb.h:42
msgb_alloc
struct msgb * msgb_alloc(uint16_t size, const char *name)
Allocate a new message buffer from tall_msgb_ctx.
Definition: msgb.c:112
osmo_hexdump
char * osmo_hexdump(const unsigned char *buf, int len)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:396
msgb_put_u8
static void msgb_put_u8(struct msgb *msgb, uint8_t word)
append a uint8 value to the end of the message
Definition: msgb.h:257
msgb_dequeue
struct msgb * msgb_dequeue(struct llist_head *queue)
Dequeue message buffer from head of queue.
Definition: msgb.c:145
linuxlist.h
msgb::head
unsigned char * head
start of underlying memory buffer
Definition: msgb.h:57
msgb_enqueue
void msgb_enqueue(struct llist_head *queue, struct msgb *msg)
Enqueue message buffer to tail of a queue.
Definition: msgb.c:133
msgb_printf
int msgb_printf(struct msgb *msgb, const char *format,...)
Print a string to the end of message buffer.
Definition: msgb.c:549
msgb_headroom
static int msgb_headroom(const struct msgb *msgb)
determine the amount of headroom in msgb
Definition: msgb.h:221
msgb::_data
unsigned char _data[0]
optional immediate data array
Definition: msgb.h:60
msgb_get
static unsigned char * msgb_get(struct msgb *msgb, unsigned int len)
remove data from end of message
Definition: msgb.h:287