Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 1 | #ifndef _GSMTAP_UTIL_H |
| 2 | #define _GSMTAP_UTIL_H |
| 3 | |
| 4 | #include <stdint.h> |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 5 | #include <osmocom/core/write_queue.h> |
| 6 | #include <osmocom/core/select.h> |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 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 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 11 | /* generate msgb from data + metadata */ |
Harald Welte | e34a940 | 2010-06-29 22:31:21 +0200 | [diff] [blame] | 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 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 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 | }; |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 22 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 23 | static inline int gsmtap_inst_fd(struct gsmtap_inst *gti) |
| 24 | { |
| 25 | return gti->wq.bfd.fd; |
| 26 | } |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 27 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 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); |
Harald Welte | d58ba46 | 2011-04-27 10:57:49 +0200 | [diff] [blame] | 52 | |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 53 | #endif /* _GSMTAP_UTIL_H */ |