blob: 84ae914ef623c96a27d204b9955defdc6129adce [file] [log] [blame]
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +02001/*
2 * SCCP management code
3 *
Holger Hans Peter Freyther82da7fc2010-01-27 12:29:49 +01004 * (C) 2009, 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +02005 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#ifndef SCCP_H
25#define SCCP_H
26
27#include <stdlib.h>
28
29#include <sys/socket.h>
Holger Hans Peter Freyther8a69cb22010-02-12 22:44:50 +010030#include <sys/types.h>
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +020031
32#include "sccp_types.h"
33
Holger Hans Peter Freyther8a69cb22010-02-12 22:44:50 +010034struct msgb;
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +020035struct sccp_system;
36
37enum {
38 SCCP_CONNECTION_STATE_NONE,
39 SCCP_CONNECTION_STATE_REQUEST,
40 SCCP_CONNECTION_STATE_CONFIRM,
41 SCCP_CONNECTION_STATE_ESTABLISHED,
42 SCCP_CONNECTION_STATE_RELEASE,
43 SCCP_CONNECTION_STATE_RELEASE_COMPLETE,
44 SCCP_CONNECTION_STATE_REFUSED,
45 SCCP_CONNECTION_STATE_SETUP_ERROR,
46};
47
48struct sockaddr_sccp {
49 sa_family_t sccp_family; /* AF_SCCP in the future??? */
50 u_int8_t sccp_ssn; /* subssystem number for routing */
51
52 /* TODO fill in address indicator... if that is ever needed */
53
54 /* not sure about these */
55 /* u_int8_t sccp_class; */
56};
57
58/*
59 * parsed structure of an address
60 */
61struct sccp_address {
62 struct sccp_called_party_address address;
63 u_int8_t ssn;
64 u_int8_t poi[2];
65};
66
67struct sccp_optional_data {
68 u_int8_t data_len;
69 u_int8_t data_start;
70};
71
72struct sccp_connection {
73 /* public */
74 void *data_ctx;
75 void (*data_cb)(struct sccp_connection *conn, struct msgb *msg, unsigned int len);
76
77 void *state_ctx;
78 void (*state_cb)(struct sccp_connection *, int old_state);
79
80 struct sccp_source_reference source_local_reference;
81 struct sccp_source_reference destination_local_reference;
82
83 int connection_state;
84
85 /* private */
86 /* list of active connections */
87 struct llist_head list;
88 struct sccp_system *system;
89 int incoming;
90};
91
92/**
93 * system functionality to implement on top of any other transport layer:
94 * call sccp_system_incoming for incoming data (from the network)
95 * sccp will call outgoing whenever outgoing data exists
96 */
Holger Hans Peter Freyther3c1221e2010-03-26 05:44:21 +010097int sccp_system_init(void (*outgoing)(struct msgb *data, void *ctx), void *context);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +020098int sccp_system_incoming(struct msgb *data);
99
100/**
101 * Send data on an existing connection
102 */
103int sccp_connection_write(struct sccp_connection *connection, struct msgb *data);
Holger Hans Peter Freyther3b9516e2009-11-18 22:11:28 +0100104int sccp_connection_send_it(struct sccp_connection *connection);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200105int sccp_connection_close(struct sccp_connection *connection, int cause);
106int sccp_connection_free(struct sccp_connection *connection);
107
108/**
Holger Hans Peter Freytherb71517f2010-04-05 18:13:40 +0200109 * internal..
110 */
111int sccp_connection_force_free(struct sccp_connection *conn);
112
113/**
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200114 * Create a new socket. Set your callbacks and then call bind to open
115 * the connection.
116 */
117struct sccp_connection *sccp_connection_socket(void);
118
119/**
120 * Open the connection and send additional data
121 */
122int sccp_connection_connect(struct sccp_connection *conn,
123 const struct sockaddr_sccp *sccp_called,
124 struct msgb *data);
125
126/**
127 * mostly for testing purposes only. Set the accept callback.
128 * TODO: add true routing information... in analogy to socket, bind, accept
129 */
130int sccp_connection_set_incoming(const struct sockaddr_sccp *sock,
131 int (*accept_cb)(struct sccp_connection *connection, void *data),
132 void *user_data);
133
134/**
135 * Send data in terms of unit data. A fixed address indicator will be used.
136 */
137int sccp_write(struct msgb *data,
138 const struct sockaddr_sccp *sock_sender,
139 const struct sockaddr_sccp *sock_target, int class);
140int sccp_set_read(const struct sockaddr_sccp *sock,
141 int (*read_cb)(struct msgb *msgb, unsigned int, void *user_data),
142 void *user_data);
143
144/* generic sock addresses */
145extern const struct sockaddr_sccp sccp_ssn_bssap;
146
147/* helpers */
148u_int32_t sccp_src_ref_to_int(struct sccp_source_reference *ref);
149struct sccp_source_reference sccp_src_ref_from_int(u_int32_t);
150
Holger Hans Peter Freytherea504e72010-05-15 05:35:48 +0800151struct msgb *sccp_create_refuse(struct sccp_source_reference *src_ref, int cause, uint8_t *data, int length);
Holger Hans Peter Freyther410422f2010-05-16 17:55:07 +0800152struct msgb *sccp_create_cc(struct sccp_source_reference *src_ref, struct sccp_source_reference *dst_ref);
Holger Hans Peter Freytherf53a9d52010-05-16 18:33:26 +0800153struct msgb *sccp_create_rlsd(struct sccp_source_reference *src_ref, struct sccp_source_reference *dst_ref, int cause);
Holger Hans Peter Freyther394520a2010-05-16 20:41:48 +0800154struct msgb *sccp_create_dt1(struct sccp_source_reference *dst_ref, uint8_t *data, uint8_t len);
Holger Hans Peter Freyther7bf332a2010-05-14 03:34:35 +0800155
Holger Hans Peter Freyther82da7fc2010-01-27 12:29:49 +0100156/**
157 * Below this are helper functions and structs for parsing SCCP messages
158 */
159struct sccp_parse_result {
160 struct sccp_address called;
161 struct sccp_address calling;
162
163 /* point to the msg packet */
164 struct sccp_source_reference *source_local_reference;
165 struct sccp_source_reference *destination_local_reference;
166
167 /* data pointer */
168 int data_len;
169};
Holger Hans Peter Freythera692fbc2010-01-13 09:55:43 +0100170
171/*
172 * helper functions for the nat code
173 */
174int sccp_determine_msg_type(struct msgb *msg);
Holger Hans Peter Freyther82da7fc2010-01-27 12:29:49 +0100175int sccp_parse_header(struct msgb *msg, struct sccp_parse_result *result);
Holger Hans Peter Freythera692fbc2010-01-13 09:55:43 +0100176
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200177#endif