1 /* (C) 2008 by Harald Welte <laforge@gnumonks.org>
2 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <sys/types.h>
27 #include <osmocore/msgb.h>
28 //#include <openbsc/gsm_data.h>
29 #include <osmocore/talloc.h>
30 //#include <openbsc/debug.h>
34 struct msgb *msgb_alloc(uint16_t size, const char *name)
38 msg = _talloc_zero(tall_msgb_ctx, sizeof(*msg) + size, name);
41 //LOGP(DRSL, LOGL_FATAL, "unable to allocate msgb\n");
47 msg->data = msg->_data;
48 msg->head = msg->_data;
49 msg->tail = msg->_data;
54 void msgb_free(struct msgb *m)
59 void msgb_enqueue(struct llist_head *queue, struct msgb *msg)
61 llist_add_tail(&msg->list, queue);
64 struct msgb *msgb_dequeue(struct llist_head *queue)
66 struct llist_head *lh;
68 if (llist_empty(queue))
74 return llist_entry(lh, struct msgb, list);
77 void msgb_reset(struct msgb *msg)
80 msg->data = msg->_data;
81 msg->head = msg->_data;
82 msg->tail = msg->_data;
90 memset(&msg->cb, 0, sizeof(msg->cb));
93 uint8_t *msgb_data(const struct msgb *msg)
98 uint16_t msgb_length(const struct msgb *msg)