libosmogsm  1.4.0
Osmocom GSM library
i460_mux.h
Go to the documentation of this file.
1 
3 /*
4  * (C) 2020 by Harald Welte <laforge@gnumonks.org>
5  *
6  * SPDX-License-Identifier: GPL-2.0+
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
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301, USA.
22  */
23 
24 #pragma once
25 #include <stdint.h>
26 #include <osmocom/core/bits.h>
27 #include <osmocom/core/linuxlist.h>
28 #include <osmocom/core/msgb.h>
29 
30 /* I.460 sub-slot rate */
32  OSMO_I460_RATE_NONE, /* disabled */
37 };
38 
39 struct osmo_i460_subchan;
40 
41 typedef void (*out_cb_bits_t)(struct osmo_i460_subchan *schan, void *user_data,
42  const ubit_t *bits, unsigned int num_bits);
43 typedef void (*out_cb_bytes_t)(struct osmo_i460_subchan *schan, void *user_data,
44  const uint8_t *bytes, unsigned int num_bytes);
45 
48  uint8_t *out_bitbuf;
50  unsigned int out_bitbuf_size;
52  unsigned int out_idx;
56  void *user_data;
57 };
58 
59 typedef void (*in_cb_queue_empty_t)(struct osmo_i460_subchan *schan, void *user_data);
60 
63  struct llist_head tx_queue;
65  void *user_data;
66 };
67 
69  struct osmo_i460_timeslot *ts; /* back-pointer */
70  enum osmo_i460_rate rate; /* 8/16/32/64k */
71  uint8_t bit_offset; /* bit offset inside each byte of the B-channel */
74 };
75 
77  struct osmo_i460_subchan schan[8];
78 };
79 
82  enum osmo_i460_rate rate;
83  uint8_t bit_offset;
84  struct {
85  /* size (in bits) of the internal buffer; determines granularity */
86  size_t num_bits;
96  /* opaque user data pointer to pass to out_cb */
97  void *user_data;
98  } demux;
99 
100  struct {
101  /* call-back function whenever the muxer requires more input data from the sub-channels,
102  * but has nothing enqueued yet. A typical function would then call osmo_i460_mux_enqueue() */
104  /* opaque user data pointer to pass to in_cb */
105  void *user_data;
106  } mux;
107 };
108 
109 void osmo_i460_demux_in(struct osmo_i460_timeslot *ts, const uint8_t *data, size_t data_len);
110 
111 void osmo_i460_mux_enqueue(struct osmo_i460_subchan *schan, struct msgb *msg);
112 int osmo_i460_mux_out(struct osmo_i460_timeslot *ts, uint8_t *out, size_t out_len);
113 
114 void osmo_i460_ts_init(struct osmo_i460_timeslot *ts);
115 
116 struct osmo_i460_subchan *
117 osmo_i460_subchan_add(void *ctx, struct osmo_i460_timeslot *ts, const struct osmo_i460_schan_desc *chd);
118 
119 void osmo_i460_subchan_del(struct osmo_i460_subchan *schan);
120 
osmo_i460_subchan_demux::out_cb_bits
out_cb_bits_t out_cb_bits
callback to be called once we have received out_bitbuf_size bits
Definition: i460_mux.h:54
osmo_i460_timeslot
Definition: i460_mux.h:76
osmo_i460_schan_desc
description of a sub-channel; passed by caller
Definition: i460_mux.h:81
osmo_i460_subchan_mux::user_data
void * user_data
Definition: i460_mux.h:65
osmo_i460_schan_desc::mux
struct osmo_i460_schan_desc::@8 mux
out_cb_bytes_t
void(* out_cb_bytes_t)(struct osmo_i460_subchan *schan, void *user_data, const uint8_t *bytes, unsigned int num_bytes)
Definition: i460_mux.h:43
msgb.h
msg
uint8_t msg[0]
Definition: gsm_08_08.h:8
osmo_i460_subchan::bit_offset
uint8_t bit_offset
Definition: i460_mux.h:71
osmo_i460_subchan_demux::out_bitbuf
uint8_t * out_bitbuf
bit-buffer for output bits
Definition: i460_mux.h:48
osmo_i460_rate
osmo_i460_rate
Definition: i460_mux.h:31
osmo_i460_subchan_demux
Definition: i460_mux.h:46
osmo_i460_schan_desc::out_cb_bytes
out_cb_bytes_t out_cb_bytes
out_cb_bytes call-back function called whenever we received num_bits.
Definition: i460_mux.h:95
osmo_i460_subchan_demux::out_bitbuf_size
unsigned int out_bitbuf_size
size of out_bitbuf in bytes
Definition: i460_mux.h:50
osmo_i460_schan_desc::num_bits
size_t num_bits
Definition: i460_mux.h:86
OSMO_I460_RATE_32k
@ OSMO_I460_RATE_32k
Definition: i460_mux.h:34
osmo_i460_subchan::mux
struct osmo_i460_subchan_mux mux
Definition: i460_mux.h:73
data
uint8_t data[0]
msgb
OSMO_I460_RATE_NONE
@ OSMO_I460_RATE_NONE
Definition: i460_mux.h:32
osmo_i460_subchan_mux::in_cb_queue_empty
in_cb_queue_empty_t in_cb_queue_empty
Definition: i460_mux.h:64
osmo_i460_mux_out
int osmo_i460_mux_out(struct osmo_i460_timeslot *ts, uint8_t *out, size_t out_len)
Data from E1 timeslot into de-multiplexer.
Definition: i460_mux.c:275
out_cb_bits_t
void(* out_cb_bits_t)(struct osmo_i460_subchan *schan, void *user_data, const ubit_t *bits, unsigned int num_bits)
Definition: i460_mux.h:41
osmo_i460_subchan_demux::out_cb_bytes
out_cb_bytes_t out_cb_bytes
Definition: i460_mux.h:55
osmo_i460_subchan::demux
struct osmo_i460_subchan_demux demux
Definition: i460_mux.h:72
llist_head
osmo_i460_subchan_mux::tx_queue
struct llist_head tx_queue
list of to-be-transmitted message buffers
Definition: i460_mux.h:63
osmo_i460_subchan_demux::out_idx
unsigned int out_idx
offset of next bit to be written in out_bitbuf
Definition: i460_mux.h:52
osmo_i460_schan_desc::out_cb_bits
out_cb_bits_t out_cb_bits
call-back function called whenever we received num_bits
Definition: i460_mux.h:88
in_cb_queue_empty_t
void(* in_cb_queue_empty_t)(struct osmo_i460_subchan *schan, void *user_data)
Definition: i460_mux.h:59
osmo_i460_subchan_del
void osmo_i460_subchan_del(struct osmo_i460_subchan *schan)
Definition: i460_mux.c:388
OSMO_I460_RATE_64k
@ OSMO_I460_RATE_64k
Definition: i460_mux.h:33
osmo_i460_demux_in
void osmo_i460_demux_in(struct osmo_i460_timeslot *ts, const uint8_t *data, size_t data_len)
Data from E1 timeslot into de-multiplexer.
Definition: i460_mux.c:131
osmo_i460_subchan_demux::user_data
void * user_data
Definition: i460_mux.h:56
osmo_i460_subchan
Definition: i460_mux.h:68
osmo_i460_schan_desc::demux
struct osmo_i460_schan_desc::@7 demux
linuxlist.h
osmo_i460_subchan_add
struct osmo_i460_subchan * osmo_i460_subchan_add(void *ctx, struct osmo_i460_timeslot *ts, const struct osmo_i460_schan_desc *chd)
add a new sub-channel to the given timeslot
Definition: i460_mux.c:358
ubit_t
uint8_t ubit_t
osmo_i460_mux_enqueue
void osmo_i460_mux_enqueue(struct osmo_i460_subchan *schan, struct msgb *msg)
enqueue a to-be-transmitted message buffer containing unpacked bits
Definition: i460_mux.c:166
OSMO_I460_RATE_16k
@ OSMO_I460_RATE_16k
Definition: i460_mux.h:35
osmo_i460_timeslot::schan
struct osmo_i460_subchan schan[8]
Definition: i460_mux.h:77
osmo_i460_schan_desc::user_data
void * user_data
Definition: i460_mux.h:97
osmo_i460_schan_desc::in_cb_queue_empty
in_cb_queue_empty_t in_cb_queue_empty
Definition: i460_mux.h:103
osmo_i460_schan_desc::bit_offset
uint8_t bit_offset
Definition: i460_mux.h:83
osmo_i460_subchan::ts
struct osmo_i460_timeslot * ts
Definition: i460_mux.h:69
osmo_i460_subchan_mux
Definition: i460_mux.h:61
bits.h
OSMO_I460_RATE_8k
@ OSMO_I460_RATE_8k
Definition: i460_mux.h:36
osmo_i460_subchan::rate
enum osmo_i460_rate rate
Definition: i460_mux.h:70
osmo_i460_schan_desc::rate
enum osmo_i460_rate rate
Definition: i460_mux.h:82
osmo_i460_ts_init
void osmo_i460_ts_init(struct osmo_i460_timeslot *ts)
initialize an I.460 timeslot
Definition: i460_mux.c:341