blob: 643479adcc2dad85b9bb358023f732db39edcdd7 [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 */
97int sccp_system_init(int (*outgoing)(struct msgb *data, void *ctx), void *context);
98int 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/**
109 * Create a new socket. Set your callbacks and then call bind to open
110 * the connection.
111 */
112struct sccp_connection *sccp_connection_socket(void);
113
114/**
115 * Open the connection and send additional data
116 */
117int sccp_connection_connect(struct sccp_connection *conn,
118 const struct sockaddr_sccp *sccp_called,
119 struct msgb *data);
120
121/**
122 * mostly for testing purposes only. Set the accept callback.
123 * TODO: add true routing information... in analogy to socket, bind, accept
124 */
125int sccp_connection_set_incoming(const struct sockaddr_sccp *sock,
126 int (*accept_cb)(struct sccp_connection *connection, void *data),
127 void *user_data);
128
129/**
130 * Send data in terms of unit data. A fixed address indicator will be used.
131 */
132int sccp_write(struct msgb *data,
133 const struct sockaddr_sccp *sock_sender,
134 const struct sockaddr_sccp *sock_target, int class);
135int sccp_set_read(const struct sockaddr_sccp *sock,
136 int (*read_cb)(struct msgb *msgb, unsigned int, void *user_data),
137 void *user_data);
138
139/* generic sock addresses */
140extern const struct sockaddr_sccp sccp_ssn_bssap;
141
142/* helpers */
143u_int32_t sccp_src_ref_to_int(struct sccp_source_reference *ref);
144struct sccp_source_reference sccp_src_ref_from_int(u_int32_t);
145
Holger Hans Peter Freyther82da7fc2010-01-27 12:29:49 +0100146/**
147 * Below this are helper functions and structs for parsing SCCP messages
148 */
149struct sccp_parse_result {
150 struct sccp_address called;
151 struct sccp_address calling;
152
153 /* point to the msg packet */
154 struct sccp_source_reference *source_local_reference;
155 struct sccp_source_reference *destination_local_reference;
156
157 /* data pointer */
158 int data_len;
159};
Holger Hans Peter Freythera692fbc2010-01-13 09:55:43 +0100160
161/*
162 * helper functions for the nat code
163 */
164int sccp_determine_msg_type(struct msgb *msg);
Holger Hans Peter Freyther82da7fc2010-01-27 12:29:49 +0100165int sccp_parse_header(struct msgb *msg, struct sccp_parse_result *result);
Holger Hans Peter Freythera692fbc2010-01-13 09:55:43 +0100166
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200167#endif