libosmo-netif  0.3.0.5-7028
Osmocom network interface library
 All Data Structures Files Functions Modules
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 
32 struct osmux_hdr {
33 #if OSMO_IS_BIG_ENDIAN
34  uint8_t rtp_m:1,
35  ft:2,
36  ctr:3,
37  amr_f:1,
38  amr_q:1;
39 #elif OSMO_IS_LITTLE_ENDIAN
40  uint8_t amr_q:1,
41  amr_f:1,
42  ctr:3,
43  ft:2,
44  rtp_m: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_BIG_ENDIAN
50  uint8_t amr_ft:4,
51  amr_cmr:4;
52 #elif OSMO_IS_LITTLE_ENDIAN
53  uint8_t amr_cmr:4,
54  amr_ft:4;
55 #endif
56 } __attribute__((packed));
57 
58 /* one to handle all existing RTP flows */
60  uint8_t osmux_seq;
61  uint8_t batch_factor;
62  uint16_t batch_size;
63 
64  struct {
65  uint32_t input_rtp_msgs;
66  uint32_t output_osmux_msgs;
67  uint64_t input_rtp_bytes;
68  uint64_t output_osmux_bytes;
69  } stats;
70 
71  void (*deliver)(struct msgb *msg, void *data);
72  void *data;
73  char *internal_data; /* internal data to store batch */
74 };
75 
76 #define OSMUX_MAX_CONCURRENT_CALLS 8
77 
78 /* one per OSmux circuit_id, ie. one per RTP flow. */
80  uint16_t rtp_seq;
81  uint32_t rtp_timestamp;
82  uint32_t rtp_ssrc;
83  uint8_t osmux_seq_ack; /* Latest received seq num */
84  struct osmo_timer_list timer;
85  struct llist_head list;
86  void (*tx_cb)(struct msgb *msg, void *data); /* Used defined rtp tx callback */
87  void *data; /* User defined opaque data structure */
88 };
89 
90 static inline uint8_t *osmux_get_payload(struct osmux_hdr *osmuxh)
91 {
92  return (uint8_t *)osmuxh + sizeof(struct osmux_hdr);
93 }
94 
95 int osmux_snprintf(char *buf, size_t size, struct msgb *msg);
96 
97 /* 1500 - sizeof(iphdr) = 20 bytes - sizeof(udphdr) = 8 bytes. */
98 #define OSMUX_BATCH_DEFAULT_MAX 1472
99 
100 void osmux_xfrm_input_init(struct osmux_in_handle *h);
101 void osmux_xfrm_input_fini(struct osmux_in_handle *h);
102 
103 int osmux_xfrm_input_open_circuit(struct osmux_in_handle *h, int ccid, int dummy);
104 void osmux_xfrm_input_close_circuit(struct osmux_in_handle *h, int ccid);
105 
106 int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid);
107 void osmux_xfrm_input_deliver(struct osmux_in_handle *h);
108 
109 void osmux_xfrm_output_init(struct osmux_out_handle *h, uint32_t rtp_ssrc);
110 void osmux_xfrm_output_set_tx_cb(struct osmux_out_handle *h, void (*tx_cb)(struct msgb *msg, void *data), void *data);
111 int osmux_xfrm_output(struct osmux_hdr *osmuxh, struct osmux_out_handle *h, struct llist_head *list) OSMO_DEPRECATED("Use osmux_xfrm_output_sched() instead");
112 int osmux_xfrm_output_sched(struct osmux_out_handle *h, struct osmux_hdr *osmuxh);
114 struct osmux_hdr *osmux_xfrm_output_pull(struct msgb *msg);
115 
116 void 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");
117 
120 #endif
int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid)
Definition: osmux.c:805
Definition: osmux.h:79
int osmux_snprintf(char *buf, size_t size, struct msgb *msg)
Definition: osmux.c:1068
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:883
Definition: osmux.h:59
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
void osmux_xfrm_output_flush(struct osmux_out_handle *h)
Flush all scheduled RTP packets still pending to be transmitted.
Definition: osmux.c:322
Definition: osmux.h:32