core/msgb: Use the new osmo_panic call to handle errors
[osmocom-bb.git] / include / osmocore / msgb.h
index 31db719..354c5d8 100644 (file)
 #include <stdint.h>
 #include "linuxlist.h"
 
-struct bts_link;
+#define MSGB_DEBUG
 
 struct msgb {
        struct llist_head list;
 
-       /* ptr to the physical E1 link to the BTS(s) */
-       struct gsm_bts_link *bts_link;
-
        /* Part of which TRX logical channel we were received / transmitted */
+       /* FIXME: move them into the control buffer */
        struct gsm_bts_trx *trx;
        struct gsm_lchan *lchan;
 
@@ -41,17 +39,11 @@ struct msgb {
        unsigned char *l2h;
        /* the layer 3 header. For OML: FOM; RSL: 04.08; GPRS: BSSGP */
        unsigned char *l3h;
-
        /* the layer 4 header */
-       union {
-               unsigned char *smsh;
-               unsigned char *llch;
-               unsigned char *l4h;
-       };
+       unsigned char *l4h;
 
-       /* the layer 5 header, GPRS: GMM header */
-       unsigned char *gmmh;
-       uint32_t tlli;
+       /* the 'control buffer', large enough to contain 5 pointers */
+       unsigned long cb[5];
 
        uint16_t data_len;
        uint16_t len;
@@ -68,10 +60,18 @@ extern void msgb_enqueue(struct llist_head *queue, struct msgb *msg);
 extern struct msgb *msgb_dequeue(struct llist_head *queue);
 extern void msgb_reset(struct msgb *m);
 
+#ifdef MSGB_DEBUG
+#include <osmocore/panic.h>
+static inline void msgb_abort(struct msgb *msg, const char *text)
+{
+       osmo_panic("%s", text);
+}
+#endif
+
 #define msgb_l1(m)     ((void *)(m->l1h))
 #define msgb_l2(m)     ((void *)(m->l2h))
 #define msgb_l3(m)     ((void *)(m->l3h))
-#define msgb_sms(m)    ((void *)(m->smsh))
+#define msgb_sms(m)    ((void *)(m->l4h))
 
 static inline unsigned int msgb_l1len(const struct msgb *msgb)
 {
@@ -92,9 +92,24 @@ static inline unsigned int msgb_headlen(const struct msgb *msgb)
 {
        return msgb->len - msgb->data_len;
 }
+
+static inline int msgb_tailroom(const struct msgb *msgb)
+{
+       return (msgb->head + msgb->data_len) - msgb->tail;
+}
+
+static inline int msgb_headroom(const struct msgb *msgb)
+{
+       return (msgb->data - msgb->head);
+}
+
 static inline unsigned char *msgb_put(struct msgb *msgb, unsigned int len)
 {
        unsigned char *tmp = msgb->tail;
+#ifdef MSGB_DEBUG
+       if (msgb_tailroom(msgb) < len)
+               msgb_abort(msgb, "Not enough tailroom\n");
+#endif
        msgb->tail += len;
        msgb->len += len;
        return tmp;
@@ -142,6 +157,10 @@ static inline uint32_t msgb_get_u32(struct msgb *msgb)
 }
 static inline unsigned char *msgb_push(struct msgb *msgb, unsigned int len)
 {
+#ifdef MSGB_DEBUG
+       if (msgb_headroom(msgb) < len)
+               msgb_abort(msgb, "Not enough headroom\n");
+#endif
        msgb->data -= len;
        msgb->len += len;
        return msgb->data;
@@ -151,10 +170,6 @@ static inline unsigned char *msgb_pull(struct msgb *msgb, unsigned int len)
        msgb->len -= len;
        return msgb->data += len;
 }
-static inline int msgb_tailroom(const struct msgb *msgb)
-{
-       return (msgb->head + msgb->data_len) - msgb->tail;
-}
 
 /* increase the headroom of an empty msgb, reducing the tailroom */
 static inline void msgb_reserve(struct msgb *msg, int len)