Loading...
Searching...
No Matches
i460_mux.h
Go to the documentation of this file.
/*
* (C) 2020 by Harald Welte <laforge@gnumonks.org>
*
* SPDX-License-Identifier: GPL-2.0+
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*/
#pragma once
#include <stdint.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/msgb.h>
#define OSMO_I460_NUM_SUBCHAN 8
/* I.460 sub-slot rate */
enum osmo_i460_rate {
OSMO_I460_RATE_NONE, /* disabled */
OSMO_I460_RATE_64k,
OSMO_I460_RATE_32k,
OSMO_I460_RATE_16k,
OSMO_I460_RATE_8k,
};
struct osmo_i460_subchan;
typedef void (*out_cb_bits_t)(struct osmo_i460_subchan *schan, void *user_data,
const ubit_t *bits, unsigned int num_bits);
typedef void (*out_cb_bytes_t)(struct osmo_i460_subchan *schan, void *user_data,
const uint8_t *bytes, unsigned int num_bytes);
struct osmo_i460_subchan_demux {
uint8_t *out_bitbuf;
unsigned int out_bitbuf_size;
unsigned int out_idx;
out_cb_bits_t out_cb_bits;
out_cb_bytes_t out_cb_bytes;
void *user_data;
};
typedef void (*in_cb_queue_empty_t)(struct osmo_i460_subchan *schan, void *user_data);
struct osmo_i460_subchan_mux {
struct llist_head tx_queue;
in_cb_queue_empty_t in_cb_queue_empty;
void *user_data;
};
struct osmo_i460_subchan {
struct osmo_i460_timeslot *ts; /* back-pointer */
enum osmo_i460_rate rate; /* 8/16/32/64k */
uint8_t bit_offset; /* bit offset inside each byte of the B-channel */
struct osmo_i460_subchan_demux demux;
struct osmo_i460_subchan_mux mux;
};
struct osmo_i460_timeslot {
struct osmo_i460_subchan schan[OSMO_I460_NUM_SUBCHAN];
};
struct osmo_i460_schan_desc {
enum osmo_i460_rate rate;
uint8_t bit_offset;
struct {
/* size (in bits) of the internal buffer; determines granularity */
size_t num_bits;
out_cb_bits_t out_cb_bits;
out_cb_bytes_t out_cb_bytes;
/* opaque user data pointer to pass to out_cb */
void *user_data;
} demux;
struct {
/* call-back function whenever the muxer requires more input data from the sub-channels,
* but has nothing enqueued yet. A typical function would then call osmo_i460_mux_enqueue() */
in_cb_queue_empty_t in_cb_queue_empty;
/* opaque user data pointer to pass to in_cb */
void *user_data;
} mux;
};
void osmo_i460_demux_in(struct osmo_i460_timeslot *ts, const uint8_t *data, size_t data_len);
void osmo_i460_mux_enqueue(struct osmo_i460_subchan *schan, struct msgb *msg);
int osmo_i460_mux_out(struct osmo_i460_timeslot *ts, uint8_t *out, size_t out_len);
void osmo_i460_ts_init(struct osmo_i460_timeslot *ts);
struct osmo_i460_subchan *
osmo_i460_subchan_add(void *ctx, struct osmo_i460_timeslot *ts, const struct osmo_i460_schan_desc *chd);
void osmo_i460_subchan_del(struct osmo_i460_subchan *schan);
int osmo_i460_subchan_count(struct osmo_i460_timeslot *ts);
bits.h
ubit_t
uint8_t ubit_t
osmo_i460_mux_out
int osmo_i460_mux_out(struct osmo_i460_timeslot *ts, uint8_t *out, size_t out_len)
Get multiplexed data from de-multiplexer (for feeding it into an E1 timeslot).
Definition i460_mux.c:269
osmo_i460_subchan_del
void osmo_i460_subchan_del(struct osmo_i460_subchan *schan)
Definition i460_mux.c:382
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:40
osmo_i460_demux_in
void osmo_i460_demux_in(struct osmo_i460_timeslot *ts, const uint8_t *data, size_t data_len)
Feed multiplexed data (from an E1 timeslot) into de-multiplexer.
Definition i460_mux.c:128
OSMO_I460_NUM_SUBCHAN
#define OSMO_I460_NUM_SUBCHAN
Definition i460_mux.h:25
osmo_i460_ts_init
void osmo_i460_ts_init(struct osmo_i460_timeslot *ts)
initialize an I.460 timeslot
Definition i460_mux.c:335
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:163
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:38
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:352
osmo_i460_subchan_count
int osmo_i460_subchan_count(struct osmo_i460_timeslot *ts)
count the number of sub-channels in this I.460 slot.
Definition i460_mux.c:29
osmo_i460_rate
osmo_i460_rate
Definition i460_mux.h:28
OSMO_I460_RATE_NONE
@ OSMO_I460_RATE_NONE
Definition i460_mux.h:29
OSMO_I460_RATE_16k
@ OSMO_I460_RATE_16k
Definition i460_mux.h:32
OSMO_I460_RATE_32k
@ OSMO_I460_RATE_32k
Definition i460_mux.h:31
OSMO_I460_RATE_8k
@ OSMO_I460_RATE_8k
Definition i460_mux.h:33
OSMO_I460_RATE_64k
@ OSMO_I460_RATE_64k
Definition i460_mux.h:30
in_cb_queue_empty_t
void(* in_cb_queue_empty_t)(struct osmo_i460_subchan *schan, void *user_data)
Definition i460_mux.h:56
linuxlist.h
msgb.h
llist_head
msgb
osmo_i460_schan_desc
description of a sub-channel; passed by caller
Definition i460_mux.h:78
osmo_i460_schan_desc::mux
struct osmo_i460_schan_desc::@1 mux
osmo_i460_schan_desc::rate
enum osmo_i460_rate rate
Definition i460_mux.h:79
osmo_i460_schan_desc::num_bits
size_t num_bits
Definition i460_mux.h:83
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:85
osmo_i460_schan_desc::user_data
void * user_data
Definition i460_mux.h:94
osmo_i460_schan_desc::demux
struct osmo_i460_schan_desc::@0 demux
osmo_i460_schan_desc::in_cb_queue_empty
in_cb_queue_empty_t in_cb_queue_empty
Definition i460_mux.h:100
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:92
osmo_i460_schan_desc::bit_offset
uint8_t bit_offset
Definition i460_mux.h:80
osmo_i460_subchan_demux
Definition i460_mux.h:43
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:51
osmo_i460_subchan_demux::out_cb_bytes
out_cb_bytes_t out_cb_bytes
Definition i460_mux.h:52
osmo_i460_subchan_demux::out_bitbuf
uint8_t * out_bitbuf
bit-buffer for output bits
Definition i460_mux.h:45
osmo_i460_subchan_demux::out_idx
unsigned int out_idx
offset of next bit to be written in out_bitbuf
Definition i460_mux.h:49
osmo_i460_subchan_demux::out_bitbuf_size
unsigned int out_bitbuf_size
size of out_bitbuf in bytes
Definition i460_mux.h:47
osmo_i460_subchan_demux::user_data
void * user_data
Definition i460_mux.h:53
osmo_i460_subchan_mux
Definition i460_mux.h:58
osmo_i460_subchan_mux::in_cb_queue_empty
in_cb_queue_empty_t in_cb_queue_empty
Definition i460_mux.h:61
osmo_i460_subchan_mux::tx_queue
struct llist_head tx_queue
list of to-be-transmitted message buffers
Definition i460_mux.h:60
osmo_i460_subchan_mux::user_data
void * user_data
Definition i460_mux.h:62
osmo_i460_subchan
Definition i460_mux.h:65
osmo_i460_subchan::ts
struct osmo_i460_timeslot * ts
Definition i460_mux.h:66
osmo_i460_subchan::demux
struct osmo_i460_subchan_demux demux
Definition i460_mux.h:69
osmo_i460_subchan::bit_offset
uint8_t bit_offset
Definition i460_mux.h:68
osmo_i460_subchan::rate
enum osmo_i460_rate rate
Definition i460_mux.h:67
osmo_i460_subchan::mux
struct osmo_i460_subchan_mux mux
Definition i460_mux.h:70
osmo_i460_timeslot
Definition i460_mux.h:73
osmo_i460_timeslot::schan
struct osmo_i460_subchan schan[OSMO_I460_NUM_SUBCHAN]
Definition i460_mux.h:74