core/conv: Add support for other termination types (trunc & tail biting)

Note that this breaks the ABI and the low level API. But it shouldn't
break the high level API, nor the conv code definitions (because fields
default to 0, and for new fields '0' is the previous behavior)

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
diff --git a/include/osmocom/core/conv.h b/include/osmocom/core/conv.h
index ba490b4..159a055 100644
--- a/include/osmocom/core/conv.h
+++ b/include/osmocom/core/conv.h
@@ -35,6 +35,19 @@
 
 #include <osmocom/core/bits.h>
 
+/*! \brief possibe termination types
+ *
+ *  The termination type will determine which state the encoder/decoder
+ *  can start/end with. This is mostly taken care of in the high level API
+ *  call. So if you use the low level API, you must take care of making the
+ *  proper calls yourself.
+ */
+enum osmo_conv_term {
+	CONV_TERM_FLUSH = 0,	/*!< \brief Flush encoder state */
+	CONV_TERM_TRUNCATION,	/*!< \brief Direct truncation */
+	CONV_TERM_TAIL_BITING,	/*!< \brief Tail biting */
+};
+
 /*! \brief structure describing a given convolutional code
  *
  *  The only required fields are N,K and the next_output/next_state arrays. The
@@ -46,6 +59,8 @@
 	int K;				/*!< \brief Constraint length */
 	int len;			/*!< \brief # of data bits */
 
+	enum osmo_conv_term term;	/*!< \brief Termination type */
+
 	const uint8_t (*next_output)[2];/*!< \brief Next output array */
 	const uint8_t (*next_state)[2];	/*!< \brief Next state array  */
 
@@ -70,9 +85,11 @@
 
 void osmo_conv_encode_init(struct osmo_conv_encoder *encoder,
                            const struct osmo_conv_code *code);
+void osmo_conv_encode_load_state(struct osmo_conv_encoder *encoder,
+                                 const ubit_t *input);
 int  osmo_conv_encode_raw(struct osmo_conv_encoder *encoder,
                           const ubit_t *input, ubit_t *output, int n);
-int  osmo_conv_encode_finish(struct osmo_conv_encoder *encoder, ubit_t *output);
+int  osmo_conv_encode_flush(struct osmo_conv_encoder *encoder, ubit_t *output);
 
 	/* All-in-one */
 int  osmo_conv_encode(const struct osmo_conv_code *code,
@@ -100,16 +117,18 @@
 };
 
 void osmo_conv_decode_init(struct osmo_conv_decoder *decoder,
-                           const struct osmo_conv_code *code, int len);
-void osmo_conv_decode_reset(struct osmo_conv_decoder *decoder);
+                           const struct osmo_conv_code *code,
+                           int len, int start_state);
+void osmo_conv_decode_reset(struct osmo_conv_decoder *decoder, int start_state);
+void osmo_conv_decode_rewind(struct osmo_conv_decoder *decoder);
 void osmo_conv_decode_deinit(struct osmo_conv_decoder *decoder);
 
 int osmo_conv_decode_scan(struct osmo_conv_decoder *decoder,
                           const sbit_t *input, int n);
-int osmo_conv_decode_finish(struct osmo_conv_decoder *decoder,
-                            const sbit_t *input);
+int osmo_conv_decode_flush(struct osmo_conv_decoder *decoder,
+                           const sbit_t *input);
 int osmo_conv_decode_get_output(struct osmo_conv_decoder *decoder,
-                                ubit_t *output, int has_finish);
+                                ubit_t *output, int has_flush, int end_state);
 
 	/* All-in-one */
 int osmo_conv_decode(const struct osmo_conv_code *code,