blob: b0740edab59fa5f1278a28887cd659e05a7b7329 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001#ifndef _MSGB_H
2#define _MSGB_H
3
4/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23struct bts_link;
24
25struct msgb {
26 /* ptr to the incoming (RX) or outgoing (TX) BTS link */
27 struct gsm_bts_link *bts_link;
28
29 u_int8_t l2_off;
30 u_int8_t l3_off;
31
32 u_int16_t data_len;
33 u_int16_t len;
34
35 unsigned char *head;
36 unsigned char *tail;
37 unsigned char *data;
38 unsigned char _data[0];
39};
40
41extern struct msgb *msgb_alloc(u_int16_t size);
42extern void msgb_free(struct msgb *m);
43
44#define msgb_l2(m) ((void *)(m->data + m->l2_off))
45#define msgb_l3(m) ((void *)(m->data + m->l3_off))
46
47static inline unsigned int msgb_headlen(const struct msgb *msgb)
48{
49 return msgb->len - msgb->data_len;
50}
51static inline unsigned char *msgb_put(struct msgb *msgb, unsigned int len)
52{
53 unsigned char *tmp = msgb->tail;
54 msgb->tail += len;
55 msgb->len += len;
56 return tmp;
57}
58static inline unsigned char *msgb_push(struct msgb *msgb, unsigned int len)
59{
60 msgb->data -= len;
61 msgb->len += len;
62 return msgb->data;
63}
64static inline unsigned char *msgb_pull(struct msgb *msgb, unsigned int len)
65{
66 msgb->len -= len;
67 return msgb->data += len;
68}
69static inline int msgb_tailroom(const struct msgb *msgb)
70{
71 return (msgb->data + msgb->data_len) - msgb->tail;
72}
73
74#endif /* _MSGB_H */