blob: 8ee4b680bb9a6ff9c9fc7210224e06ec6897f458 [file] [log] [blame]
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +02001/*
2 * SCCP management code
3 *
4 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
5 *
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>
30
31#include <openbsc/msgb.h>
32
33#include "sccp_types.h"
34
35struct 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);
104int sccp_connection_close(struct sccp_connection *connection, int cause);
105int sccp_connection_free(struct sccp_connection *connection);
106
107/**
108 * Create a new socket. Set your callbacks and then call bind to open
109 * the connection.
110 */
111struct sccp_connection *sccp_connection_socket(void);
112
113/**
114 * Open the connection and send additional data
115 */
116int sccp_connection_connect(struct sccp_connection *conn,
117 const struct sockaddr_sccp *sccp_called,
118 struct msgb *data);
119
120/**
121 * mostly for testing purposes only. Set the accept callback.
122 * TODO: add true routing information... in analogy to socket, bind, accept
123 */
124int sccp_connection_set_incoming(const struct sockaddr_sccp *sock,
125 int (*accept_cb)(struct sccp_connection *connection, void *data),
126 void *user_data);
127
128/**
129 * Send data in terms of unit data. A fixed address indicator will be used.
130 */
131int sccp_write(struct msgb *data,
132 const struct sockaddr_sccp *sock_sender,
133 const struct sockaddr_sccp *sock_target, int class);
134int sccp_set_read(const struct sockaddr_sccp *sock,
135 int (*read_cb)(struct msgb *msgb, unsigned int, void *user_data),
136 void *user_data);
137
138/* generic sock addresses */
139extern const struct sockaddr_sccp sccp_ssn_bssap;
140
141/* helpers */
142u_int32_t sccp_src_ref_to_int(struct sccp_source_reference *ref);
143struct sccp_source_reference sccp_src_ref_from_int(u_int32_t);
144
145#endif