From 6a973bab9c5ae4f139ce30aa02e34e3779b8c5fa Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Wed, 26 Sep 2018 20:49:48 +0200 Subject: build: move include/{mtp,sccp} to include/osmocom/ Anywhere else in the Osmocom code base, we arrange headers in include/osmocom/foo/ and pass -I ${root_srcdir}/include/. This way including an osmocom header always has the format #include whether we are including from the local source tree or from $prefix. For some reason not clear to me, the mtp and sccp folders, even though they are being installed to $prefix/include/osmocom/, were kept *next* to the osmocom/ dir, instead of inside it. Fix that weird situation. The motivation is that I wanted to use a definition from sccp_types.h in a public-API header. That is impossible if it requires #include in a local build, but #include for any other source tree using libosmo-sccp. After this patch, both are identical and including works without quirks. (The other patch that needed this has changed in the meantime on and no longer needs this, but this still makes sense for future hacking.) The installed result does not change, since both mtp/*.h and sccp/*.h have always been installed to $prefix/include/osmocom/{mtp,sccp}/. This merely changes their position in the source tree. The most curious situation before this is that any patch #including might not get a notice that the header didn't exist, but might instead include an older system-installed file. Change-Id: I1209a4ecf9f692a8030b5c93cd281fc9dd58d105 --- configure.ac | 4 +- include/Makefile.am | 2 +- include/mtp/Makefile.am | 2 - include/mtp/mtp_level3.h | 182 ---------------- include/mtp/mtp_pcap.h | 29 --- include/osmocom/Makefile.am | 2 +- include/osmocom/mtp/Makefile.am | 2 + include/osmocom/mtp/mtp_level3.h | 182 ++++++++++++++++ include/osmocom/mtp/mtp_pcap.h | 29 +++ include/osmocom/sccp/Makefile.am | 2 + include/osmocom/sccp/sccp.h | 204 ++++++++++++++++++ include/osmocom/sccp/sccp_types.h | 443 ++++++++++++++++++++++++++++++++++++++ include/sccp/Makefile.am | 2 - include/sccp/sccp.h | 204 ------------------ include/sccp/sccp_types.h | 443 -------------------------------------- src/mtp_pcap.c | 2 +- src/sccp.c | 2 +- src/sccp2sua.c | 2 +- src/sccp_sclc.c | 2 +- src/sccp_scoc.c | 2 +- src/sccp_scrc.c | 2 +- tests/mtp/mtp_parse_test.c | 2 +- tests/sccp/sccp_test.c | 2 +- 23 files changed, 874 insertions(+), 874 deletions(-) delete mode 100644 include/mtp/Makefile.am delete mode 100644 include/mtp/mtp_level3.h delete mode 100644 include/mtp/mtp_pcap.h create mode 100644 include/osmocom/mtp/Makefile.am create mode 100644 include/osmocom/mtp/mtp_level3.h create mode 100644 include/osmocom/mtp/mtp_pcap.h create mode 100644 include/osmocom/sccp/Makefile.am create mode 100644 include/osmocom/sccp/sccp.h create mode 100644 include/osmocom/sccp/sccp_types.h delete mode 100644 include/sccp/Makefile.am delete mode 100644 include/sccp/sccp.h delete mode 100644 include/sccp/sccp_types.h diff --git a/configure.ac b/configure.ac index 7dfb266..acef6f6 100644 --- a/configure.ac +++ b/configure.ac @@ -136,9 +136,9 @@ AC_OUTPUT( libosmo-sccp.pc libosmo-mtp.pc libosmo-xua.pc - include/sccp/Makefile - include/mtp/Makefile include/osmocom/Makefile + include/osmocom/sccp/Makefile + include/osmocom/mtp/Makefile include/osmocom/sigtran/Makefile include/Makefile src/Makefile diff --git a/include/Makefile.am b/include/Makefile.am index 7cd4b57..3578a80 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1 @@ -SUBDIRS = sccp mtp osmocom +SUBDIRS = osmocom diff --git a/include/mtp/Makefile.am b/include/mtp/Makefile.am deleted file mode 100644 index dbd0e79..0000000 --- a/include/mtp/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -mtp_HEADERS = mtp_level3.h mtp_pcap.h -mtpdir = $(includedir)/osmocom/mtp diff --git a/include/mtp/mtp_level3.h b/include/mtp/mtp_level3.h deleted file mode 100644 index d0d24a1..0000000 --- a/include/mtp/mtp_level3.h +++ /dev/null @@ -1,182 +0,0 @@ -/* Q.701-Q.704, Q.706, Q.707 handling code */ -/* - * (C) 2010 by Holger Hans Peter Freyther - * (C) 2010 by On-Waves - * All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#pragma once - -#include - -#include -#include - - -/* - * pssible service information octets.. - */ -#define MTP_NI_NATION_NET 0x02 - -#define MTP_SI_MNT_SNM_MSG 0x00 -#define MTP_SI_MNT_REG_MSG 0x01 -#define MTP_SI_MNT_SCCP 0x03 -#define MTP_SI_MNT_ISUP 0x05 - -/* - * h0 contains the group, h1 the semantic of it - */ - -#define MTP_TST_MSG_GRP 0x01 -#define MTP_PROHIBIT_MSG_GRP 0x04 -#define MTP_SROUTE_MSG_GRP 0x05 -#define MTP_TRF_RESTR_MSG_GRP 0x07 - -/* h1 values for different groups */ -#define MTP_TST_MSG_SLTM 0x01 -#define MTP_TST_MSG_SLTA 0x02 - -#define MTP_RESTR_MSG_ALLWED 0x01 - -/* For the prohibit group */ -#define MTP_PROHIBIT_MSG_SIG 0x01 -#define MTP_PROHIBIT_MSG_TFA 0x05 - -/* For the Signalling-route-set-test */ -#define MTP_SROUTE_MSG_TEST 0x01 - - -#define SCCP_SST 0x03 -#define SCCP_SSP 0x02 -#define SCCP_SSA 0x01 - -#define MTP_LINK_MASK 0x0F -#define MTP_ADDR_MASK 0x3FFF -#define MTP_APOC_MASK 0x3f - - -#if OSMO_IS_LITTLE_ENDIAN -#define MTP_LINK_SLS(addr) ((addr >>28) & MTP_LINK_MASK) -#define MTP_ADDR(link, dpc, opc) \ - (((dpc) & MTP_ADDR_MASK) << 0 | \ - ((opc) & MTP_ADDR_MASK) << 14| \ - ((link) & MTP_LINK_MASK) << 28) -#define MTP_MAKE_APOC(apoc) \ - (apoc & 0x3fff) -#define MTP_READ_DPC(addr) \ - (((addr) >> 0) & MTP_ADDR_MASK) -#define MTP_READ_OPC(addr) \ - (((addr) >> 14) & MTP_ADDR_MASK) -#elif OSMO_IS_BIG_ENDIAN -static inline uint32_t c_swap_32(uint32_t in) -{ - return (((in & 0x000000ff) << 24) | - ((in & 0x0000ff00) << 8) | - ((in & 0x00ff0000) >> 8) | - ((in & 0xff000000) >> 24)); -} -static inline uint16_t c_swap_16(uint16_t in) -{ - return (((in & 0x00ff) << 8) | - (in & 0xff00) >> 8); -} -#define MTP_LINK_SLS(addr) ((c_swap_32(addr)>>28) & MTP_LINK_MASK) -#define MTP_ADDR(link, dpc, opc) \ - c_swap_32(((dpc) & MTP_ADDR_MASK) << 0 | \ - ((opc) & MTP_ADDR_MASK) << 14| \ - ((link) & MTP_LINK_MASK) << 28) -#define MTP_MAKE_APOC(apoc) \ - c_swap_16((apoc & 0x3fff)) -#define MTP_READ_DPC(addr) \ - (c_swap_32(addr) & MTP_ADDR_MASK) -#define MTP_READ_OPC(addr) \ - ((c_swap_32(addr) >> 14) & MTP_ADDR_MASK) -#else -#error "Unknown endian" -#endif - - - -/* - * not the on wire address... - */ -struct mtp_addr { - uint16_t dpc; - uint16_t opc; - uint8_t link; -} __attribute__((packed)); - -/* - * the struct is defined in Q.704 and can be seen in the - * wireshark dissectors too - */ -struct mtp_level_3_hdr { -#if OSMO_IS_LITTLE_ENDIAN - uint8_t ser_ind : 4, - spare : 2, - ni : 2; -#elif OSMO_IS_BIG_ENDIAN - uint8_t ni : 2, - spare : 2, - ser_ind : 4; -#endif - uint32_t addr; - uint8_t data[0]; -} __attribute__((packed)); - -struct mtp_level_3_cmn { -#if OSMO_IS_LITTLE_ENDIAN - uint8_t h0 : 4, - h1 : 4; -#elif OSMO_IS_BIG_ENDIAN - uint8_t h1 : 4, - h0 : 4; -#endif -} __attribute__((packed)); - -struct mtp_level_3_mng { - struct mtp_level_3_cmn cmn; -#if OSMO_IS_LITTLE_ENDIAN - uint8_t spare : 4, - length : 4; -#elif OSMO_IS_BIG_ENDIAN - uint8_t length : 4, - spare : 4; -#endif - uint8_t data[0]; -} __attribute__((packed)); - -struct mtp_level_3_prohib { - struct mtp_level_3_cmn cmn; - - uint16_t apoc; -} __attribute__((packed)); - -struct sccp_con_ctrl_prt_mgt { - uint8_t sst; - uint8_t assn; /* affected sub system number */ - uint16_t apoc; -#if OSMO_IS_LITTLE_ENDIAN - uint8_t mul_ind : 2, - spare : 6; -#elif OSMO_IS_BIG_ENDIAN - uint8_t spare : 6, - mul_ind : 2; -#endif -} __attribute__((packed)); - diff --git a/include/mtp/mtp_pcap.h b/include/mtp/mtp_pcap.h deleted file mode 100644 index 5e8f7d3..0000000 --- a/include/mtp/mtp_pcap.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * (C) 2010 by Holger Hans Peter Freyther - * (C) 2010 by On-Waves - * All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ -#ifndef mtp_pcap_h -#define mtp_pcap_h - -#include - -int mtp_pcap_write_header(int fd); -int mtp_pcap_write_msu(int fd, const uint8_t *data, int length); - -#endif diff --git a/include/osmocom/Makefile.am b/include/osmocom/Makefile.am index 7e86a4b..c4535f3 100644 --- a/include/osmocom/Makefile.am +++ b/include/osmocom/Makefile.am @@ -1 +1 @@ -SUBDIRS = sigtran +SUBDIRS = mtp sccp sigtran diff --git a/include/osmocom/mtp/Makefile.am b/include/osmocom/mtp/Makefile.am new file mode 100644 index 0000000..dbd0e79 --- /dev/null +++ b/include/osmocom/mtp/Makefile.am @@ -0,0 +1,2 @@ +mtp_HEADERS = mtp_level3.h mtp_pcap.h +mtpdir = $(includedir)/osmocom/mtp diff --git a/include/osmocom/mtp/mtp_level3.h b/include/osmocom/mtp/mtp_level3.h new file mode 100644 index 0000000..d0d24a1 --- /dev/null +++ b/include/osmocom/mtp/mtp_level3.h @@ -0,0 +1,182 @@ +/* Q.701-Q.704, Q.706, Q.707 handling code */ +/* + * (C) 2010 by Holger Hans Peter Freyther + * (C) 2010 by On-Waves + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#pragma once + +#include + +#include +#include + + +/* + * pssible service information octets.. + */ +#define MTP_NI_NATION_NET 0x02 + +#define MTP_SI_MNT_SNM_MSG 0x00 +#define MTP_SI_MNT_REG_MSG 0x01 +#define MTP_SI_MNT_SCCP 0x03 +#define MTP_SI_MNT_ISUP 0x05 + +/* + * h0 contains the group, h1 the semantic of it + */ + +#define MTP_TST_MSG_GRP 0x01 +#define MTP_PROHIBIT_MSG_GRP 0x04 +#define MTP_SROUTE_MSG_GRP 0x05 +#define MTP_TRF_RESTR_MSG_GRP 0x07 + +/* h1 values for different groups */ +#define MTP_TST_MSG_SLTM 0x01 +#define MTP_TST_MSG_SLTA 0x02 + +#define MTP_RESTR_MSG_ALLWED 0x01 + +/* For the prohibit group */ +#define MTP_PROHIBIT_MSG_SIG 0x01 +#define MTP_PROHIBIT_MSG_TFA 0x05 + +/* For the Signalling-route-set-test */ +#define MTP_SROUTE_MSG_TEST 0x01 + + +#define SCCP_SST 0x03 +#define SCCP_SSP 0x02 +#define SCCP_SSA 0x01 + +#define MTP_LINK_MASK 0x0F +#define MTP_ADDR_MASK 0x3FFF +#define MTP_APOC_MASK 0x3f + + +#if OSMO_IS_LITTLE_ENDIAN +#define MTP_LINK_SLS(addr) ((addr >>28) & MTP_LINK_MASK) +#define MTP_ADDR(link, dpc, opc) \ + (((dpc) & MTP_ADDR_MASK) << 0 | \ + ((opc) & MTP_ADDR_MASK) << 14| \ + ((link) & MTP_LINK_MASK) << 28) +#define MTP_MAKE_APOC(apoc) \ + (apoc & 0x3fff) +#define MTP_READ_DPC(addr) \ + (((addr) >> 0) & MTP_ADDR_MASK) +#define MTP_READ_OPC(addr) \ + (((addr) >> 14) & MTP_ADDR_MASK) +#elif OSMO_IS_BIG_ENDIAN +static inline uint32_t c_swap_32(uint32_t in) +{ + return (((in & 0x000000ff) << 24) | + ((in & 0x0000ff00) << 8) | + ((in & 0x00ff0000) >> 8) | + ((in & 0xff000000) >> 24)); +} +static inline uint16_t c_swap_16(uint16_t in) +{ + return (((in & 0x00ff) << 8) | + (in & 0xff00) >> 8); +} +#define MTP_LINK_SLS(addr) ((c_swap_32(addr)>>28) & MTP_LINK_MASK) +#define MTP_ADDR(link, dpc, opc) \ + c_swap_32(((dpc) & MTP_ADDR_MASK) << 0 | \ + ((opc) & MTP_ADDR_MASK) << 14| \ + ((link) & MTP_LINK_MASK) << 28) +#define MTP_MAKE_APOC(apoc) \ + c_swap_16((apoc & 0x3fff)) +#define MTP_READ_DPC(addr) \ + (c_swap_32(addr) & MTP_ADDR_MASK) +#define MTP_READ_OPC(addr) \ + ((c_swap_32(addr) >> 14) & MTP_ADDR_MASK) +#else +#error "Unknown endian" +#endif + + + +/* + * not the on wire address... + */ +struct mtp_addr { + uint16_t dpc; + uint16_t opc; + uint8_t link; +} __attribute__((packed)); + +/* + * the struct is defined in Q.704 and can be seen in the + * wireshark dissectors too + */ +struct mtp_level_3_hdr { +#if OSMO_IS_LITTLE_ENDIAN + uint8_t ser_ind : 4, + spare : 2, + ni : 2; +#elif OSMO_IS_BIG_ENDIAN + uint8_t ni : 2, + spare : 2, + ser_ind : 4; +#endif + uint32_t addr; + uint8_t data[0]; +} __attribute__((packed)); + +struct mtp_level_3_cmn { +#if OSMO_IS_LITTLE_ENDIAN + uint8_t h0 : 4, + h1 : 4; +#elif OSMO_IS_BIG_ENDIAN + uint8_t h1 : 4, + h0 : 4; +#endif +} __attribute__((packed)); + +struct mtp_level_3_mng { + struct mtp_level_3_cmn cmn; +#if OSMO_IS_LITTLE_ENDIAN + uint8_t spare : 4, + length : 4; +#elif OSMO_IS_BIG_ENDIAN + uint8_t length : 4, + spare : 4; +#endif + uint8_t data[0]; +} __attribute__((packed)); + +struct mtp_level_3_prohib { + struct mtp_level_3_cmn cmn; + + uint16_t apoc; +} __attribute__((packed)); + +struct sccp_con_ctrl_prt_mgt { + uint8_t sst; + uint8_t assn; /* affected sub system number */ + uint16_t apoc; +#if OSMO_IS_LITTLE_ENDIAN + uint8_t mul_ind : 2, + spare : 6; +#elif OSMO_IS_BIG_ENDIAN + uint8_t spare : 6, + mul_ind : 2; +#endif +} __attribute__((packed)); + diff --git a/include/osmocom/mtp/mtp_pcap.h b/include/osmocom/mtp/mtp_pcap.h new file mode 100644 index 0000000..5e8f7d3 --- /dev/null +++ b/include/osmocom/mtp/mtp_pcap.h @@ -0,0 +1,29 @@ +/* + * (C) 2010 by Holger Hans Peter Freyther + * (C) 2010 by On-Waves + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ +#ifndef mtp_pcap_h +#define mtp_pcap_h + +#include + +int mtp_pcap_write_header(int fd); +int mtp_pcap_write_msu(int fd, const uint8_t *data, int length); + +#endif diff --git a/include/osmocom/sccp/Makefile.am b/include/osmocom/sccp/Makefile.am new file mode 100644 index 0000000..c64db26 --- /dev/null +++ b/include/osmocom/sccp/Makefile.am @@ -0,0 +1,2 @@ +sccp_HEADERS = sccp_types.h sccp.h +sccpdir = $(includedir)/osmocom/sccp diff --git a/include/osmocom/sccp/sccp.h b/include/osmocom/sccp/sccp.h new file mode 100644 index 0000000..4293792 --- /dev/null +++ b/include/osmocom/sccp/sccp.h @@ -0,0 +1,204 @@ +/* + * SCCP management code + * + * (C) 2009, 2010, 2013 by Holger Hans Peter Freyther + * (C) 2009, 2010, 2013 by On-Waves + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef SCCP_H +#define SCCP_H + +#include + +#include +#include + +#include + +#include "sccp_types.h" + +struct msgb; +struct sccp_system; + +enum { + SCCP_CONNECTION_STATE_NONE, + SCCP_CONNECTION_STATE_REQUEST, + SCCP_CONNECTION_STATE_CONFIRM, + SCCP_CONNECTION_STATE_ESTABLISHED, + SCCP_CONNECTION_STATE_RELEASE, + SCCP_CONNECTION_STATE_RELEASE_COMPLETE, + SCCP_CONNECTION_STATE_REFUSED, + SCCP_CONNECTION_STATE_SETUP_ERROR, +}; + +struct sockaddr_sccp { + sa_family_t sccp_family; /* AF_SCCP in the future??? */ + uint8_t sccp_ssn; /* subssystem number for routing */ + + /* TODO fill in address indicator... if that is ever needed */ + + /* optional gti information */ + uint8_t *gti; + int gti_len; + + /* any of SCCP_TITLE_IND_* */ + uint8_t gti_ind; + + int use_poi; + uint8_t poi[2]; + + /* not sure about these */ + /* uint8_t sccp_class; */ +}; + +/* + * parsed structure of an address + */ +struct sccp_address { + struct sccp_called_party_address address; + uint8_t ssn; + uint8_t poi[2]; + + uint8_t *gti_data; + int gti_len; +}; + +struct sccp_optional_data { + uint8_t data_len; + uint8_t data_start; +}; + +struct sccp_connection { + /* public */ + void *data_ctx; + void (*data_cb)(struct sccp_connection *conn, struct msgb *msg, unsigned int len); + + void *state_ctx; + void (*state_cb)(struct sccp_connection *, int old_state); + + struct sccp_source_reference source_local_reference; + struct sccp_source_reference destination_local_reference; + + int connection_state; + + /* private */ + /* list of active connections */ + struct llist_head list; + struct sccp_system *system; + int incoming; +}; + +/** + * system functionality to implement on top of any other transport layer: + * call sccp_system_incoming for incoming data (from the network) + * sccp will call outgoing whenever outgoing data exists + * The conn is NULL for UDT and other messages without a connection + */ +int sccp_system_init(void (*outgoing)(struct sccp_connection *conn, struct msgb *data, void *gctx, void *ctx), void *context); +int sccp_system_incoming_ctx(struct msgb *data, void *ctx); +int sccp_system_incoming(struct msgb *data); + +/** + * Send data on an existing connection + */ +int sccp_connection_write(struct sccp_connection *connection, struct msgb *data); +int sccp_connection_send_it(struct sccp_connection *connection); +int sccp_connection_close(struct sccp_connection *connection, int cause); +int sccp_connection_free(struct sccp_connection *connection); + +/** + * internal.. + */ +int sccp_connection_force_free(struct sccp_connection *conn); + +/** + * Create a new socket. Set your callbacks and then call bind to open + * the connection. + */ +struct sccp_connection *sccp_connection_socket(void); + +/** + * Open the connection and send additional data + */ +int sccp_connection_connect(struct sccp_connection *conn, + const struct sockaddr_sccp *sccp_called, + struct msgb *data); + +/** + * mostly for testing purposes only. Set the accept callback. + * TODO: add true routing information... in analogy to socket, bind, accept + */ +int sccp_connection_set_incoming(const struct sockaddr_sccp *sock, + int (*accept_cb)(struct sccp_connection *connection, void *data), + void *user_data); + +/** + * Send data in terms of unit data. A fixed address indicator will be used. + */ +int sccp_write(struct msgb *data, + const struct sockaddr_sccp *sock_sender, + const struct sockaddr_sccp *sock_target, + int class, void *ctx); +int sccp_set_read(const struct sockaddr_sccp *sock, + int (*read_cb)(struct msgb *msgb, unsigned int, void *user_data), + void *user_data); + +/* generic sock addresses */ +extern const struct sockaddr_sccp sccp_ssn_bssap; + +/* helpers */ +uint32_t sccp_src_ref_to_int(struct sccp_source_reference *ref); +struct sccp_source_reference sccp_src_ref_from_int(uint32_t); + +struct msgb *sccp_create_cr(const struct sccp_source_reference *src_ref, const struct sockaddr_sccp *called, const uint8_t *data, size_t length); +struct msgb *sccp_create_refuse(struct sccp_source_reference *src_ref, int cause, uint8_t *data, int length); +struct msgb *sccp_create_cc(struct sccp_source_reference *src_ref, struct sccp_source_reference *dst_ref); +struct msgb *sccp_create_rlsd(struct sccp_source_reference *src_ref, struct sccp_source_reference *dst_ref, int cause); +struct msgb *sccp_create_dt1(struct sccp_source_reference *dst_ref, uint8_t *data, uint8_t len); +struct msgb *sccp_create_udt(int _class, const struct sockaddr_sccp *sock_sender, + const struct sockaddr_sccp *sock_target, uint8_t *data, int len); + +/** + * Below this are helper functions and structs for parsing SCCP messages + */ +struct sccp_parse_result { + struct sccp_address called; + struct sccp_address calling; + + /* point to the msg packet */ + struct sccp_source_reference *source_local_reference; + struct sccp_source_reference *destination_local_reference; + + /* data pointer */ + int data_len; +}; + +/* + * helper functions for the nat code + */ +int sccp_determine_msg_type(struct msgb *msg); +int sccp_parse_header(struct msgb *msg, struct sccp_parse_result *result); + +/* + * osmocore logging features + */ +void sccp_set_log_area(int log_area); + +#endif diff --git a/include/osmocom/sccp/sccp_types.h b/include/osmocom/sccp/sccp_types.h new file mode 100644 index 0000000..ab7f74f --- /dev/null +++ b/include/osmocom/sccp/sccp_types.h @@ -0,0 +1,443 @@ +/* + * ITU Q.713 defined types for SCCP + * + * (C) 2009 by Holger Hans Peter Freyther + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef SCCP_TYPES_H +#define SCCP_TYPES_H + +#include +#include + +/* Table 1/Q.713 - SCCP message types */ +enum sccp_message_types { + SCCP_MSG_TYPE_CR = 1, + SCCP_MSG_TYPE_CC = 2, + SCCP_MSG_TYPE_CREF = 3, + SCCP_MSG_TYPE_RLSD = 4, + SCCP_MSG_TYPE_RLC = 5, + SCCP_MSG_TYPE_DT1 = 6, + SCCP_MSG_TYPE_DT2 = 7, + SCCP_MSG_TYPE_AK = 8, + SCCP_MSG_TYPE_UDT = 9, + SCCP_MSG_TYPE_UDTS = 10, + SCCP_MSG_TYPE_ED = 11, + SCCP_MSG_TYPE_EA = 12, + SCCP_MSG_TYPE_RSR = 13, + SCCP_MSG_TYPE_RSC = 14, + SCCP_MSG_TYPE_ERR = 15, + SCCP_MSG_TYPE_IT = 16, + SCCP_MSG_TYPE_XUDT = 17, + SCCP_MSG_TYPE_XUDTS = 18, + SCCP_MSG_TYPE_LUDT = 19, + SCCP_MSG_TYPE_LUDTS = 20 +}; + +/* Table 2/Q.713 - SCCP parameter name codes */ +enum sccp_parameter_name_codes { + SCCP_PNC_END_OF_OPTIONAL = 0, + SCCP_PNC_DESTINATION_LOCAL_REFERENCE = 1, + SCCP_PNC_SOURCE_LOCAL_REFERENCE = 2, + SCCP_PNC_CALLED_PARTY_ADDRESS = 3, + SCCP_PNC_CALLING_PARTY_ADDRESS = 4, + SCCP_PNC_PROTOCOL_CLASS = 5, + SCCP_PNC_SEGMENTING = 6, + SCCP_PNC_RECEIVE_SEQ_NUMBER = 7, + SCCP_PNC_SEQUENCING = 8, + SCCP_PNC_CREDIT = 9, + SCCP_PNC_RELEASE_CAUSE = 10, + SCCP_PNC_RETURN_CAUSE = 11, + SCCP_PNC_RESET_CAUSE = 12, + SCCP_PNC_ERROR_CAUSE = 13, + SCCP_PNC_REFUSAL_CAUSE = 14, + SCCP_PNC_DATA = 15, + SCCP_PNC_SEGMENTATION = 16, + SCCP_PNC_HOP_COUNTER = 17, + SCCP_PNC_IMPORTANCE = 18, + SCCP_PNC_LONG_DATA = 19, +}; + +/* Figure 3/Q.713 Called/calling party address */ +enum { + SCCP_TITLE_IND_NONE = 0, + SCCP_TITLE_IND_NATURE_ONLY = 1, + SCCP_TITLE_IND_TRANSLATION_ONLY = 2, + SCCP_TITLE_IND_TRANS_NUM_ENC = 3, + SCCP_TITLE_IND_TRANS_NUM_ENC_NATURE = 4, +}; + +enum { + SCCP_CALL_ROUTE_ON_SSN = 1, + SCCP_CALL_ROUTE_ON_GT = 0, +}; + +struct sccp_called_party_address { +#if OSMO_IS_LITTLE_ENDIAN + uint8_t point_code_indicator : 1, + ssn_indicator : 1, + global_title_indicator : 4, + routing_indicator : 1, + reserved : 1; +#elif OSMO_IS_BIG_ENDIAN + uint8_t reserved : 1, + routing_indicator : 1, + global_title_indicator : 4, + ssn_indicator : 1, + point_code_indicator : 1; +#endif + uint8_t data[0]; +} __attribute__((packed)); + +/* indicator indicates presence in the above order */ + +/* Figure 6/Q.713 */ +struct sccp_signalling_point_code { + uint8_t lsb; +#if OSMO_IS_LITTLE_ENDIAN + uint8_t msb : 6, + reserved : 2; +#elif OSMO_IS_BIG_ENDIAN + uint8_t reserved : 2, + msb : 6; +#endif +} __attribute__((packed)); + +/* SSN == subsystem number */ +enum sccp_subsystem_number { + SCCP_SSN_NOT_KNOWN_OR_USED = 0, + SCCP_SSN_MANAGEMENT = 1, + SCCP_SSN_RESERVED_ITU = 2, + SCCP_SSN_ISDN_USER_PART = 3, + SCCP_SSN_OMAP = 4, /* operation, maint and administration part */ + SCCP_SSN_MAP = 5, /* mobile application part */ + SCCP_SSN_HLR = 6, + SCCP_SSN_VLR = 7, + SCCP_SSN_MSC = 8, + SCCP_SSN_EIC = 9, /* equipent identifier centre */ + SCCP_SSN_AUC = 10, /* authentication centre */ + SCCP_SSN_ISDN_SUPPL_SERVICES = 11, + SCCP_SSN_RESERVED_INTL = 12, + SCCP_SSN_ISDN_EDGE_TO_EDGE = 13, + SCCP_SSN_TC_TEST_RESPONDER = 14, + + /* From GSM 03.03 8.2 */ + SCCP_SSN_BSSAP = 254, + SCCP_SSN_BSSOM = 253, +}; + +/* Q.713, 3.4.2.3 */ +enum { + SCCP_NAI_UNKNOWN = 0, + SCCP_NAI_SUBSCRIBER_NUMBER = 1, + SCCP_NAI_RESERVED_NATIONAL = 2, + SCCP_NAI_NATIONAL_SIGNIFICANT = 3, + SCCP_NAI_INTERNATIONAL = 4, +}; + +struct sccp_global_title { +#if OSMO_IS_LITTLE_ENDIAN + uint8_t nature_of_addr_ind : 7, + odd_even : 1; +#elif OSMO_IS_BIG_ENDIAN + uint8_t odd_even : 1, + nature_of_addr_ind : 7; +#endif + uint8_t data[0]; +} __attribute__((packed)); + +/* Q.713, 3.3 */ +struct sccp_source_reference { + uint8_t octet1; + uint8_t octet2; + uint8_t octet3; +} __attribute__((packed)); + +/* Q.714, 3.6 */ +enum sccp_protocol_class { + SCCP_PROTOCOL_CLASS_0 = 0, + SCCP_PROTOCOL_CLASS_1 = 1, + SCCP_PROTOCOL_CLASS_2 = 2, + SCCP_PROTOCOL_CLASS_3 = 3, +}; + +/* bits 5-8 when class0, class1 is used */ +enum sccp_protocol_options { + SCCP_PROTOCOL_NO_SPECIAL = 0, + SCCP_PROTOCOL_RETURN_MESSAGE = 8, +}; + +enum sccp_release_cause { + SCCP_RELEASE_CAUSE_END_USER_ORIGINATED = 0, + SCCP_RELEASE_CAUSE_END_USER_CONGESTION = 1, + SCCP_RELEASE_CAUSE_END_USER_FAILURE = 2, + SCCP_RELEASE_CAUSE_SCCP_USER_ORIGINATED = 3, + SCCP_RELEASE_CAUSE_REMOTE_PROCEDURE_ERROR = 4, + SCCP_RELEASE_CAUSE_INCONSISTENT_CONN_DATA = 5, + SCCP_RELEASE_CAUSE_ACCESS_FAILURE = 6, + SCCP_RELEASE_CAUSE_ACCESS_CONGESTION = 7, + SCCP_RELEASE_CAUSE_SUBSYSTEM_FAILURE = 8, + SCCP_RELEASE_CAUSE_SUBSYSTEM_CONGESTION = 9, + SCCP_RELEASE_CAUSE_MTP_FAILURE = 10, + SCCP_RELEASE_CAUSE_NETWORK_CONGESTION = 11, + SCCP_RELEASE_CAUSE_EXPIRATION_RESET = 12, + SCCP_RELEASE_CAUSE_EXPIRATION_INACTIVE = 13, + SCCP_RELEASE_CAUSE_RESERVED = 14, + SCCP_RELEASE_CAUSE_UNQUALIFIED = 15, + SCCP_RELEASE_CAUSE_SCCP_FAILURE = 16, +}; + +enum sccp_return_cause { + SCCP_RETURN_CAUSE_NO_TRANSLATION_NATURE = 0, + SCCP_RETURN_CAUSE_NO_TRANSLATION = 1, + SCCP_RETURN_CAUSE_SUBSYSTEM_CONGESTION = 2, + SCCP_RETURN_CAUSE_SUBSYSTEM_FAILURE = 3, + SCCP_RETURN_CAUSE_UNEQUIPPED_USER = 4, + SCCP_RETURN_CAUSE_MTP_FAILURE = 5, + SCCP_RETURN_CAUSE_NETWORK_CONGESTION = 6, + SCCP_RETURN_CAUSE_UNQUALIFIED = 7, + SCCP_RETURN_CAUSE_ERROR_IN_MSG_TRANSPORT = 8, + SCCP_RETURN_CAUSE_ERROR_IN_LOCAL_PROCESSING = 9, + SCCP_RETURN_CAUSE_DEST_CANNOT_PERFORM_REASSEMBLY = 10, + SCCP_RETURN_CAUSE_SCCP_FAILURE = 11, + SCCP_RETURN_CAUSE_HOP_COUNTER_VIOLATION = 12, + SCCP_RETURN_CAUSE_SEGMENTATION_NOT_SUPPORTED= 13, + SCCP_RETURN_CAUSE_SEGMENTATION_FAILURE = 14 +}; + +enum sccp_reset_cause { + SCCP_RESET_CAUSE_END_USER_ORIGINATED = 0, + SCCP_RESET_CAUSE_SCCP_USER_ORIGINATED = 1, + SCCP_RESET_CAUSE_MSG_OUT_OF_ORDER_PS = 2, + SCCP_RESET_CAUSE_MSG_OUT_OF_ORDER_PR = 3, + SCCP_RESET_CAUSE_RPC_OUT_OF_WINDOW = 4, + SCCP_RESET_CAUSE_RPC_INCORRECT_PS = 5, + SCCP_RESET_CAUSE_RPC_GENERAL = 6, + SCCP_RESET_CAUSE_REMOTE_END_USER_OPERATIONAL= 7, + SCCP_RESET_CAUSE_NETWORK_OPERATIONAL = 8, + SCCP_RESET_CAUSE_ACCESS_OPERATIONAL = 9, + SCCP_RESET_CAUSE_NETWORK_CONGESTION = 10, + SCCP_RESET_CAUSE_RESERVED = 11, +}; + +enum sccp_error_cause { + SCCP_ERROR_LRN_MISMATCH_UNASSIGNED = 0, /* local reference number */ + SCCP_ERROR_LRN_MISMATCH_INCONSISTENT = 1, + SCCP_ERROR_POINT_CODE_MISMATCH = 2, + SCCP_ERROR_SERVICE_CLASS_MISMATCH = 3, + SCCP_ERROR_UNQUALIFIED = 4, +}; + +/* ITU=T Q.713 Section 3.15 */ +enum sccp_refusal_cause { + SCCP_REFUSAL_END_USER_ORIGINATED = 0, + SCCP_REFUSAL_END_USER_CONGESTION = 1, + SCCP_REFUSAL_END_USER_FAILURE = 2, + SCCP_REFUSAL_SCCP_USER_ORIGINATED = 3, + SCCP_REFUSAL_DESTINATION_ADDRESS_UKNOWN = 4, + SCCP_REFUSAL_DESTINATION_INACCESSIBLE = 5, + SCCP_REFUSAL_NET_QOS_NON_TRANSIENT = 6, + SCCP_REFUSAL_NET_QOS_TRANSIENT = 7, + SCCP_REFUSAL_ACCESS_FAILURE = 8, + SCCP_REFUSAL_ACCESS_CONGESTION = 9, + SCCP_REFUSAL_SUBSYSTEM_FAILURE = 10, + SCCP_REFUSAL_SUBSYTEM_CONGESTION = 11, + SCCP_REFUSAL_EXPIRATION = 12, + SCCP_REFUSAL_INCOMPATIBLE_USER_DATA = 13, + SCCP_REFUSAL_RESERVED = 14, + SCCP_REFUSAL_UNQUALIFIED = 15, + SCCP_REFUSAL_HOP_COUNTER_VIOLATION = 16, + SCCP_REFUSAL_SCCP_FAILURE = 17, + SCCP_REFUSAL_NO_TRANS_FOR_ADDRESS_NATURE = 18, + SCCP_REFUSAL_UNEQUIPPED_USER = 19, +}; + +/* + * messages... as of Q.713 Chapter 4 + */ +struct sccp_connection_request { + /* mandatory */ + uint8_t type; + struct sccp_source_reference source_local_reference; + uint8_t proto_class; + + + /* variable */ + uint8_t variable_called; +#if VARIABLE + called_party_address +#endif + + /* optional */ + uint8_t optional_start; + +#if OPTIONAL + credit 3 + callingparty var 4-n + data 3-130 + hop_counter 3 + importance 3 + end_of_optional 1 +#endif + + uint8_t data[0]; +} __attribute__((packed)); + +struct sccp_connection_confirm { + /* mandatory */ + uint8_t type; + struct sccp_source_reference destination_local_reference; + struct sccp_source_reference source_local_reference; + uint8_t proto_class; + + /* optional */ + uint8_t optional_start; + + /* optional */ +#if OPTIONAL + credit 3 + called party 4 + data 3-130 + importance 3 + end_of_optional 1 +#endif + + uint8_t data[0]; +} __attribute__((packed)); + +struct sccp_connection_refused { + /* mandatory */ + uint8_t type; + struct sccp_source_reference destination_local_reference; + uint8_t cause; + + /* optional */ + uint8_t optional_start; + + /* optional */ +#if OPTIONAL + called party 4 + data 3-130 + importance 3 + end_of_optional 1 +#endif + + uint8_t data[0]; +} __attribute__((packed)); + +struct sccp_connection_released { + /* mandatory */ + uint8_t type; + struct sccp_source_reference destination_local_reference; + struct sccp_source_reference source_local_reference; + uint8_t release_cause; + + + /* optional */ + uint8_t optional_start; + +#if OPTIONAL + data 3-130 + importance 3 + end_of_optional 1 +#endif + uint8_t data[0]; +} __attribute__((packed)); + +struct sccp_connection_release_complete { + uint8_t type; + struct sccp_source_reference destination_local_reference; + struct sccp_source_reference source_local_reference; +} __attribute__((packed)); + +struct sccp_data_form1 { + /* mandatory */ + uint8_t type; + struct sccp_source_reference destination_local_reference; + uint8_t segmenting; + + /* variable */ + uint8_t variable_start; + +#if VARIABLE + data 2-256; +#endif + + uint8_t data[0]; +} __attribute__((packed)); + + +struct sccp_data_unitdata { + /* mandatory */ + uint8_t type; + uint8_t proto_class; + + + /* variable */ + uint8_t variable_called; + uint8_t variable_calling; + uint8_t variable_data; + +#if VARIABLE + called party address + calling party address +#endif + + uint8_t data[0]; +} __attribute__((packed)); + +struct sccp_data_unitdata_service { + /* mandantory */ + uint8_t type; + uint8_t return_cause; + + + /* variable */ + uint8_t variable_called; + uint8_t variable_calling; + uint8_t variable_data; + +#if VARIABLE + called party address + calling party address +#endif + + uint8_t data[0]; +} __attribute__((packed)); + + +struct sccp_data_it { + /* mandatory */ + uint8_t type; + struct sccp_source_reference destination_local_reference; + struct sccp_source_reference source_local_reference; + uint8_t proto_class; + + uint8_t sequencing[2]; + uint8_t credit; +} __attribute__((packed)); + +struct sccp_proto_err { + uint8_t type; + struct sccp_source_reference destination_local_reference; + uint8_t error_cause; +}; + +#endif diff --git a/include/sccp/Makefile.am b/include/sccp/Makefile.am deleted file mode 100644 index c64db26..0000000 --- a/include/sccp/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -sccp_HEADERS = sccp_types.h sccp.h -sccpdir = $(includedir)/osmocom/sccp diff --git a/include/sccp/sccp.h b/include/sccp/sccp.h deleted file mode 100644 index 4293792..0000000 --- a/include/sccp/sccp.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - * SCCP management code - * - * (C) 2009, 2010, 2013 by Holger Hans Peter Freyther - * (C) 2009, 2010, 2013 by On-Waves - * - * All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef SCCP_H -#define SCCP_H - -#include - -#include -#include - -#include - -#include "sccp_types.h" - -struct msgb; -struct sccp_system; - -enum { - SCCP_CONNECTION_STATE_NONE, - SCCP_CONNECTION_STATE_REQUEST, - SCCP_CONNECTION_STATE_CONFIRM, - SCCP_CONNECTION_STATE_ESTABLISHED, - SCCP_CONNECTION_STATE_RELEASE, - SCCP_CONNECTION_STATE_RELEASE_COMPLETE, - SCCP_CONNECTION_STATE_REFUSED, - SCCP_CONNECTION_STATE_SETUP_ERROR, -}; - -struct sockaddr_sccp { - sa_family_t sccp_family; /* AF_SCCP in the future??? */ - uint8_t sccp_ssn; /* subssystem number for routing */ - - /* TODO fill in address indicator... if that is ever needed */ - - /* optional gti information */ - uint8_t *gti; - int gti_len; - - /* any of SCCP_TITLE_IND_* */ - uint8_t gti_ind; - - int use_poi; - uint8_t poi[2]; - - /* not sure about these */ - /* uint8_t sccp_class; */ -}; - -/* - * parsed structure of an address - */ -struct sccp_address { - struct sccp_called_party_address address; - uint8_t ssn; - uint8_t poi[2]; - - uint8_t *gti_data; - int gti_len; -}; - -struct sccp_optional_data { - uint8_t data_len; - uint8_t data_start; -}; - -struct sccp_connection { - /* public */ - void *data_ctx; - void (*data_cb)(struct sccp_connection *conn, struct msgb *msg, unsigned int len); - - void *state_ctx; - void (*state_cb)(struct sccp_connection *, int old_state); - - struct sccp_source_reference source_local_reference; - struct sccp_source_reference destination_local_reference; - - int connection_state; - - /* private */ - /* list of active connections */ - struct llist_head list; - struct sccp_system *system; - int incoming; -}; - -/** - * system functionality to implement on top of any other transport layer: - * call sccp_system_incoming for incoming data (from the network) - * sccp will call outgoing whenever outgoing data exists - * The conn is NULL for UDT and other messages without a connection - */ -int sccp_system_init(void (*outgoing)(struct sccp_connection *conn, struct msgb *data, void *gctx, void *ctx), void *context); -int sccp_system_incoming_ctx(struct msgb *data, void *ctx); -int sccp_system_incoming(struct msgb *data); - -/** - * Send data on an existing connection - */ -int sccp_connection_write(struct sccp_connection *connection, struct msgb *data); -int sccp_connection_send_it(struct sccp_connection *connection); -int sccp_connection_close(struct sccp_connection *connection, int cause); -int sccp_connection_free(struct sccp_connection *connection); - -/** - * internal.. - */ -int sccp_connection_force_free(struct sccp_connection *conn); - -/** - * Create a new socket. Set your callbacks and then call bind to open - * the connection. - */ -struct sccp_connection *sccp_connection_socket(void); - -/** - * Open the connection and send additional data - */ -int sccp_connection_connect(struct sccp_connection *conn, - const struct sockaddr_sccp *sccp_called, - struct msgb *data); - -/** - * mostly for testing purposes only. Set the accept callback. - * TODO: add true routing information... in analogy to socket, bind, accept - */ -int sccp_connection_set_incoming(const struct sockaddr_sccp *sock, - int (*accept_cb)(struct sccp_connection *connection, void *data), - void *user_data); - -/** - * Send data in terms of unit data. A fixed address indicator will be used. - */ -int sccp_write(struct msgb *data, - const struct sockaddr_sccp *sock_sender, - const struct sockaddr_sccp *sock_target, - int class, void *ctx); -int sccp_set_read(const struct sockaddr_sccp *sock, - int (*read_cb)(struct msgb *msgb, unsigned int, void *user_data), - void *user_data); - -/* generic sock addresses */ -extern const struct sockaddr_sccp sccp_ssn_bssap; - -/* helpers */ -uint32_t sccp_src_ref_to_int(struct sccp_source_reference *ref); -struct sccp_source_reference sccp_src_ref_from_int(uint32_t); - -struct msgb *sccp_create_cr(const struct sccp_source_reference *src_ref, const struct sockaddr_sccp *called, const uint8_t *data, size_t length); -struct msgb *sccp_create_refuse(struct sccp_source_reference *src_ref, int cause, uint8_t *data, int length); -struct msgb *sccp_create_cc(struct sccp_source_reference *src_ref, struct sccp_source_reference *dst_ref); -struct msgb *sccp_create_rlsd(struct sccp_source_reference *src_ref, struct sccp_source_reference *dst_ref, int cause); -struct msgb *sccp_create_dt1(struct sccp_source_reference *dst_ref, uint8_t *data, uint8_t len); -struct msgb *sccp_create_udt(int _class, const struct sockaddr_sccp *sock_sender, - const struct sockaddr_sccp *sock_target, uint8_t *data, int len); - -/** - * Below this are helper functions and structs for parsing SCCP messages - */ -struct sccp_parse_result { - struct sccp_address called; - struct sccp_address calling; - - /* point to the msg packet */ - struct sccp_source_reference *source_local_reference; - struct sccp_source_reference *destination_local_reference; - - /* data pointer */ - int data_len; -}; - -/* - * helper functions for the nat code - */ -int sccp_determine_msg_type(struct msgb *msg); -int sccp_parse_header(struct msgb *msg, struct sccp_parse_result *result); - -/* - * osmocore logging features - */ -void sccp_set_log_area(int log_area); - -#endif diff --git a/include/sccp/sccp_types.h b/include/sccp/sccp_types.h deleted file mode 100644 index ab7f74f..0000000 --- a/include/sccp/sccp_types.h +++ /dev/null @@ -1,443 +0,0 @@ -/* - * ITU Q.713 defined types for SCCP - * - * (C) 2009 by Holger Hans Peter Freyther - * - * All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#ifndef SCCP_TYPES_H -#define SCCP_TYPES_H - -#include -#include - -/* Table 1/Q.713 - SCCP message types */ -enum sccp_message_types { - SCCP_MSG_TYPE_CR = 1, - SCCP_MSG_TYPE_CC = 2, - SCCP_MSG_TYPE_CREF = 3, - SCCP_MSG_TYPE_RLSD = 4, - SCCP_MSG_TYPE_RLC = 5, - SCCP_MSG_TYPE_DT1 = 6, - SCCP_MSG_TYPE_DT2 = 7, - SCCP_MSG_TYPE_AK = 8, - SCCP_MSG_TYPE_UDT = 9, - SCCP_MSG_TYPE_UDTS = 10, - SCCP_MSG_TYPE_ED = 11, - SCCP_MSG_TYPE_EA = 12, - SCCP_MSG_TYPE_RSR = 13, - SCCP_MSG_TYPE_RSC = 14, - SCCP_MSG_TYPE_ERR = 15, - SCCP_MSG_TYPE_IT = 16, - SCCP_MSG_TYPE_XUDT = 17, - SCCP_MSG_TYPE_XUDTS = 18, - SCCP_MSG_TYPE_LUDT = 19, - SCCP_MSG_TYPE_LUDTS = 20 -}; - -/* Table 2/Q.713 - SCCP parameter name codes */ -enum sccp_parameter_name_codes { - SCCP_PNC_END_OF_OPTIONAL = 0, - SCCP_PNC_DESTINATION_LOCAL_REFERENCE = 1, - SCCP_PNC_SOURCE_LOCAL_REFERENCE = 2, - SCCP_PNC_CALLED_PARTY_ADDRESS = 3, - SCCP_PNC_CALLING_PARTY_ADDRESS = 4, - SCCP_PNC_PROTOCOL_CLASS = 5, - SCCP_PNC_SEGMENTING = 6, - SCCP_PNC_RECEIVE_SEQ_NUMBER = 7, - SCCP_PNC_SEQUENCING = 8, - SCCP_PNC_CREDIT = 9, - SCCP_PNC_RELEASE_CAUSE = 10, - SCCP_PNC_RETURN_CAUSE = 11, - SCCP_PNC_RESET_CAUSE = 12, - SCCP_PNC_ERROR_CAUSE = 13, - SCCP_PNC_REFUSAL_CAUSE = 14, - SCCP_PNC_DATA = 15, - SCCP_PNC_SEGMENTATION = 16, - SCCP_PNC_HOP_COUNTER = 17, - SCCP_PNC_IMPORTANCE = 18, - SCCP_PNC_LONG_DATA = 19, -}; - -/* Figure 3/Q.713 Called/calling party address */ -enum { - SCCP_TITLE_IND_NONE = 0, - SCCP_TITLE_IND_NATURE_ONLY = 1, - SCCP_TITLE_IND_TRANSLATION_ONLY = 2, - SCCP_TITLE_IND_TRANS_NUM_ENC = 3, - SCCP_TITLE_IND_TRANS_NUM_ENC_NATURE = 4, -}; - -enum { - SCCP_CALL_ROUTE_ON_SSN = 1, - SCCP_CALL_ROUTE_ON_GT = 0, -}; - -struct sccp_called_party_address { -#if OSMO_IS_LITTLE_ENDIAN - uint8_t point_code_indicator : 1, - ssn_indicator : 1, - global_title_indicator : 4, - routing_indicator : 1, - reserved : 1; -#elif OSMO_IS_BIG_ENDIAN - uint8_t reserved : 1, - routing_indicator : 1, - global_title_indicator : 4, - ssn_indicator : 1, - point_code_indicator : 1; -#endif - uint8_t data[0]; -} __attribute__((packed)); - -/* indicator indicates presence in the above order */ - -/* Figure 6/Q.713 */ -struct sccp_signalling_point_code { - uint8_t lsb; -#if OSMO_IS_LITTLE_ENDIAN - uint8_t msb : 6, - reserved : 2; -#elif OSMO_IS_BIG_ENDIAN - uint8_t reserved : 2, - msb : 6; -#endif -} __attribute__((packed)); - -/* SSN == subsystem number */ -enum sccp_subsystem_number { - SCCP_SSN_NOT_KNOWN_OR_USED = 0, - SCCP_SSN_MANAGEMENT = 1, - SCCP_SSN_RESERVED_ITU = 2, - SCCP_SSN_ISDN_USER_PART = 3, - SCCP_SSN_OMAP = 4, /* operation, maint and administration part */ - SCCP_SSN_MAP = 5, /* mobile application part */ - SCCP_SSN_HLR = 6, - SCCP_SSN_VLR = 7, - SCCP_SSN_MSC = 8, - SCCP_SSN_EIC = 9, /* equipent identifier centre */ - SCCP_SSN_AUC = 10, /* authentication centre */ - SCCP_SSN_ISDN_SUPPL_SERVICES = 11, - SCCP_SSN_RESERVED_INTL = 12, - SCCP_SSN_ISDN_EDGE_TO_EDGE = 13, - SCCP_SSN_TC_TEST_RESPONDER = 14, - - /* From GSM 03.03 8.2 */ - SCCP_SSN_BSSAP = 254, - SCCP_SSN_BSSOM = 253, -}; - -/* Q.713, 3.4.2.3 */ -enum { - SCCP_NAI_UNKNOWN = 0, - SCCP_NAI_SUBSCRIBER_NUMBER = 1, - SCCP_NAI_RESERVED_NATIONAL = 2, - SCCP_NAI_NATIONAL_SIGNIFICANT = 3, - SCCP_NAI_INTERNATIONAL = 4, -}; - -struct sccp_global_title { -#if OSMO_IS_LITTLE_ENDIAN - uint8_t nature_of_addr_ind : 7, - odd_even : 1; -#elif OSMO_IS_BIG_ENDIAN - uint8_t odd_even : 1, - nature_of_addr_ind : 7; -#endif - uint8_t data[0]; -} __attribute__((packed)); - -/* Q.713, 3.3 */ -struct sccp_source_reference { - uint8_t octet1; - uint8_t octet2; - uint8_t octet3; -} __attribute__((packed)); - -/* Q.714, 3.6 */ -enum sccp_protocol_class { - SCCP_PROTOCOL_CLASS_0 = 0, - SCCP_PROTOCOL_CLASS_1 = 1, - SCCP_PROTOCOL_CLASS_2 = 2, - SCCP_PROTOCOL_CLASS_3 = 3, -}; - -/* bits 5-8 when class0, class1 is used */ -enum sccp_protocol_options { - SCCP_PROTOCOL_NO_SPECIAL = 0, - SCCP_PROTOCOL_RETURN_MESSAGE = 8, -}; - -enum sccp_release_cause { - SCCP_RELEASE_CAUSE_END_USER_ORIGINATED = 0, - SCCP_RELEASE_CAUSE_END_USER_CONGESTION = 1, - SCCP_RELEASE_CAUSE_END_USER_FAILURE = 2, - SCCP_RELEASE_CAUSE_SCCP_USER_ORIGINATED = 3, - SCCP_RELEASE_CAUSE_REMOTE_PROCEDURE_ERROR = 4, - SCCP_RELEASE_CAUSE_INCONSISTENT_CONN_DATA = 5, - SCCP_RELEASE_CAUSE_ACCESS_FAILURE = 6, - SCCP_RELEASE_CAUSE_ACCESS_CONGESTION = 7, - SCCP_RELEASE_CAUSE_SUBSYSTEM_FAILURE = 8, - SCCP_RELEASE_CAUSE_SUBSYSTEM_CONGESTION = 9, - SCCP_RELEASE_CAUSE_MTP_FAILURE = 10, - SCCP_RELEASE_CAUSE_NETWORK_CONGESTION = 11, - SCCP_RELEASE_CAUSE_EXPIRATION_RESET = 12, - SCCP_RELEASE_CAUSE_EXPIRATION_INACTIVE = 13, - SCCP_RELEASE_CAUSE_RESERVED = 14, - SCCP_RELEASE_CAUSE_UNQUALIFIED = 15, - SCCP_RELEASE_CAUSE_SCCP_FAILURE = 16, -}; - -enum sccp_return_cause { - SCCP_RETURN_CAUSE_NO_TRANSLATION_NATURE = 0, - SCCP_RETURN_CAUSE_NO_TRANSLATION = 1, - SCCP_RETURN_CAUSE_SUBSYSTEM_CONGESTION = 2, - SCCP_RETURN_CAUSE_SUBSYSTEM_FAILURE = 3, - SCCP_RETURN_CAUSE_UNEQUIPPED_USER = 4, - SCCP_RETURN_CAUSE_MTP_FAILURE = 5, - SCCP_RETURN_CAUSE_NETWORK_CONGESTION = 6, - SCCP_RETURN_CAUSE_UNQUALIFIED = 7, - SCCP_RETURN_CAUSE_ERROR_IN_MSG_TRANSPORT = 8, - SCCP_RETURN_CAUSE_ERROR_IN_LOCAL_PROCESSING = 9, - SCCP_RETURN_CAUSE_DEST_CANNOT_PERFORM_REASSEMBLY = 10, - SCCP_RETURN_CAUSE_SCCP_FAILURE = 11, - SCCP_RETURN_CAUSE_HOP_COUNTER_VIOLATION = 12, - SCCP_RETURN_CAUSE_SEGMENTATION_NOT_SUPPORTED= 13, - SCCP_RETURN_CAUSE_SEGMENTATION_FAILURE = 14 -}; - -enum sccp_reset_cause { - SCCP_RESET_CAUSE_END_USER_ORIGINATED = 0, - SCCP_RESET_CAUSE_SCCP_USER_ORIGINATED = 1, - SCCP_RESET_CAUSE_MSG_OUT_OF_ORDER_PS = 2, - SCCP_RESET_CAUSE_MSG_OUT_OF_ORDER_PR = 3, - SCCP_RESET_CAUSE_RPC_OUT_OF_WINDOW = 4, - SCCP_RESET_CAUSE_RPC_INCORRECT_PS = 5, - SCCP_RESET_CAUSE_RPC_GENERAL = 6, - SCCP_RESET_CAUSE_REMOTE_END_USER_OPERATIONAL= 7, - SCCP_RESET_CAUSE_NETWORK_OPERATIONAL = 8, - SCCP_RESET_CAUSE_ACCESS_OPERATIONAL = 9, - SCCP_RESET_CAUSE_NETWORK_CONGESTION = 10, - SCCP_RESET_CAUSE_RESERVED = 11, -}; - -enum sccp_error_cause { - SCCP_ERROR_LRN_MISMATCH_UNASSIGNED = 0, /* local reference number */ - SCCP_ERROR_LRN_MISMATCH_INCONSISTENT = 1, - SCCP_ERROR_POINT_CODE_MISMATCH = 2, - SCCP_ERROR_SERVICE_CLASS_MISMATCH = 3, - SCCP_ERROR_UNQUALIFIED = 4, -}; - -/* ITU=T Q.713 Section 3.15 */ -enum sccp_refusal_cause { - SCCP_REFUSAL_END_USER_ORIGINATED = 0, - SCCP_REFUSAL_END_USER_CONGESTION = 1, - SCCP_REFUSAL_END_USER_FAILURE = 2, - SCCP_REFUSAL_SCCP_USER_ORIGINATED = 3, - SCCP_REFUSAL_DESTINATION_ADDRESS_UKNOWN = 4, - SCCP_REFUSAL_DESTINATION_INACCESSIBLE = 5, - SCCP_REFUSAL_NET_QOS_NON_TRANSIENT = 6, - SCCP_REFUSAL_NET_QOS_TRANSIENT = 7, - SCCP_REFUSAL_ACCESS_FAILURE = 8, - SCCP_REFUSAL_ACCESS_CONGESTION = 9, - SCCP_REFUSAL_SUBSYSTEM_FAILURE = 10, - SCCP_REFUSAL_SUBSYTEM_CONGESTION = 11, - SCCP_REFUSAL_EXPIRATION = 12, - SCCP_REFUSAL_INCOMPATIBLE_USER_DATA = 13, - SCCP_REFUSAL_RESERVED = 14, - SCCP_REFUSAL_UNQUALIFIED = 15, - SCCP_REFUSAL_HOP_COUNTER_VIOLATION = 16, - SCCP_REFUSAL_SCCP_FAILURE = 17, - SCCP_REFUSAL_NO_TRANS_FOR_ADDRESS_NATURE = 18, - SCCP_REFUSAL_UNEQUIPPED_USER = 19, -}; - -/* - * messages... as of Q.713 Chapter 4 - */ -struct sccp_connection_request { - /* mandatory */ - uint8_t type; - struct sccp_source_reference source_local_reference; - uint8_t proto_class; - - - /* variable */ - uint8_t variable_called; -#if VARIABLE - called_party_address -#endif - - /* optional */ - uint8_t optional_start; - -#if OPTIONAL - credit 3 - callingparty var 4-n - data 3-130 - hop_counter 3 - importance 3 - end_of_optional 1 -#endif - - uint8_t data[0]; -} __attribute__((packed)); - -struct sccp_connection_confirm { - /* mandatory */ - uint8_t type; - struct sccp_source_reference destination_local_reference; - struct sccp_source_reference source_local_reference; - uint8_t proto_class; - - /* optional */ - uint8_t optional_start; - - /* optional */ -#if OPTIONAL - credit 3 - called party 4 - data 3-130 - importance 3 - end_of_optional 1 -#endif - - uint8_t data[0]; -} __attribute__((packed)); - -struct sccp_connection_refused { - /* mandatory */ - uint8_t type; - struct sccp_source_reference destination_local_reference; - uint8_t cause; - - /* optional */ - uint8_t optional_start; - - /* optional */ -#if OPTIONAL - called party 4 - data 3-130 - importance 3 - end_of_optional 1 -#endif - - uint8_t data[0]; -} __attribute__((packed)); - -struct sccp_connection_released { - /* mandatory */ - uint8_t type; - struct sccp_source_reference destination_local_reference; - struct sccp_source_reference source_local_reference; - uint8_t release_cause; - - - /* optional */ - uint8_t optional_start; - -#if OPTIONAL - data 3-130 - importance 3 - end_of_optional 1 -#endif - uint8_t data[0]; -} __attribute__((packed)); - -struct sccp_connection_release_complete { - uint8_t type; - struct sccp_source_reference destination_local_reference; - struct sccp_source_reference source_local_reference; -} __attribute__((packed)); - -struct sccp_data_form1 { - /* mandatory */ - uint8_t type; - struct sccp_source_reference destination_local_reference; - uint8_t segmenting; - - /* variable */ - uint8_t variable_start; - -#if VARIABLE - data 2-256; -#endif - - uint8_t data[0]; -} __attribute__((packed)); - - -struct sccp_data_unitdata { - /* mandatory */ - uint8_t type; - uint8_t proto_class; - - - /* variable */ - uint8_t variable_called; - uint8_t variable_calling; - uint8_t variable_data; - -#if VARIABLE - called party address - calling party address -#endif - - uint8_t data[0]; -} __attribute__((packed)); - -struct sccp_data_unitdata_service { - /* mandantory */ - uint8_t type; - uint8_t return_cause; - - - /* variable */ - uint8_t variable_called; - uint8_t variable_calling; - uint8_t variable_data; - -#if VARIABLE - called party address - calling party address -#endif - - uint8_t data[0]; -} __attribute__((packed)); - - -struct sccp_data_it { - /* mandatory */ - uint8_t type; - struct sccp_source_reference destination_local_reference; - struct sccp_source_reference source_local_reference; - uint8_t proto_class; - - uint8_t sequencing[2]; - uint8_t credit; -} __attribute__((packed)); - -struct sccp_proto_err { - uint8_t type; - struct sccp_source_reference destination_local_reference; - uint8_t error_cause; -}; - -#endif diff --git a/src/mtp_pcap.c b/src/mtp_pcap.c index e83e6f7..a59efc5 100644 --- a/src/mtp_pcap.c +++ b/src/mtp_pcap.c @@ -22,7 +22,7 @@ * */ -#include +#include #include diff --git a/src/sccp.c b/src/sccp.c index a15a84b..8c3641c 100644 --- a/src/sccp.c +++ b/src/sccp.c @@ -31,7 +31,7 @@ #include #include -#include +#include // Unassigned debug area static int DSCCP = 0; diff --git a/src/sccp2sua.c b/src/sccp2sua.c index 2f5b687..f68f9a9 100644 --- a/src/sccp2sua.c +++ b/src/sccp2sua.c @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/sccp_sclc.c b/src/sccp_sclc.c index e4dbae6..db67660 100644 --- a/src/sccp_sclc.c +++ b/src/sccp_sclc.c @@ -56,7 +56,7 @@ #include #include -#include +#include #include "xua_internal.h" #include "sccp_internal.h" diff --git a/src/sccp_scoc.c b/src/sccp_scoc.c index 8138e43..fbbad49 100644 --- a/src/sccp_scoc.c +++ b/src/sccp_scoc.c @@ -56,7 +56,7 @@ #include #include -#include +#include #include "xua_internal.h" #include "sccp_internal.h" diff --git a/src/sccp_scrc.c b/src/sccp_scrc.c index 9005dc7..db49299 100644 --- a/src/sccp_scrc.c +++ b/src/sccp_scrc.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include diff --git a/tests/mtp/mtp_parse_test.c b/tests/mtp/mtp_parse_test.c index 75650a3..92c34ca 100644 --- a/tests/mtp/mtp_parse_test.c +++ b/tests/mtp/mtp_parse_test.c @@ -1,5 +1,5 @@ /* MTP Layer3 parsing tests */ -#include +#include #include diff --git a/tests/sccp/sccp_test.c b/tests/sccp/sccp_test.c index ed485bc..ba9ff7a 100644 --- a/tests/sccp/sccp_test.c +++ b/tests/sccp/sccp_test.c @@ -31,7 +31,7 @@ #include #include -#include +#include #define MIN(x, y) ((x) < (y) ? (x) : (y)) -- cgit v1.2.3