libosmo-netif 1.4.0.12-5cce.202312042026
Osmocom network interface library
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
18/* OSmux header:
19 *
20 * rtp_m (1 bit): RTP M field (RFC3550, RFC4867)
21 * ft (2 bits): 0=signalling, 1=voice, 2=dummy
22 * ctr (3 bits): Number of batched AMR payloads (starting 0)
23 * amr_f (1 bit): AMR F field (RFC3267)
24 * amr_q (1 bit): AMR Q field (RFC3267)
25 * seq (8 bits): Combination of RTP timestamp and seq. number
26 * circuit_id (8 bits): Circuit ID, ie. Call identifier.
27 * amr_ft (4 bits): AMR FT field (RFC3267)
28 * amr_cmr (4 bits): AMR CMT field (RFC3267)
29 */
30
31#define OSMUX_FT_SIGNAL 0
32#define OSMUX_FT_VOICE_AMR 1
33#define OSMUX_FT_DUMMY 2
34
35struct osmux_hdr {
36#if OSMO_IS_LITTLE_ENDIAN
37 uint8_t amr_q:1,
38 amr_f:1,
39 ctr:3,
40 ft:2,
41 rtp_m:1;
42#elif OSMO_IS_BIG_ENDIAN
43/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */
44 uint8_t rtp_m:1, ft:2, ctr:3, amr_f:1, amr_q:1;
45#endif
46 uint8_t seq;
47#define OSMUX_CID_MAX 255 /* determined by circuit_id */
48 uint8_t circuit_id;
49#if OSMO_IS_LITTLE_ENDIAN
50 uint8_t amr_cmr:4,
51 amr_ft:4;
52#elif OSMO_IS_BIG_ENDIAN
53/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */
54 uint8_t amr_ft:4, amr_cmr:4;
55#endif
56 uint8_t data[0];
57} __attribute__((packed));
58
59/* one to handle all existing RTP flows */
61 /* Initial Osmux seqnum for each circuit, set during osmux_xfrm_input_open_circuit() */
62 uint8_t osmux_seq;
63 uint8_t batch_factor;
64 uint16_t batch_size;
65
66 struct {
67 uint32_t input_rtp_msgs;
68 uint32_t output_osmux_msgs;
69 uint64_t input_rtp_bytes;
70 uint64_t output_osmux_bytes;
71 } stats;
72
73 void (*deliver)(struct msgb *msg, void *data);
74 void *data;
75 char *internal_data; /* internal data to store batch */
76};
77
78#define OSMUX_MAX_CONCURRENT_CALLS 8
79
80typedef struct msgb *(*rtp_msgb_alloc_cb_t)(void *rtp_msgb_alloc_priv_data,
81 unsigned int msg_len);
82/* one per OSmux circuit_id, ie. one per RTP flow. */
84 uint16_t rtp_seq;
85 uint32_t rtp_timestamp;
86 uint32_t rtp_ssrc;
87 uint8_t rtp_payload_type;
88 uint8_t osmux_seq_ack; /* Latest received seq num */
89 struct osmo_timer_list timer;
90 struct llist_head list;
91 void (*tx_cb)(struct msgb *msg, void *data); /* Used defined rtp tx callback */
92 void *data; /* User defined opaque data structure */
93 rtp_msgb_alloc_cb_t rtp_msgb_alloc_cb; /* User defined msgb alloc function for generated RTP pkts */
94 void *rtp_msgb_alloc_cb_data; /* Opaque data pointer set by user and passed in rtp_msgb_alloc_cb() */
95};
96
97static inline uint8_t *osmux_get_payload(struct osmux_hdr *osmuxh)
98{
99 return (uint8_t *)osmuxh + sizeof(struct osmux_hdr);
100}
101
102int osmux_snprintf(char *buf, size_t size, struct msgb *msg);
103
104/* 1500 - sizeof(iphdr) = 20 bytes - sizeof(udphdr) = 8 bytes. */
105#define OSMUX_BATCH_DEFAULT_MAX 1472
106
107struct osmux_in_handle *osmux_xfrm_input_alloc(void *ctx);
108void osmux_xfrm_input_init(struct osmux_in_handle *h) OSMO_DEPRECATED("Use osmux_xfrm_input_alloc() instead");
109void osmux_xfrm_input_fini(struct osmux_in_handle *h) OSMO_DEPRECATED("Use talloc_free() instead");
110void osmux_xfrm_input_set_name(struct osmux_in_handle *h, const char *name);
111int osmux_xfrm_input_set_batch_factor(struct osmux_in_handle *h, uint8_t batch_factor);
112void osmux_xfrm_input_set_batch_size(struct osmux_in_handle *h, uint16_t batch_size);
113void osmux_xfrm_input_set_initial_seqnum(struct osmux_in_handle *h, uint8_t osmux_seqnum);
114void osmux_xfrm_input_set_deliver_cb(struct osmux_in_handle *h, void (*deliver_cb)(struct msgb *msg, void *data), void *data);
115void *osmux_xfrm_input_get_deliver_cb_data(struct osmux_in_handle *h);
116
117int osmux_xfrm_input_open_circuit(struct osmux_in_handle *h, int ccid, int dummy);
118void osmux_xfrm_input_close_circuit(struct osmux_in_handle *h, int ccid);
119
120int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid);
121void osmux_xfrm_input_deliver(struct osmux_in_handle *h);
122
124void 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");
125void 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");
126void osmux_xfrm_output_set_rtp_ssrc(struct osmux_out_handle *h, uint32_t rtp_ssrc);
127void osmux_xfrm_output_set_rtp_pl_type(struct osmux_out_handle *h, uint32_t rtp_payload_type);
128void osmux_xfrm_output_set_tx_cb(struct osmux_out_handle *h, void (*tx_cb)(struct msgb *msg, void *data), void *data);
129void osmux_xfrm_output_set_rtp_msgb_alloc_cb(struct osmux_out_handle *h, rtp_msgb_alloc_cb_t cb, void *cb_data);
130int osmux_xfrm_output_sched(struct osmux_out_handle *h, struct osmux_hdr *osmuxh);
132struct osmux_hdr *osmux_xfrm_output_pull(struct msgb *msg);
135#endif
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
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
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
struct osmux_out_handle * osmux_xfrm_output_alloc(void *ctx)
Allocate a new osmux out handle.
Definition: osmux_output.c:320
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
int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid)
Definition: osmux_input.c:617
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
int osmux_snprintf(char *buf, size_t size, struct msgb *msg)
Definition: osmux.c:108
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
Definition: osmux.h:35
Definition: osmux.h:60
Definition: osmux.h:83