libosmo-netif 1.1.0
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
15/* OSmux header:
16 *
17 * rtp_m (1 bit): RTP M field (RFC3550, RFC4867)
18 * ft (2 bits): 0=signalling, 1=voice, 2=dummy
19 * ctr (3 bits): Number of batched AMR payloads (starting 0)
20 * amr_f (1 bit): AMR F field (RFC3267)
21 * amr_q (1 bit): AMR Q field (RFC3267)
22 * seq (8 bits): Combination of RTP timestamp and seq. number
23 * circuit_id (8 bits): Circuit ID, ie. Call identifier.
24 * amr_ft (4 bits): AMR FT field (RFC3267)
25 * amr_cmr (4 bits): AMR CMT field (RFC3267)
26 */
27
28#define OSMUX_FT_SIGNAL 0
29#define OSMUX_FT_VOICE_AMR 1
30#define OSMUX_FT_DUMMY 2
31
32struct osmux_hdr {
33#if OSMO_IS_LITTLE_ENDIAN
34 uint8_t amr_q:1,
35 amr_f:1,
36 ctr:3,
37 ft:2,
38 rtp_m:1;
39#elif OSMO_IS_BIG_ENDIAN
40/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
41 uint8_t rtp_m:1, ft:2, ctr:3, amr_f:1, amr_q:1;
42#endif
43 uint8_t seq;
44#define OSMUX_CID_MAX 255 /* determined by circuit_id */
45 uint8_t circuit_id;
46#if OSMO_IS_LITTLE_ENDIAN
47 uint8_t amr_cmr:4,
48 amr_ft:4;
49#elif OSMO_IS_BIG_ENDIAN
50/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
51 uint8_t amr_ft:4, amr_cmr:4;
52#endif
53} __attribute__((packed));
54
55/* one to handle all existing RTP flows */
57 uint8_t osmux_seq;
58 uint8_t batch_factor;
59 uint16_t batch_size;
60
61 struct {
62 uint32_t input_rtp_msgs;
63 uint32_t output_osmux_msgs;
64 uint64_t input_rtp_bytes;
65 uint64_t output_osmux_bytes;
66 } stats;
67
68 void (*deliver)(struct msgb *msg, void *data);
69 void *data;
70 char *internal_data; /* internal data to store batch */
71};
72
73#define OSMUX_MAX_CONCURRENT_CALLS 8
74
75/* one per OSmux circuit_id, ie. one per RTP flow. */
77 uint16_t rtp_seq;
78 uint32_t rtp_timestamp;
79 uint32_t rtp_ssrc;
80 uint8_t rtp_payload_type;
81 uint8_t osmux_seq_ack; /* Latest received seq num */
82 struct osmo_timer_list timer;
83 struct llist_head list;
84 void (*tx_cb)(struct msgb *msg, void *data); /* Used defined rtp tx callback */
85 void *data; /* User defined opaque data structure */
86};
87
88static inline uint8_t *osmux_get_payload(struct osmux_hdr *osmuxh)
89{
90 return (uint8_t *)osmuxh + sizeof(struct osmux_hdr);
91}
92
93int osmux_snprintf(char *buf, size_t size, struct msgb *msg);
94
95/* 1500 - sizeof(iphdr) = 20 bytes - sizeof(udphdr) = 8 bytes. */
96#define OSMUX_BATCH_DEFAULT_MAX 1472
97
98void osmux_xfrm_input_init(struct osmux_in_handle *h);
99void osmux_xfrm_input_fini(struct osmux_in_handle *h);
100
101int osmux_xfrm_input_open_circuit(struct osmux_in_handle *h, int ccid, int dummy);
102void osmux_xfrm_input_close_circuit(struct osmux_in_handle *h, int ccid);
103
104int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid);
105void osmux_xfrm_input_deliver(struct osmux_in_handle *h);
106
107void osmux_xfrm_output_init(struct osmux_out_handle *h, uint32_t rtp_ssrc) OSMO_DEPRECATED("Use osmux_xfrm_output_init2() instead");
108void osmux_xfrm_output_init2(struct osmux_out_handle *h, uint32_t rtp_ssrc, uint8_t rtp_payload_type);
109void osmux_xfrm_output_set_tx_cb(struct osmux_out_handle *h, void (*tx_cb)(struct msgb *msg, void *data), void *data);
110int osmux_xfrm_output(struct osmux_hdr *osmuxh, struct osmux_out_handle *h, struct llist_head *list) OSMO_DEPRECATED("Use osmux_xfrm_output_sched() instead");
111int osmux_xfrm_output_sched(struct osmux_out_handle *h, struct osmux_hdr *osmuxh);
113struct osmux_hdr *osmux_xfrm_output_pull(struct msgb *msg);
114
115void osmux_tx_sched(struct llist_head *list, void (*tx_cb)(struct msgb *msg, void *data), void *data) OSMO_DEPRECATED("Use osmux_xfrm_output_set_tx_cb() instead");
116
119#endif
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.c:882
int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid)
Definition: osmux.c:804
void osmux_xfrm_output_flush(struct osmux_out_handle *h)
Flush all scheduled RTP packets still pending to be transmitted.
Definition: osmux.c:322
int osmux_snprintf(char *buf, size_t size, struct msgb *msg)
Definition: osmux.c:1074
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 appropiat...
Definition: osmux.c:270
Definition: osmux.h:32
Definition: osmux.h:56
Definition: osmux.h:76