diff options
author | Harald Welte <laforge@gnumonks.org> | 2011-05-21 18:54:32 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2011-05-22 11:43:23 +0200 |
commit | 33cb71ac91fb870702dbb71595dba4a554001e3c (patch) | |
tree | ba275acb6376eef01b8dc54a574fea6c2fe47443 /include | |
parent | 825607672215b7a12ea6e201a89cd5209f6d657f (diff) |
gsmtap: rework GSMTAP API to be more future-proof
* use write_queue where applicable
* provide functions that work on raw FD and those with osmo_fd
* add support for multiple gsmtap instances (no global variables)
Diffstat (limited to 'include')
-rw-r--r-- | include/osmocom/core/Makefile.am | 2 | ||||
-rw-r--r-- | include/osmocom/core/gsmtap_util.h | 46 | ||||
-rw-r--r-- | include/osmocom/core/socket.h | 16 |
3 files changed, 54 insertions, 10 deletions
diff --git a/include/osmocom/core/Makefile.am b/include/osmocom/core/Makefile.am index 36988733..3c30362c 100644 --- a/include/osmocom/core/Makefile.am +++ b/include/osmocom/core/Makefile.am @@ -1,5 +1,5 @@ osmocore_HEADERS = signal.h linuxlist.h timer.h select.h msgb.h bits.h \ - bitvec.h statistics.h utils.h \ + bitvec.h statistics.h utils.h socket.h \ gsmtap.h write_queue.h \ logging.h rate_ctr.h gsmtap_util.h \ plugin.h crc16.h panic.h process.h msgfile.h \ diff --git a/include/osmocom/core/gsmtap_util.h b/include/osmocom/core/gsmtap_util.h index 785f5e58..f553c17a 100644 --- a/include/osmocom/core/gsmtap_util.h +++ b/include/osmocom/core/gsmtap_util.h @@ -2,24 +2,52 @@ #define _GSMTAP_UTIL_H #include <stdint.h> +#include <osmocom/core/write_queue.h> +#include <osmocom/core/select.h> /* convert RSL channel number to GSMTAP channel type */ uint8_t chantype_rsl2gsmtap(uint8_t rsl_chantype, uint8_t rsl_link_id); -/* receive a message from L1/L2 and put it in GSMTAP */ +/* generate msgb from data + metadata */ struct msgb *gsmtap_makemsg(uint16_t arfcn, uint8_t ts, uint8_t chan_type, uint8_t ss, uint32_t fn, int8_t signal_dbm, uint8_t snr, const uint8_t *data, unsigned int len); -/* receive a message from L1/L2 and put it in GSMTAP */ -int gsmtap_sendmsg(uint16_t arfcn, uint8_t ts, uint8_t chan_type, uint8_t ss, - uint32_t fn, int8_t signal_dbm, uint8_t snr, - const uint8_t *data, unsigned int len); +/* one gsmtap instance */ +struct gsmtap_inst { + int ofd_wq_mode; + struct osmo_wqueue wq; + struct osmo_fd sink_ofd; +}; -int gsmtap_init(uint32_t dst_ip); +static inline int gsmtap_inst_fd(struct gsmtap_inst *gti) +{ + return gti->wq.bfd.fd; +} -/* Create a local 'gsmtap sink' avoiding the UDP packets being rejected - * with ICMP reject messages */ -int gsmtap_sink_init(uint32_t bind_ip); +/* Open a GSMTAP source (sending) socket, conncet it to host/port and + * return resulting fd */ +int gsmtap_source_init_fd(const char *host, uint16_t port); + +/* Add a local sink to an existing GSMTAP source and return fd */ +int gsmtap_source_add_sink_fd(int gsmtap_fd); + +/* Open GSMTAP source (sending) socket, connect it to host/port, + * allocate 'struct gsmtap_inst' and optionally osmo_fd/osmo_wqueue + * registration */ +struct gsmtap_inst *gsmtap_source_init(const char *host, uint16_t port, + int ofd_wq_mode); + +/* Add a local sink to an existing GSMTAP source instance */ +int gsmtap_source_add_sink(struct gsmtap_inst *gti); + +/* Send a msgb through a GSMTAP source */ +int gsmtap_sendmsg(struct gsmtap_inst *gti, struct msgb *msg); + +/* generate a message and send it via GSMTAP */ +int gsmtap_send(struct gsmtap_inst *gti, uint16_t arfcn, uint8_t ts, + uint8_t chan_type, uint8_t ss, uint32_t fn, + int8_t signal_dbm, uint8_t snr, const uint8_t *data, + unsigned int len); #endif /* _GSMTAP_UTIL_H */ diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h new file mode 100644 index 00000000..3ede524b --- /dev/null +++ b/include/osmocom/core/socket.h @@ -0,0 +1,16 @@ +#ifndef _OSMOCORE_SOCKET_H +#define _OSMOCORE_SOCKET_H + +#include <stdint.h> +#include <sys/socket.h> + +int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto, + const char *host, uint16_t port, int connect0_bind1); + +int osmo_sock_init_sa(struct sockaddr *ss, uint16_t type, + uint8_t proto, int connect0_bind1); + +/* determine if the given address is a local address */ +int osmo_sockaddr_is_local(struct sockaddr *addr, socklen_t addrlen); + +#endif /* _OSMOCORE_SOCKET_H */ |