aboutsummaryrefslogtreecommitdiffstats
path: root/include/openbsc/subchan_demux.h
blob: b71c856d9ee04496b3904b9ec136aa5b01efc659 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef _SUBCH_DEMUX_H
#define _SUBCH_DEMUX_H
/* A E1 sub-channel (de)multiplexer with TRAU frame sync */

/* (C) 2009 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 Affero General Public License as published by
 * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdint.h>
#include <osmocom/core/linuxlist.h>

#define NR_SUBCH	4
#define TRAU_FRAME_SIZE	40
#define TRAU_FRAME_BITS	(TRAU_FRAME_SIZE*8)

/***********************************************************************/
/* DEMULTIPLEXER */
/***********************************************************************/

struct demux_subch {
	uint8_t out_bitbuf[TRAU_FRAME_BITS];
	uint16_t out_idx; /* next bit to be written in out_bitbuf */
	/* number of consecutive zeros that we have received (for sync) */
	unsigned int consecutive_zeros;
	/* are we in TRAU frame sync or not? */
	unsigned int in_sync;
};

struct subch_demux {
	/* bitmask of currently active subchannels */
	uint8_t chan_activ;
	/* one demux_subch struct for every subchannel */
	struct demux_subch subch[NR_SUBCH];
	/* callback to be called once we have received a complete
	 * frame on a given subchannel */
	int (*out_cb)(struct subch_demux *dmx, int ch, uint8_t *data, int len,
		      void *);
	/* user-provided data, transparently passed to out_cb() */
	void *data;
};

/* initialize one demultiplexer instance */
int subch_demux_init(struct subch_demux *dmx);

/* feed 'len' number of muxed bytes into the demultiplexer */
int subch_demux_in(struct subch_demux *dmx, uint8_t *data, int len);

/* activate decoding/processing for one subchannel */
int subch_demux_activate(struct subch_demux *dmx, int subch);

/* deactivate decoding/processing for one subchannel */
int subch_demux_deactivate(struct subch_demux *dmx, int subch);

/***********************************************************************/
/* MULTIPLEXER */
/***********************************************************************/

/* one element in the tx_queue of a muxer sub-channel */
struct subch_txq_entry {
	struct llist_head list;

	unsigned int bit_len;	/* total number of bits in 'bits' */
	unsigned int next_bit;	/* next bit to be transmitted */

	uint8_t bits[0];	/* one bit per byte */
};

struct mux_subch {
	struct llist_head tx_queue;
};

/* structure representing one instance of the subchannel muxer */
struct subch_mux {
	struct mux_subch subch[NR_SUBCH];
};

/* initialize a subchannel muxer instance */
int subchan_mux_init(struct subch_mux *mx);

/* request the output of 'len' multiplexed bytes */
int subchan_mux_out(struct subch_mux *mx, uint8_t *data, int len);

/* enqueue some data into one sub-channel of the muxer */
int subchan_mux_enqueue(struct subch_mux *mx, int s_nr, const uint8_t *data,
			int len);

#endif /* _SUBCH_DEMUX_H */