From 33cb71ac91fb870702dbb71595dba4a554001e3c Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 21 May 2011 18:54:32 +0200 Subject: 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) --- include/osmocom/core/Makefile.am | 2 +- include/osmocom/core/gsmtap_util.h | 46 ++++++++++++++++++++++++++++++-------- include/osmocom/core/socket.h | 16 +++++++++++++ 3 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 include/osmocom/core/socket.h (limited to 'include/osmocom') 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 +#include +#include /* 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 +#include + +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 */ -- cgit v1.2.3 From e476442cf0e84c65565ace545f5b73602b5f0ffc Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 22 May 2011 12:25:57 +0200 Subject: GSMTAP/socket code: Check for sys/socket.h and conditionally compile --- include/osmocom/core/socket.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include/osmocom') diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h index 3ede524b..a3baa9d5 100644 --- a/include/osmocom/core/socket.h +++ b/include/osmocom/core/socket.h @@ -2,7 +2,8 @@ #define _OSMOCORE_SOCKET_H #include -#include + +struct sockaddr; int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto, const char *host, uint16_t port, int connect0_bind1); @@ -11,6 +12,6 @@ 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); +int osmo_sockaddr_is_local(struct sockaddr *addr, unsigned int addrlen); #endif /* _OSMOCORE_SOCKET_H */ -- cgit v1.2.3 From 68b1574257fdbf4b06d225c116cfa6a2a6929965 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 22 May 2011 21:47:29 +0200 Subject: socket: use listen() and SO_REUSEADDR, new osmo_sock_init_ofd() function osmo_sock_init_ofd() is a wrapper around osmo_sock_init() which will take care of initializing and registering a 'struct osmo_fd' for the newly-created socket. --- include/osmocom/core/socket.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/osmocom') diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h index a3baa9d5..b2601c76 100644 --- a/include/osmocom/core/socket.h +++ b/include/osmocom/core/socket.h @@ -8,6 +8,9 @@ struct sockaddr; 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_ofd(struct osmo_fd *ofd, int family, int type, int 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); -- cgit v1.2.3 From 4185fa5d9b6bf712499b8e65bac4077dd1aa34fa Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 22 May 2011 21:57:15 +0200 Subject: libosmogsm: add ipaccess related header file --- include/osmocom/gsm/protocol/Makefile.am | 2 +- include/osmocom/gsm/protocol/ipaccess.h | 93 ++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 include/osmocom/gsm/protocol/ipaccess.h (limited to 'include/osmocom') diff --git a/include/osmocom/gsm/protocol/Makefile.am b/include/osmocom/gsm/protocol/Makefile.am index 8483f10a..7f6de639 100644 --- a/include/osmocom/gsm/protocol/Makefile.am +++ b/include/osmocom/gsm/protocol/Makefile.am @@ -1,6 +1,6 @@ osmogsm_proto_HEADERS = gsm_03_41.h \ gsm_04_08.h gsm_04_11.h gsm_04_12.h gsm_04_80.h \ gsm_08_08.h gsm_08_58.h \ - gsm_12_21.h + gsm_12_21.h ipaccess.h osmogsm_protodir = $(includedir)/osmocom/gsm/protocol diff --git a/include/osmocom/gsm/protocol/ipaccess.h b/include/osmocom/gsm/protocol/ipaccess.h new file mode 100644 index 00000000..27925725 --- /dev/null +++ b/include/osmocom/gsm/protocol/ipaccess.h @@ -0,0 +1,93 @@ +#ifndef _OSMO_PROTO_IPACCESS_H +#define _OSMO_PROTO_IPACCESS_H + +#include + +#define IPA_TCP_PORT_OML 3002 +#define IPA_TCP_PORT_RSL 3003 + +struct ipaccess_head { + uint16_t len; /* network byte order */ + uint8_t proto; + uint8_t data[0]; +} __attribute__ ((packed)); + +struct ipaccess_head_ext { + uint8_t proto; + uint8_t data[0]; +} __attribute__ ((packed)); + +enum ipaccess_proto { + IPAC_PROTO_RSL = 0x00, + IPAC_PROTO_IPACCESS = 0xfe, + IPAC_PROTO_SCCP = 0xfd, + IPAC_PROTO_OML = 0xff, + + + /* OpenBSC extensions */ + IPAC_PROTO_OSMO = 0xee, + IPAC_PROTO_MGCP_OLD = 0xfc, +}; + +enum ipaccess_proto_ext { + IPAC_PROTO_EXT_CTRL = 0x00, + IPAC_PROTO_EXT_MGCP = 0x01, + IPAC_PROTO_EXT_LAC = 0x02, +}; + +enum ipaccess_msgtype { + IPAC_MSGT_PING = 0x00, + IPAC_MSGT_PONG = 0x01, + IPAC_MSGT_ID_GET = 0x04, + IPAC_MSGT_ID_RESP = 0x05, + IPAC_MSGT_ID_ACK = 0x06, + + /* OpenBSC extension */ + IPAC_MSGT_SCCP_OLD = 0xff, +}; + +enum ipaccess_id_tags { + IPAC_IDTAG_SERNR = 0x00, + IPAC_IDTAG_UNITNAME = 0x01, + IPAC_IDTAG_LOCATION1 = 0x02, + IPAC_IDTAG_LOCATION2 = 0x03, + IPAC_IDTAG_EQUIPVERS = 0x04, + IPAC_IDTAG_SWVERSION = 0x05, + IPAC_IDTAG_IPADDR = 0x06, + IPAC_IDTAG_MACADDR = 0x07, + IPAC_IDTAG_UNIT = 0x08, +}; + +/* + * Firmware specific header + */ +struct sdp_firmware { + char magic[4]; + char more_magic[2]; + uint16_t more_more_magic; + uint32_t header_length; + uint32_t file_length; + char sw_part[20]; + char text1[64]; + char time[12]; + char date[14]; + char text2[10]; + char version[20]; + uint16_t table_offset; + /* stuff i don't know */ +} __attribute__((packed)); + +struct sdp_header_entry { + uint16_t something1; + char text1[64]; + char time[12]; + char date[14]; + char text2[10]; + char version[20]; + uint32_t length; + uint32_t addr1; + uint32_t addr2; + uint32_t start; +} __attribute__((packed)); + +#endif /* _OSMO_PROTO_IPACCESS_H */ -- cgit v1.2.3 From f7a1bcce0cea50650517e305d59e674475f913d0 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 22 May 2011 22:45:16 +0200 Subject: abis_nm: import definitions and common code on A-bis OML from OpenBSC --- include/osmocom/gsm/Makefile.am | 2 +- include/osmocom/gsm/abis_nm.h | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 include/osmocom/gsm/abis_nm.h (limited to 'include/osmocom') diff --git a/include/osmocom/gsm/Makefile.am b/include/osmocom/gsm/Makefile.am index a39d2d04..c3670ec7 100644 --- a/include/osmocom/gsm/Makefile.am +++ b/include/osmocom/gsm/Makefile.am @@ -1,5 +1,5 @@ osmogsm_HEADERS = a5.h comp128.h gsm0808.h gsm48_ie.h mncc.h rxlev_stat.h \ - gsm0480.h gsm48.h gsm_utils.h rsl.h tlv.h + gsm0480.h gsm48.h gsm_utils.h rsl.h tlv.h abis_nm.h SUBDIRS = protocol diff --git a/include/osmocom/gsm/abis_nm.h b/include/osmocom/gsm/abis_nm.h new file mode 100644 index 00000000..04e4575d --- /dev/null +++ b/include/osmocom/gsm/abis_nm.h @@ -0,0 +1,24 @@ +#ifndef _OSMO_GSM_ABIS_NM_H +#define _OSMO_GSM_ABIS_NM_H + +#include +#include + +const enum abis_nm_msgtype abis_nm_reports[4]; +const enum abis_nm_msgtype abis_nm_no_ack_nack[3]; +const enum abis_nm_msgtype abis_nm_sw_load_msgs[9]; +const enum abis_nm_msgtype abis_nm_nacks[33]; + +const char *abis_nm_nack_cause_name(uint8_t cause); +const char *abis_nm_nack_name(uint8_t nack); +const char *abis_nm_event_type_name(uint8_t cause); +const char *abis_nm_severity_name(uint8_t cause); +const struct tlv_definition abis_nm_att_tlvdef; +const char *abis_nm_obj_class_name(uint8_t oc); +const char *abis_nm_opstate_name(uint8_t os); +const char *abis_nm_avail_name(uint8_t avail); +const char *abis_nm_test_name(uint8_t test); +const char *abis_nm_adm_name(uint8_t adm); +void abis_nm_debugp_foh(int ss, struct abis_om_fom_hdr *foh); + +#endif /* _OSMO_GSM_ABIS_NM_H */ -- cgit v1.2.3