2008-12-23 20:25:15 +00:00
|
|
|
/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
2009-01-01 00:33:02 +00:00
|
|
|
#include <string.h>
|
2008-12-23 20:25:15 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
split 'libosmocore' from openbsc codebase
This library is intended to collect all generic/common funcitionality
of all Osmocom.org projects, including OpenBSC but also OsmocomBB
The library currently includes the following modules:
bitvec, comp128, gsm_utils, msgb, select, signal, statistics, talloc, timer,
tlv_parse, linuxlist
msgb allocation error debugging had to be temporarily disabled as it depends on
'debug.c' functionality which at the moment remains in OpenBSC
2010-02-20 15:24:02 +00:00
|
|
|
#include <osmocore/msgb.h>
|
|
|
|
//#include <openbsc/gsm_data.h>
|
|
|
|
#include <osmocore/talloc.h>
|
|
|
|
//#include <openbsc/debug.h>
|
2009-06-20 20:36:41 +00:00
|
|
|
|
2009-12-24 08:43:25 +00:00
|
|
|
void *tall_msgb_ctx;
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2009-06-26 17:39:35 +00:00
|
|
|
struct msgb *msgb_alloc(u_int16_t size, const char *name)
|
2008-12-23 20:25:15 +00:00
|
|
|
{
|
2009-06-20 20:36:41 +00:00
|
|
|
struct msgb *msg;
|
|
|
|
|
2009-06-26 17:39:35 +00:00
|
|
|
msg = _talloc_zero(tall_msgb_ctx, sizeof(*msg) + size, name);
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2009-12-17 22:10:46 +00:00
|
|
|
if (!msg) {
|
split 'libosmocore' from openbsc codebase
This library is intended to collect all generic/common funcitionality
of all Osmocom.org projects, including OpenBSC but also OsmocomBB
The library currently includes the following modules:
bitvec, comp128, gsm_utils, msgb, select, signal, statistics, talloc, timer,
tlv_parse, linuxlist
msgb allocation error debugging had to be temporarily disabled as it depends on
'debug.c' functionality which at the moment remains in OpenBSC
2010-02-20 15:24:02 +00:00
|
|
|
//LOGP(DRSL, LOGL_FATAL, "unable to allocate msgb\n");
|
2008-12-23 20:25:15 +00:00
|
|
|
return NULL;
|
2009-12-17 22:10:46 +00:00
|
|
|
}
|
2008-12-23 20:25:15 +00:00
|
|
|
|
|
|
|
msg->data_len = size;
|
|
|
|
msg->len = 0;
|
|
|
|
msg->data = msg->_data;
|
|
|
|
|
|
|
|
msg->head = msg->data;
|
|
|
|
msg->data = msg->data;
|
|
|
|
/* reset tail pointer */
|
2008-12-25 23:28:35 +00:00
|
|
|
msg->tail = msg->data;
|
2008-12-23 20:25:15 +00:00
|
|
|
//msg->end = msg->tail + size;
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void msgb_free(struct msgb *m)
|
|
|
|
{
|
2009-06-20 20:36:41 +00:00
|
|
|
talloc_free(m);
|
2008-12-23 20:25:15 +00:00
|
|
|
}
|
2008-12-25 23:28:35 +00:00
|
|
|
|
|
|
|
void msgb_enqueue(struct llist_head *queue, struct msgb *msg)
|
|
|
|
{
|
|
|
|
llist_add_tail(&msg->list, queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct msgb *msgb_dequeue(struct llist_head *queue)
|
|
|
|
{
|
|
|
|
struct llist_head *lh;
|
|
|
|
|
|
|
|
if (llist_empty(queue))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
lh = queue->next;
|
2008-12-26 10:20:07 +00:00
|
|
|
llist_del(lh);
|
|
|
|
|
2008-12-25 23:28:35 +00:00
|
|
|
return llist_entry(lh, struct msgb, list);
|
|
|
|
}
|
2009-07-27 22:41:45 +00:00
|
|
|
|
2009-10-09 05:33:36 +00:00
|
|
|
void msgb_reset(struct msgb *msg)
|
|
|
|
{
|
|
|
|
msg->len = 0;
|
|
|
|
msg->len = 0;
|
|
|
|
msg->data = msg->_data;
|
|
|
|
|
|
|
|
msg->head = msg->data;
|
|
|
|
msg->data = msg->data;
|
|
|
|
/* reset tail pointer */
|
|
|
|
msg->tail = msg->data;
|
|
|
|
|
|
|
|
/* reset pointers */
|
|
|
|
msg->bts_link = NULL;
|
|
|
|
msg->trx = NULL;
|
|
|
|
msg->lchan = NULL;
|
|
|
|
msg->l2h = NULL;
|
|
|
|
msg->l3h = NULL;
|
|
|
|
msg->smsh = NULL;
|
|
|
|
}
|