fix off-by-one error in OSMO_NUM_DLIB
[osmocom-bb.git] / include / osmocom / core / gsmtap_util.h
1 #ifndef _GSMTAP_UTIL_H
2 #define _GSMTAP_UTIL_H
3
4 #include <stdint.h>
5 #include <osmocom/core/write_queue.h>
6 #include <osmocom/core/select.h>
7
8 /* convert RSL channel number to GSMTAP channel type */
9 uint8_t chantype_rsl2gsmtap(uint8_t rsl_chantype, uint8_t rsl_link_id);
10
11 /* generate msgb from data + metadata */
12 struct msgb *gsmtap_makemsg(uint16_t arfcn, uint8_t ts, uint8_t chan_type,
13                             uint8_t ss, uint32_t fn, int8_t signal_dbm,
14                             uint8_t snr, const uint8_t *data, unsigned int len);
15
16 /* one gsmtap instance */
17 struct gsmtap_inst {
18         int ofd_wq_mode;
19         struct osmo_wqueue wq;
20         struct osmo_fd sink_ofd;
21 };
22
23 static inline int gsmtap_inst_fd(struct gsmtap_inst *gti)
24 {
25         return gti->wq.bfd.fd;
26 }
27
28 /* Open a GSMTAP source (sending) socket, conncet it to host/port and
29  * return resulting fd */
30 int gsmtap_source_init_fd(const char *host, uint16_t port);
31
32 /* Add a local sink to an existing GSMTAP source and return fd */
33 int gsmtap_source_add_sink_fd(int gsmtap_fd);
34
35 /* Open GSMTAP source (sending) socket, connect it to host/port,
36  * allocate 'struct gsmtap_inst' and optionally osmo_fd/osmo_wqueue
37  * registration */
38 struct gsmtap_inst *gsmtap_source_init(const char *host, uint16_t port,
39                                         int ofd_wq_mode);
40
41 /* Add a local sink to an existing GSMTAP source instance */
42 int gsmtap_source_add_sink(struct gsmtap_inst *gti);
43
44 /* Send a msgb through a GSMTAP source */
45 int gsmtap_sendmsg(struct gsmtap_inst *gti, struct msgb *msg);
46
47 /* generate a message and send it via GSMTAP */
48 int gsmtap_send(struct gsmtap_inst *gti, uint16_t arfcn, uint8_t ts,
49                 uint8_t chan_type, uint8_t ss, uint32_t fn,
50                 int8_t signal_dbm, uint8_t snr, const uint8_t *data,
51                 unsigned int len);
52
53 #endif /* _GSMTAP_UTIL_H */