Holger Hans Peter Freyther | ac96770 | 2009-07-29 07:37:48 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 35 | struct sccp_system; |
| 36 | |
| 37 | enum { |
| 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 | |
| 48 | struct 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 | */ |
| 61 | struct sccp_address { |
| 62 | struct sccp_called_party_address address; |
| 63 | u_int8_t ssn; |
| 64 | u_int8_t poi[2]; |
| 65 | }; |
| 66 | |
| 67 | struct sccp_optional_data { |
| 68 | u_int8_t data_len; |
| 69 | u_int8_t data_start; |
| 70 | }; |
| 71 | |
| 72 | struct 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 | */ |
| 97 | int sccp_system_init(int (*outgoing)(struct msgb *data, void *ctx), void *context); |
| 98 | int sccp_system_incoming(struct msgb *data); |
| 99 | |
| 100 | /** |
| 101 | * Send data on an existing connection |
| 102 | */ |
| 103 | int sccp_connection_write(struct sccp_connection *connection, struct msgb *data); |
Holger Hans Peter Freyther | 3b9516e | 2009-11-18 22:11:28 +0100 | [diff] [blame] | 104 | int sccp_connection_send_it(struct sccp_connection *connection); |
Holger Hans Peter Freyther | ac96770 | 2009-07-29 07:37:48 +0200 | [diff] [blame] | 105 | int sccp_connection_close(struct sccp_connection *connection, int cause); |
| 106 | int 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 | */ |
| 112 | struct sccp_connection *sccp_connection_socket(void); |
| 113 | |
| 114 | /** |
| 115 | * Open the connection and send additional data |
| 116 | */ |
| 117 | int 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 | */ |
| 125 | int 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 | */ |
| 132 | int sccp_write(struct msgb *data, |
| 133 | const struct sockaddr_sccp *sock_sender, |
| 134 | const struct sockaddr_sccp *sock_target, int class); |
| 135 | int 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 */ |
| 140 | extern const struct sockaddr_sccp sccp_ssn_bssap; |
| 141 | |
| 142 | /* helpers */ |
| 143 | u_int32_t sccp_src_ref_to_int(struct sccp_source_reference *ref); |
| 144 | struct sccp_source_reference sccp_src_ref_from_int(u_int32_t); |
| 145 | |
| 146 | #endif |