2009-07-29 05:37:48 +00:00
|
|
|
/*
|
|
|
|
* SCCP management code
|
|
|
|
*
|
2010-01-27 11:29:49 +00:00
|
|
|
* (C) 2009, 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
|
2009-07-29 05:37:48 +00:00
|
|
|
*
|
|
|
|
* 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 <stdlib.h>
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
2010-02-12 21:44:50 +00:00
|
|
|
#include <sys/types.h>
|
2009-07-29 05:37:48 +00:00
|
|
|
|
|
|
|
#include "sccp_types.h"
|
|
|
|
|
2010-02-12 21:44:50 +00:00
|
|
|
struct msgb;
|
2009-07-29 05:37:48 +00:00
|
|
|
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??? */
|
2010-07-23 10:39:17 +00:00
|
|
|
uint8_t sccp_ssn; /* subssystem number for routing */
|
2009-07-29 05:37:48 +00:00
|
|
|
|
|
|
|
/* TODO fill in address indicator... if that is ever needed */
|
|
|
|
|
2010-07-31 17:04:28 +00:00
|
|
|
/* optional gti information */
|
|
|
|
uint8_t *gti;
|
|
|
|
int gti_len;
|
|
|
|
|
|
|
|
/* any of SCCP_TITLE_IND_* */
|
|
|
|
uint8_t gti_ind;
|
|
|
|
|
2010-07-31 18:52:28 +00:00
|
|
|
int use_poi;
|
|
|
|
uint8_t poi[2];
|
|
|
|
|
2009-07-29 05:37:48 +00:00
|
|
|
/* not sure about these */
|
2010-07-23 10:39:17 +00:00
|
|
|
/* uint8_t sccp_class; */
|
2009-07-29 05:37:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parsed structure of an address
|
|
|
|
*/
|
|
|
|
struct sccp_address {
|
|
|
|
struct sccp_called_party_address address;
|
2010-07-23 10:39:17 +00:00
|
|
|
uint8_t ssn;
|
|
|
|
uint8_t poi[2];
|
2010-07-31 20:06:04 +00:00
|
|
|
|
|
|
|
uint8_t *gti_data;
|
|
|
|
int gti_len;
|
2009-07-29 05:37:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sccp_optional_data {
|
2010-07-23 10:39:17 +00:00
|
|
|
uint8_t data_len;
|
|
|
|
uint8_t data_start;
|
2009-07-29 05:37:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2010-08-25 03:56:57 +00:00
|
|
|
* The conn is NULL for UDT and other messages without a connection
|
2009-07-29 05:37:48 +00:00
|
|
|
*/
|
2010-08-25 03:56:57 +00:00
|
|
|
int sccp_system_init(void (*outgoing)(struct sccp_connection *conn, struct msgb *data, void *ctx), void *context);
|
2009-07-29 05:37:48 +00:00
|
|
|
int sccp_system_incoming(struct msgb *data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send data on an existing connection
|
|
|
|
*/
|
|
|
|
int sccp_connection_write(struct sccp_connection *connection, struct msgb *data);
|
2009-11-18 21:11:28 +00:00
|
|
|
int sccp_connection_send_it(struct sccp_connection *connection);
|
2009-07-29 05:37:48 +00:00
|
|
|
int sccp_connection_close(struct sccp_connection *connection, int cause);
|
|
|
|
int sccp_connection_free(struct sccp_connection *connection);
|
|
|
|
|
2010-04-05 16:13:40 +00:00
|
|
|
/**
|
|
|
|
* internal..
|
|
|
|
*/
|
|
|
|
int sccp_connection_force_free(struct sccp_connection *conn);
|
|
|
|
|
2009-07-29 05:37:48 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
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 */
|
2010-07-23 10:40:10 +00:00
|
|
|
uint32_t sccp_src_ref_to_int(struct sccp_source_reference *ref);
|
|
|
|
struct sccp_source_reference sccp_src_ref_from_int(uint32_t);
|
2009-07-29 05:37:48 +00:00
|
|
|
|
2010-05-14 21:35:48 +00:00
|
|
|
struct msgb *sccp_create_refuse(struct sccp_source_reference *src_ref, int cause, uint8_t *data, int length);
|
2010-05-16 09:55:07 +00:00
|
|
|
struct msgb *sccp_create_cc(struct sccp_source_reference *src_ref, struct sccp_source_reference *dst_ref);
|
2010-05-16 10:33:26 +00:00
|
|
|
struct msgb *sccp_create_rlsd(struct sccp_source_reference *src_ref, struct sccp_source_reference *dst_ref, int cause);
|
2010-05-16 12:41:48 +00:00
|
|
|
struct msgb *sccp_create_dt1(struct sccp_source_reference *dst_ref, uint8_t *data, uint8_t len);
|
2010-08-01 12:52:01 +00:00
|
|
|
struct msgb *sccp_create_udt(int _class, const struct sockaddr_sccp *sock_sender,
|
2010-08-02 15:01:02 +00:00
|
|
|
const struct sockaddr_sccp *sock_target, uint8_t *data, int len);
|
2010-05-13 19:34:35 +00:00
|
|
|
|
2010-01-27 11:29:49 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
};
|
2010-01-13 08:55:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* helper functions for the nat code
|
|
|
|
*/
|
|
|
|
int sccp_determine_msg_type(struct msgb *msg);
|
2010-01-27 11:29:49 +00:00
|
|
|
int sccp_parse_header(struct msgb *msg, struct sccp_parse_result *result);
|
2010-01-13 08:55:43 +00:00
|
|
|
|
2010-07-29 18:12:02 +00:00
|
|
|
/*
|
|
|
|
* osmocore logging features
|
|
|
|
*/
|
|
|
|
void sccp_set_log_area(int log_area);
|
|
|
|
|
2009-07-29 05:37:48 +00:00
|
|
|
#endif
|