blob: 23c9032042ef52baa2db7d70df0e7c46865cde22 [file] [log] [blame]
Harald Welte54bd94d2009-01-05 19:00:01 +00001#ifndef _SUBCH_DEMUX_H
2#define _SUBCH_DEMUX_H
Harald Welte1fa60c82009-02-09 18:13:26 +00003/* A E1 sub-channel (de)multiplexer with TRAU frame sync */
Harald Welte54bd94d2009-01-05 19:00:01 +00004
5/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <sys/types.h>
Harald Welte1fa60c82009-02-09 18:13:26 +000025#include <openbsc/linuxlist.h>
Harald Welte54bd94d2009-01-05 19:00:01 +000026
27#define NR_SUBCH 4
28#define TRAU_FRAME_SIZE 40
29#define TRAU_FRAME_BITS (TRAU_FRAME_SIZE*8)
30
Harald Welte1fa60c82009-02-09 18:13:26 +000031/***********************************************************************/
32/* DEMULTIPLEXER */
33/***********************************************************************/
34
35struct demux_subch {
Harald Welte54bd94d2009-01-05 19:00:01 +000036 u_int8_t out_bitbuf[TRAU_FRAME_BITS];
37 u_int8_t out_idx; /* next bit to be written in out_bitbuf */
38};
39
40struct subch_demux {
Harald Welte1fa60c82009-02-09 18:13:26 +000041 /* bitmask of currently active subchannels */
Harald Welte54bd94d2009-01-05 19:00:01 +000042 u_int8_t chan_activ;
Harald Welte1fa60c82009-02-09 18:13:26 +000043 /* one demux_subch struct for every subchannel */
44 struct demux_subch subch[NR_SUBCH];
45 /* callback to be called once we have received a complete
46 * frame on a given subchannel */
Harald Welte54bd94d2009-01-05 19:00:01 +000047 int (*out_cb)(struct subch_demux *dmx, int ch, u_int8_t *data, int len,
48 void *);
Harald Welte1fa60c82009-02-09 18:13:26 +000049 /* user-provided data, transparently passed to out_cb() */
Harald Welte54bd94d2009-01-05 19:00:01 +000050 void *data;
51};
52
Harald Welte1fa60c82009-02-09 18:13:26 +000053/* initialize one demultiplexer instance */
Harald Weltece281c02009-01-05 20:14:14 +000054int subch_demux_init(struct subch_demux *dmx);
Harald Welte1fa60c82009-02-09 18:13:26 +000055
56/* feed 'len' number of muxed bytes into the demultiplexer */
Harald Welte54bd94d2009-01-05 19:00:01 +000057int subch_demux_in(struct subch_demux *dmx, u_int8_t *data, int len);
Harald Welte1fa60c82009-02-09 18:13:26 +000058
59/* activate decoding/processing for one subchannel */
Harald Welte54bd94d2009-01-05 19:00:01 +000060int subch_demux_activate(struct subch_demux *dmx, int subch);
Harald Welte1fa60c82009-02-09 18:13:26 +000061
62/* deactivate decoding/processing for one subchannel */
Harald Welte54bd94d2009-01-05 19:00:01 +000063int subch_demux_deactivate(struct subch_demux *dmx, int subch);
Harald Welte1fa60c82009-02-09 18:13:26 +000064
65/***********************************************************************/
66/* MULTIPLEXER */
67/***********************************************************************/
68
69/* one element in the tx_queue of a muxer sub-channel */
70struct subch_txq_entry {
71 struct llist_head list;
72
73 unsigned int bit_len; /* total number of bits in 'bits' */
74 unsigned int next_bit; /* next bit to be transmitted */
75
76 u_int8_t bits[0]; /* one bit per byte */
77};
78
79struct mux_subch {
80 struct llist_head tx_queue;
81};
82
83/* structure representing one instance of the subchannel muxer */
84struct subch_mux {
85 struct mux_subch subch[NR_SUBCH];
86};
87
88/* initialize a subchannel muxer instance */
89int subchan_mux_init(struct subch_mux *mx);
90
91/* request the output of 'len' multiplexed bytes */
92int subchan_mux_out(struct subch_mux *mx, u_int8_t *data, int len);
93
94/* enqueue some data into one sub-channel of the muxer */
95int subchan_mux_enqueue(struct subch_mux *mx, int s_nr, const u_int8_t *data,
96 int len);
97
Harald Welte54bd94d2009-01-05 19:00:01 +000098#endif /* _SUBCH_DEMUX_H */