V.42bis: integration and unit test

 - Edit previously committed V.42bis implementation to function
   outside IAXmodem.
 - Add unit test to verify the correct function of V.42bis

Change-Id: I689413f2541b6def0625ce6bd96f1f488f05f99d
diff --git a/openbsc/src/gprs/Makefile.am b/openbsc/src/gprs/Makefile.am
index c044f24..3970ba6 100644
--- a/openbsc/src/gprs/Makefile.am
+++ b/openbsc/src/gprs/Makefile.am
@@ -93,6 +93,7 @@
 	oap.c \
 	oap_messages.c \
 	gprs_llc_xid.c \
+	v42bis.c \
 	$(NULL)
 osmo_sgsn_LDADD = \
 	$(top_builddir)/src/libcommon/libcommon.a \
diff --git a/openbsc/src/gprs/v42bis.c b/openbsc/src/gprs/v42bis.c
index d025ea9..a04b0af 100644
--- a/openbsc/src/gprs/v42bis.c
+++ b/openbsc/src/gprs/v42bis.c
@@ -29,10 +29,6 @@
 
 /*! \file */
 
-#if defined(HAVE_CONFIG_H)
-#include "config.h"
-#endif
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <inttypes.h>
@@ -42,14 +38,19 @@
 #include <ctype.h>
 #include <assert.h>
 
-#include "spandsp/telephony.h"
-#include "spandsp/logging.h"
-#include "spandsp/bit_operations.h"
-#include "spandsp/async.h"
-#include "spandsp/v42bis.h"
+#include <openbsc/v42bis.h>
+#include <openbsc/v42bis_private.h>
+#include <openbsc/debug.h>
+#include <osmocom/core/talloc.h>
 
-#include "spandsp/private/logging.h"
-#include "spandsp/private/v42bis.h"
+
+#define span_log(x,y,msg, ...) DEBUGP(DV42BIS,msg, ##__VA_ARGS__)
+#define span_log_init(x,y,z)
+#define span_log_set_protocol(x,y)
+
+
+#define FALSE 0
+#define TRUE 1
 
 /* Fixed parameters from the spec. */
 /* Character size (bits) */
@@ -708,7 +709,8 @@
 }
 /*- End of function --------------------------------------------------------*/
 
-SPAN_DECLARE(v42bis_state_t *) v42bis_init(v42bis_state_t *s,
+SPAN_DECLARE(v42bis_state_t *) v42bis_init(const void *ctx,
+                                           v42bis_state_t *s,
                                            int negotiated_p0,
                                            int negotiated_p1,
                                            int negotiated_p2,
@@ -727,7 +729,7 @@
         return NULL;
     if (s == NULL)
     {
-        if ((s = (v42bis_state_t *) malloc(sizeof(*s))) == NULL)
+        if ((s = (v42bis_state_t *) talloc_zero_size(ctx,sizeof(*s))) == NULL)
             return NULL;
     }
     memset(s, 0, sizeof(*s));
@@ -758,6 +760,7 @@
 {
     comp_exit(&s->compress);
     comp_exit(&s->decompress);
+    talloc_free(s);
     return 0;
 }
 /*- End of function --------------------------------------------------------*/