libosmo-netif  0.0.7.20171026
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 
14 /* OSmux header:
15  *
16  * rtp_m (1 bit): RTP M field (RFC3550, RFC4867)
17  * ft (2 bits): 0=signalling, 1=voice, 2=dummy
18  * ctr (3 bits): Number of batched AMR payloads (starting 0)
19  * amr_f (1 bit): AMR F field (RFC3267)
20  * amr_q (1 bit): AMR Q field (RFC3267)
21  * seq (8 bits): Combination of RTP timestamp and seq. number
22  * circuit_id (8 bits): Circuit ID, ie. Call identifier.
23  * amr_ft (4 bits): AMR FT field (RFC3267)
24  * amr_cmr (4 bits): AMR CMT field (RFC3267)
25  */
26 
27 #define OSMUX_FT_SIGNAL 0
28 #define OSMUX_FT_VOICE_AMR 1
29 #define OSMUX_FT_DUMMY 2
30 
31 struct osmux_hdr {
32 #if OSMO_IS_BIG_ENDIAN
33  uint8_t rtp_m:1,
34  ft:2,
35  ctr:3,
36  amr_f:1,
37  amr_q:1;
38 #elif 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 #endif
45  uint8_t seq;
46 #define OSMUX_CID_MAX 255 /* determined by circuit_id */
47  uint8_t circuit_id;
48 #if OSMO_IS_BIG_ENDIAN
49  uint8_t amr_ft:4,
50  amr_cmr:4;
51 #elif OSMO_IS_LITTLE_ENDIAN
52  uint8_t amr_cmr:4,
53  amr_ft:4;
54 #endif
55 } __attribute__((packed));
56 
57 /* one to handle all existing RTP flows */
59  uint8_t osmux_seq;
60  uint8_t batch_factor;
61  uint16_t batch_size;
62 
63  struct {
64  uint32_t input_rtp_msgs;
65  uint32_t output_osmux_msgs;
66  uint64_t input_rtp_bytes;
67  uint64_t output_osmux_bytes;
68  } stats;
69 
70  void (*deliver)(struct msgb *msg, void *data);
71  void *data;
72  char *internal_data; /* internal data to store batch */
73 };
74 
75 #define OSMUX_MAX_CONCURRENT_CALLS 8
76 
77 /* one per OSmux circuit_id, ie. one per RTP flow. */
79  uint16_t rtp_seq;
80  uint32_t rtp_timestamp;
81  uint32_t rtp_ssrc;
82 };
83 
84 static inline uint8_t *osmux_get_payload(struct osmux_hdr *osmuxh)
85 {
86  return (uint8_t *)osmuxh + sizeof(struct osmux_hdr);
87 }
88 
89 int osmux_snprintf(char *buf, size_t size, struct msgb *msg);
90 
91 /* 1500 - sizeof(iphdr) = 20 bytes - sizeof(udphdr) = 8 bytes. */
92 #define OSMUX_BATCH_DEFAULT_MAX 1472
93 
94 void osmux_xfrm_input_init(struct osmux_in_handle *h);
95 void osmux_xfrm_input_fini(struct osmux_in_handle *h);
96 
97 int osmux_xfrm_input_open_circuit(struct osmux_in_handle *h, int ccid, int dummy);
98 void osmux_xfrm_input_close_circuit(struct osmux_in_handle *h, int ccid);
99 
100 int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid);
101 void osmux_xfrm_input_deliver(struct osmux_in_handle *h);
102 
103 void osmux_xfrm_output_init(struct osmux_out_handle *h, uint32_t rtp_ssrc);
104 int osmux_xfrm_output(struct osmux_hdr *osmuxh, struct osmux_out_handle *h, struct llist_head *list);
105 struct osmux_hdr *osmux_xfrm_output_pull(struct msgb *msg);
106 
107 void osmux_tx_sched(struct llist_head *list, void (*tx_cb)(struct msgb *msg, void *data), void *data);
108 
111 #endif
int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid)
Definition: osmux.c:661
Definition: osmux.h:78
int osmux_snprintf(char *buf, size_t size, struct msgb *msg)
Definition: osmux.c:905
Definition: osmux.h:58
Definition: osmux.h:31