blob: a5c5d8ea457f0f97d4e93f1d2b5bc656f856f1c3 [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];
Harald Welte7eb1f622009-02-18 03:40:58 +000037 u_int16_t out_idx; /* next bit to be written in out_bitbuf */
38 unsigned int consecutive_zeros;
Harald Welte54bd94d2009-01-05 19:00:01 +000039};
40
41struct subch_demux {
Harald Welte1fa60c82009-02-09 18:13:26 +000042 /* bitmask of currently active subchannels */
Harald Welte54bd94d2009-01-05 19:00:01 +000043 u_int8_t chan_activ;
Harald Welte1fa60c82009-02-09 18:13:26 +000044 /* one demux_subch struct for every subchannel */
45 struct demux_subch subch[NR_SUBCH];
46 /* callback to be called once we have received a complete
47 * frame on a given subchannel */
Harald Welte54bd94d2009-01-05 19:00:01 +000048 int (*out_cb)(struct subch_demux *dmx, int ch, u_int8_t *data, int len,
49 void *);
Harald Welte1fa60c82009-02-09 18:13:26 +000050 /* user-provided data, transparently passed to out_cb() */
Harald Welte54bd94d2009-01-05 19:00:01 +000051 void *data;
52};
53
Harald Welte1fa60c82009-02-09 18:13:26 +000054/* initialize one demultiplexer instance */
Harald Weltece281c02009-01-05 20:14:14 +000055int subch_demux_init(struct subch_demux *dmx);
Harald Welte1fa60c82009-02-09 18:13:26 +000056
57/* feed 'len' number of muxed bytes into the demultiplexer */
Harald Welte54bd94d2009-01-05 19:00:01 +000058int subch_demux_in(struct subch_demux *dmx, u_int8_t *data, int len);
Harald Welte1fa60c82009-02-09 18:13:26 +000059
60/* activate decoding/processing for one subchannel */
Harald Welte54bd94d2009-01-05 19:00:01 +000061int subch_demux_activate(struct subch_demux *dmx, int subch);
Harald Welte1fa60c82009-02-09 18:13:26 +000062
63/* deactivate decoding/processing for one subchannel */
Harald Welte54bd94d2009-01-05 19:00:01 +000064int subch_demux_deactivate(struct subch_demux *dmx, int subch);
Harald Welte1fa60c82009-02-09 18:13:26 +000065
66/***********************************************************************/
67/* MULTIPLEXER */
68/***********************************************************************/
69
70/* one element in the tx_queue of a muxer sub-channel */
71struct subch_txq_entry {
72 struct llist_head list;
73
74 unsigned int bit_len; /* total number of bits in 'bits' */
75 unsigned int next_bit; /* next bit to be transmitted */
76
77 u_int8_t bits[0]; /* one bit per byte */
78};
79
80struct mux_subch {
81 struct llist_head tx_queue;
82};
83
84/* structure representing one instance of the subchannel muxer */
85struct subch_mux {
86 struct mux_subch subch[NR_SUBCH];
87};
88
89/* initialize a subchannel muxer instance */
90int subchan_mux_init(struct subch_mux *mx);
91
92/* request the output of 'len' multiplexed bytes */
93int subchan_mux_out(struct subch_mux *mx, u_int8_t *data, int len);
94
95/* enqueue some data into one sub-channel of the muxer */
96int subchan_mux_enqueue(struct subch_mux *mx, int s_nr, const u_int8_t *data,
97 int len);
98
Harald Welte54bd94d2009-01-05 19:00:01 +000099#endif /* _SUBCH_DEMUX_H */