libosmo-netif 1.6.0.16-c51c Osmocom network interface library

Loading...
Searching...
No Matches
osmux.h
Go to the documentation of this file.
1#ifndef _OSMUX_H_
2#define _OSMUX_H_
3
4#include <osmocom/core/endian.h>
5#include <osmocom/core/timer.h>
6#include <osmocom/core/msgb.h>
7
16#define OSMUX_DEFAULT_PORT 1984
17
32#define OSMUX_FT_SIGNAL 0
33#define OSMUX_FT_VOICE_AMR 1
34#define OSMUX_FT_DUMMY 2
35
37 struct osmux_hdr {
38#if OSMO_IS_LITTLE_ENDIAN
39 uint8_t amr_q:1,
40 amr_f:1,
41 ctr:3,
42 ft:2,
43 rtp_m:1;
44#elif OSMO_IS_BIG_ENDIAN
45/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */
46 uint8_t rtp_m:1, ft:2, ctr:3, amr_f:1, amr_q:1;
47#endif
48 uint8_t seq;
49#define OSMUX_CID_MAX 255 /* determined by circuit_id */
50 uint8_t circuit_id;
51#if OSMO_IS_LITTLE_ENDIAN
52 uint8_t amr_cmr:4,
53 amr_ft:4;
54#elif OSMO_IS_BIG_ENDIAN
55/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */
56 uint8_t amr_ft:4, amr_cmr:4;
57#endif
58 uint8_t data[0];
59} __attribute__((packed));
60
62 struct osmux_in_handle {
64 uint8_t osmux_seq;
65 uint8_t batch_factor;
66 uint16_t batch_size;
67
68 struct {
69 uint32_t input_rtp_msgs;
70 uint32_t output_osmux_msgs;
71 uint64_t input_rtp_bytes;
72 uint64_t output_osmux_bytes;
73 } stats;
74
75 void (*deliver)(struct msgb *msg, void *data);
76 void *data;
77 char *internal_data; /* internal data to store batch */
78};
79
80#define OSMUX_MAX_CONCURRENT_CALLS 8
81
82typedef struct msgb *(*rtp_msgb_alloc_cb_t)(void *rtp_msgb_alloc_priv_data,
83 unsigned int msg_len);
85 struct osmux_out_handle {
86 uint16_t rtp_seq;
87 uint32_t rtp_timestamp;
88 uint32_t rtp_ssrc;
89 uint8_t rtp_payload_type;
90 uint8_t osmux_seq_ack; /* Latest received seq num */
91 struct osmo_timer_list timer;
92 struct llist_head list;
93 void (*tx_cb)(struct msgb *msg, void *data); /* Used defined rtp tx callback */
94 void *data; /* User defined opaque data structure */
95 rtp_msgb_alloc_cb_t rtp_msgb_alloc_cb; /* User defined msgb alloc function for generated RTP pkts */
96 void *rtp_msgb_alloc_cb_data; /* Opaque data pointer set by user and passed in rtp_msgb_alloc_cb() */
97};
98
100static inline uint8_t *osmux_get_payload(struct osmux_hdr *osmuxh)
101{
102 return (uint8_t *)osmuxh + sizeof(struct osmux_hdr);
103}
104
105int osmux_snprintf(char *buf, size_t size, struct msgb *msg);
106
107/* 1500 - sizeof(iphdr) = 20 bytes - sizeof(udphdr) = 8 bytes. */
108#define OSMUX_BATCH_DEFAULT_MAX 1472
109
110struct osmux_in_handle *osmux_xfrm_input_alloc(void *ctx);
111void osmux_xfrm_input_init(struct osmux_in_handle *h) OSMO_DEPRECATED("Use osmux_xfrm_input_alloc() instead");
112void osmux_xfrm_input_fini(struct osmux_in_handle *h) OSMO_DEPRECATED("Use talloc_free() instead");
113void osmux_xfrm_input_set_name(struct osmux_in_handle *h, const char *name);
114int osmux_xfrm_input_set_batch_factor(struct osmux_in_handle *h, uint8_t batch_factor);
115void osmux_xfrm_input_set_batch_size(struct osmux_in_handle *h, uint16_t batch_size);
116void osmux_xfrm_input_set_initial_seqnum(struct osmux_in_handle *h, uint8_t osmux_seqnum);
117void osmux_xfrm_input_set_deliver_cb(struct osmux_in_handle *h, void (*deliver_cb)(struct msgb *msg, void *data), void *data);
118void *osmux_xfrm_input_get_deliver_cb_data(struct osmux_in_handle *h);
119
120int osmux_xfrm_input_open_circuit(struct osmux_in_handle *h, int ccid, int dummy);
121void osmux_xfrm_input_close_circuit(struct osmux_in_handle *h, int ccid);
122
123int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid);
124void osmux_xfrm_input_deliver(struct osmux_in_handle *h);
125
126struct osmux_out_handle *osmux_xfrm_output_alloc(void *ctx);
127void osmux_xfrm_output_init(struct osmux_out_handle *h, uint32_t rtp_ssrc) OSMO_DEPRECATED("Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead");
128void osmux_xfrm_output_init2(struct osmux_out_handle *h, uint32_t rtp_ssrc, uint8_t rtp_payload_type) OSMO_DEPRECATED("Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead");
129void osmux_xfrm_output_set_rtp_ssrc(struct osmux_out_handle *h, uint32_t rtp_ssrc);
130void osmux_xfrm_output_set_rtp_pl_type(struct osmux_out_handle *h, uint32_t rtp_payload_type);
131void osmux_xfrm_output_set_tx_cb(struct osmux_out_handle *h, void (*tx_cb)(struct msgb *msg, void *data), void *data);
132void osmux_xfrm_output_set_rtp_msgb_alloc_cb(struct osmux_out_handle *h, rtp_msgb_alloc_cb_t cb, void *cb_data);
133int osmux_xfrm_output_sched(struct osmux_out_handle *h, struct osmux_hdr *osmuxh);
134void osmux_xfrm_output_flush(struct osmux_out_handle *h);
135struct osmux_hdr *osmux_xfrm_output_pull(struct msgb *msg);
138#endif
osmux_xfrm_output_set_rtp_ssrc
void osmux_xfrm_output_set_rtp_ssrc(struct osmux_out_handle *h, uint32_t rtp_ssrc)
Set SSRC of generated RTP packets from Osmux frames.
Definition osmux_output.c:382
osmux_xfrm_output_set_rtp_pl_type
void osmux_xfrm_output_set_rtp_pl_type(struct osmux_out_handle *h, uint32_t rtp_payload_type)
Set Payload Type of generated RTP packets from Osmux frames.
Definition osmux_output.c:391
osmux_xfrm_input_fini
void osmux_xfrm_input_fini(struct osmux_in_handle *h) OSMO_DEPRECATED("Use talloc_free() instead")
Definition osmux_input.c:852
osmux_xfrm_output_set_tx_cb
void osmux_xfrm_output_set_tx_cb(struct osmux_out_handle *h, void(*tx_cb)(struct msgb *msg, void *data), void *data)
Set transmission callback to call when a generated RTP packet is to be transmitted.
Definition osmux_output.c:356
osmux_xfrm_output_alloc
struct osmux_out_handle * osmux_xfrm_output_alloc(void *ctx)
Allocate a new osmux out handle.
Definition osmux_output.c:320
osmux_xfrm_output_init
void osmux_xfrm_output_init(struct osmux_out_handle *h, uint32_t rtp_ssrc) OSMO_DEPRECATED("Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead")
Definition osmux_output.c:341
osmux_xfrm_input_init
void osmux_xfrm_input_init(struct osmux_in_handle *h) OSMO_DEPRECATED("Use osmux_xfrm_input_alloc() instead")
Definition osmux_input.c:738
osmux_xfrm_output_set_rtp_msgb_alloc_cb
void osmux_xfrm_output_set_rtp_msgb_alloc_cb(struct osmux_out_handle *h, rtp_msgb_alloc_cb_t cb, void *cb_data)
Set callback to call when an RTP packet to be generated is to be allocated.
Definition osmux_output.c:370
osmux_xfrm_input
int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid)
osmux_xfrm_input - add RTP message to OSmux batch
Definition osmux_input.c:616
osmux_xfrm_output_init2
void osmux_xfrm_output_init2(struct osmux_out_handle *h, uint32_t rtp_ssrc, uint8_t rtp_payload_type) OSMO_DEPRECATED("Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead")
Definition osmux_output.c:334
osmux_xfrm_output_flush
void osmux_xfrm_output_flush(struct osmux_out_handle *h)
Flush all scheduled RTP packets still pending to be transmitted.
Definition osmux_output.c:270
osmux_xfrm_input_alloc
struct osmux_in_handle * osmux_xfrm_input_alloc(void *ctx)
Allocate a new osmux in handle (osmux source, tx side)
Definition osmux_input.c:711
osmux_snprintf
int osmux_snprintf(char *buf, size_t size, struct msgb *msg)
Print osmux header fields and payload from msg into buffer buf.
Definition osmux.c:108
osmux_xfrm_output_sched
int osmux_xfrm_output_sched(struct osmux_out_handle *h, struct osmux_hdr *osmuxh)
Generate RTP packets from osmux frame AMR payload set and schedule them for transmission at appropria...
Definition osmux_output.c:218
osmux_hdr
Osmux protocol header.
Definition osmux.h:37
osmux_in_handle
one to handle all existing RTP flows
Definition osmux.h:62
osmux_in_handle::osmux_seq
uint8_t osmux_seq
Initial Osmux seqnum for each circuit, set during osmux_xfrm_input_open_circuit()
Definition osmux.h:64
osmux_out_handle
one per OSmux circuit_id, ie.
Definition osmux.h:85