blob: fe8abf5750b5a8316b038389e84f477f7cc2d52b [file] [log] [blame]
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +02001/*
2 * SCCP management code
3 *
Holger Hans Peter Freytherefca5412010-01-27 12:12:46 +01004 * (C) 2009, 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * (C) 2009, 2010 by on-waves.com
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +02006 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24
25#include <string.h>
26
27#include <sccp/sccp.h>
28
29#include <openbsc/debug.h>
30#include <openbsc/talloc.h>
31#include <openbsc/linuxlist.h>
32
33static void *tall_sccp_ctx;
34static LLIST_HEAD(sccp_connections);
35
36#define SCCP_MSG_SIZE 4096
37#define SCCP_MSG_HEADROOM 128
38
39/* global data */
40const struct sockaddr_sccp sccp_ssn_bssap = {
41 .sccp_family = 0,
42 .sccp_ssn = SCCP_SSN_BSSAP,
43};
44
45struct sccp_system {
46 /* layer3 -> layer2 */
47 int (*write_data)(struct msgb *data, void *context);
48 void *write_context;
49};
50
51
52static struct sccp_system sccp_system = {
53 .write_data = NULL,
54};
55
56struct sccp_data_callback {
57 /* connection based */
58 int (*accept_cb)(struct sccp_connection *, void *);
59 void *accept_context;
60
61 /* connection less */
62 int (*read_cb)(struct msgb *, unsigned int, void *);
63 void *read_context;
64
65 u_int8_t ssn;
66 struct llist_head callback;
67};
68
69static LLIST_HEAD(sccp_callbacks);
70
71static struct sccp_data_callback *_find_ssn(u_int8_t ssn)
72{
73 struct sccp_data_callback *cb;
74
75 llist_for_each_entry(cb, &sccp_callbacks, callback) {
76 if (cb->ssn == ssn)
77 return cb;
78 }
79
80 /* need to add one */
81 cb = talloc_zero(tall_sccp_ctx, struct sccp_data_callback);
82 if (!cb) {
83 DEBUGP(DSCCP, "Failed to allocate sccp callback.\n");
84 return NULL;
85 }
86
87 cb->ssn = ssn;
88 llist_add_tail(&cb->callback, &sccp_callbacks);
89 return cb;
90}
91
92
93static int _send_msg(struct msgb *msg)
94{
95 return sccp_system.write_data(msg, sccp_system.write_context);
96}
97
98/*
99 * parsing routines
100 */
101static int copy_address(struct sccp_address *addr, u_int8_t offset, struct msgb *msgb)
102{
103 struct sccp_called_party_address *party;
104
105 int room = msgb_l2len(msgb) - offset;
106 u_int8_t read = 0;
107 u_int8_t length;
108
109 if (room <= 0) {
110 DEBUGP(DSCCP, "Not enough room for an address: %u\n", room);
111 return -1;
112 }
113
114 length = msgb->l2h[offset];
115 if (room <= length) {
116 DEBUGP(DSCCP, "Not enough room for optional data %u %u\n", room, length);
117 return -1;
118 }
119
120
121 party = (struct sccp_called_party_address *)(msgb->l2h + offset + 1);
122 if (party->point_code_indicator) {
123 if (length <= read + 2) {
124 DEBUGP(DSCCP, "POI does not fit %u\n", length);
125 return -1;
126 }
127
128
129 memcpy(&addr->poi, &party->data[read], 2);
130 read += 2;
131 }
132
133 if (party->ssn_indicator) {
134 if (length <= read + 1) {
135 DEBUGP(DSCCP, "SSN does not fit %u\n", length);
136 return -1;
137 }
138
139 addr->ssn = party->data[read];
140 read += 1;
141 }
142
143 if (party->global_title_indicator) {
144 DEBUGP(DSCCP, "GTI not supported %u\n", *(u_int8_t *)party);
145 return -1;
146 }
147
148 addr->address = *party;
149 return 0;
150}
151
152static int check_address(struct sccp_address *addr)
153{
154 /* ignore point_code_indicator... it should be zero... but */
155 if (addr->address.ssn_indicator != 1
156 || addr->address.global_title_indicator == 1
157 || addr->address.routing_indicator != 1) {
158 DEBUGP(DSCCP, "Invalid called address according to 08.06: 0x%x 0x%x\n",
159 *(u_int8_t *)&addr->address, addr->ssn);
160 return -1;
161 }
162
163 return 0;
164}
165
166static int _sccp_parse_optional_data(const int offset,
167 struct msgb *msgb, struct sccp_optional_data *data)
168{
169 u_int16_t room = msgb_l2len(msgb) - offset;
170 u_int16_t read = 0;
171
172 while (room > read) {
173 u_int8_t type = msgb->l2h[offset + read];
174 if (type == SCCP_PNC_END_OF_OPTIONAL)
175 return 0;
176
177 if (read + 1 >= room) {
178 DEBUGP(DSCCP, "no place for length\n");
179 return 0;
180 }
181
182 u_int8_t length = msgb->l2h[offset + read + 1];
183 read += 2 + length;
184
185
186 if (room <= read) {
187 DEBUGP(DSCCP, "no space for the data: type: %d read: %d room: %d l2: %d\n",
188 type, read, room, msgb_l2len(msgb));
189 return 0;
190 }
191
192 if (type == SCCP_PNC_DATA) {
193 data->data_len = length;
194 data->data_start = offset + read - length;
195 }
196
197 }
198
199 return -1;
200}
201
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100202int _sccp_parse_connection_request(struct msgb *msgb, struct sccp_parse_result *result)
Holger Hans Peter Freytherefca5412010-01-27 12:12:46 +0100203{
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100204 static const u_int32_t header_size =
205 sizeof(struct sccp_connection_request);
206 static const u_int32_t optional_offset =
207 offsetof(struct sccp_connection_request, optional_start);
208 static const u_int32_t called_offset =
209 offsetof(struct sccp_connection_request, variable_called);
210
211 struct sccp_connection_request *req = (struct sccp_connection_request *)msgb->data;
212 struct sccp_optional_data optional_data;
213
214 /* header check */
215 if (msgb_l2len(msgb) < header_size) {
216 DEBUGP(DSCCP, "msgb < header_size %u %u\n",
217 msgb_l2len(msgb), header_size);
218 return -1;
219 }
220
221 /* copy out the calling and called address. Add the offset */
222 if (copy_address(&result->called, called_offset + req->variable_called, msgb) != 0)
223 return -1;
224
225 if (check_address(&result->called) != 0) {
226 DEBUGP(DSCCP, "Invalid called address according to 08.06: 0x%x 0x%x\n",
227 *(u_int8_t *)&result->called.address, result->called.ssn);
228 return -1;
229 }
230
231 result->source_local_reference = &req->source_local_reference;
232
233 /*
234 * parse optional data.
235 */
236 memset(&optional_data, 0, sizeof(optional_data));
237 if (_sccp_parse_optional_data(optional_offset + req->optional_start, msgb, &optional_data) != 0) {
238 DEBUGP(DSCCP, "parsing of optional data failed.\n");
239 return -1;
240 }
241
242 if (optional_data.data_len != 0) {
243 msgb->l3h = &msgb->l2h[optional_data.data_start];
244 result->data_len = optional_data.data_len;
245 } else {
246 result->data_len = 0;
247 }
248
249 return 0;
Holger Hans Peter Freytherefca5412010-01-27 12:12:46 +0100250}
251
Holger Hans Peter Freyther88fe6ee2010-01-29 03:49:32 +0100252int _sccp_parse_connection_released(struct msgb *msgb, struct sccp_parse_result *result)
Holger Hans Peter Freytherefca5412010-01-27 12:12:46 +0100253{
Holger Hans Peter Freyther88fe6ee2010-01-29 03:49:32 +0100254 static int header_size = sizeof(struct sccp_connection_released);
255 static int optional_offset = offsetof(struct sccp_connection_released, optional_start);
256
257 struct sccp_optional_data optional_data;
258 struct sccp_connection_released *rls = (struct sccp_connection_released *) msgb->l2h;
259
260 /* we don't have enough size for the struct */
261 if (msgb_l2len(msgb) < header_size) {
262 DEBUGP(DSCCP, "msgb > header_size %u %u\n",
263 msgb_l2len(msgb), header_size);
264 return -1;
265 }
266
267 memset(&optional_data, 0, sizeof(optional_data));
268 if (_sccp_parse_optional_data(optional_offset + rls->optional_start, msgb, &optional_data) != 0) {
269 DEBUGP(DSCCP, "parsing of optional data failed.\n");
270 return -1;
271 }
272
273 result->source_local_reference = &rls->source_local_reference;
274 result->destination_local_reference = &rls->destination_local_reference;
275
276 if (optional_data.data_len != 0) {
277 msgb->l3h = &msgb->l2h[optional_data.data_start];
278 result->data_len = optional_data.data_len;
279 } else {
280 result->data_len = 0;
281 }
282
283 return 0;
Holger Hans Peter Freytherefca5412010-01-27 12:12:46 +0100284}
285
Holger Hans Peter Freytherfe5de4e2010-01-29 03:58:12 +0100286int _sccp_parse_connection_refused(struct msgb *msgb, struct sccp_parse_result *result)
Holger Hans Peter Freytherefca5412010-01-27 12:12:46 +0100287{
Holger Hans Peter Freytherfe5de4e2010-01-29 03:58:12 +0100288 static const u_int32_t header_size =
289 sizeof(struct sccp_connection_refused);
290 static int optional_offset = offsetof(struct sccp_connection_refused, optional_start);
291
292 struct sccp_optional_data optional_data;
293 struct sccp_connection_refused *ref;
294
295 /* header check */
296 if (msgb_l2len(msgb) < header_size) {
297 DEBUGP(DSCCP, "msgb < header_size %u %u\n",
298 msgb_l2len(msgb), header_size);
299 return -1;
300 }
301
302 ref = (struct sccp_connection_refused *) msgb->l2h;
303
304 result->destination_local_reference = &ref->destination_local_reference;
305
306 memset(&optional_data, 0, sizeof(optional_data));
307 if (_sccp_parse_optional_data(optional_offset + ref->optional_start, msgb, &optional_data) != 0) {
308 DEBUGP(DSCCP, "parsing of optional data failed.\n");
309 return -1;
310 }
311
312 /* optional data */
313 if (optional_data.data_len != 0) {
314 msgb->l3h = &msgb->l2h[optional_data.data_start];
315 result->data_len = optional_data.data_len;
316 } else {
317 result->data_len = 0;
318 }
319
320 return 0;
Holger Hans Peter Freytherefca5412010-01-27 12:12:46 +0100321}
322
323int _sccp_parse_connection_confirm(struct msgb *msg, struct sccp_parse_result *result)
324{
325 return -1;
326}
327
328int _sccp_parse_connection_release_complete(struct msgb *msg, struct sccp_parse_result *result)
329{
330 return -1;
331}
332
333int _sccp_parse_connection_dt1(struct msgb *msg, struct sccp_parse_result *result)
334{
335 return -1;
336}
337
338int _sccp_parse_udt(struct msgb *msgb, struct sccp_parse_result *result)
339{
340 static const u_int32_t header_size = sizeof(struct sccp_data_unitdata);
341 static const u_int32_t called_offset = offsetof(struct sccp_data_unitdata, variable_called);
342 static const u_int32_t calling_offset = offsetof(struct sccp_data_unitdata, variable_calling);
343 static const u_int32_t data_offset = offsetof(struct sccp_data_unitdata, variable_data);
344
345 struct sccp_data_unitdata *udt = (struct sccp_data_unitdata *)msgb->l2h;
346
347 if (msgb_l2len(msgb) < header_size) {
348 DEBUGP(DSCCP, "msgb < header_size %u %u\n",
349 msgb_l2len(msgb), header_size);
350 return -1;
351 }
352
353 /* copy out the calling and called address. Add the off */
354 if (copy_address(&result->called, called_offset + udt->variable_called, msgb) != 0)
355 return -1;
356
357 if (check_address(&result->called) != 0) {
358 DEBUGP(DSCCP, "Invalid called address according to 08.06: 0x%x 0x%x\n",
359 *(u_int8_t *)&result->called.address, result->called.ssn);
360 return -1;
361 }
362
363 if (copy_address(&result->calling, calling_offset + udt->variable_calling, msgb) != 0)
364 return -1;
365
366 if (check_address(&result->calling) != 0) {
367 DEBUGP(DSCCP, "Invalid called address according to 08.06: 0x%x 0x%x\n",
368 *(u_int8_t *)&result->called.address, result->called.ssn);
369 }
370
371 /* we don't have enough size for the data */
372 if (msgb_l2len(msgb) < data_offset + udt->variable_data + 1) {
373 DEBUGP(DSCCP, "msgb < header + offset %u %u %u\n",
374 msgb_l2len(msgb), header_size, udt->variable_data);
375 return -1;
376 }
377
378
379 msgb->l3h = &udt->data[udt->variable_data];
380
381 if (msgb_l3len(msgb) != msgb->l3h[-1]) {
382 DEBUGP(DSCCP, "msgb is truncated %u %u\n",
383 msgb_l3len(msgb), msgb->l3h[-1]);
384 return -1;
385 }
386
387 return 0;
388}
389
390
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200391/*
392 * Send UDT. Currently we have a fixed address...
393 */
394static int _sccp_send_data(int class, const struct sockaddr_sccp *in,
395 const struct sockaddr_sccp *out, struct msgb *payload)
396{
397 struct sccp_data_unitdata *udt;
398 u_int8_t *data;
399 int ret;
400
401 if (msgb_l3len(payload) > 256) {
402 DEBUGP(DSCCP, "The payload is too big for one udt\n");
403 return -1;
404 }
405
406 struct msgb *msg = msgb_alloc_headroom(SCCP_MSG_SIZE,
407 SCCP_MSG_HEADROOM, "sccp: udt");
408 msg->l2h = &msg->data[0];
409 udt = (struct sccp_data_unitdata *)msgb_put(msg, sizeof(*udt));
410
411 udt->type = SCCP_MSG_TYPE_UDT;
412 udt->proto_class = class;
413 udt->variable_called = 3;
414 udt->variable_calling = 5;
415 udt->variable_data = 7;
416
417 /* for variable data we start with a size and the data */
418 data = msgb_put(msg, 1 + 2);
419 data[0] = 2;
420 data[1] = 0x42;
421 data[2] = out->sccp_ssn;
422
423 data = msgb_put(msg, 1 + 2);
424 data[0] = 2;
425 data[1] = 0x42;
426 data[2] = in->sccp_ssn;
427
428 /* copy the payload */
429 data = msgb_put(msg, 1 + msgb_l3len(payload));
430 data[0] = msgb_l3len(payload);
431 memcpy(&data[1], payload->l3h, msgb_l3len(payload));
432
433 ret = _send_msg(msg);
434 msgb_free(msg);
435
436 return ret;
437}
438
439static int _sccp_handle_read(struct msgb *msgb)
440{
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200441 struct sccp_data_callback *cb;
Holger Hans Peter Freytherefca5412010-01-27 12:12:46 +0100442 struct sccp_parse_result result;
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200443
Holger Hans Peter Freytherefca5412010-01-27 12:12:46 +0100444 if (_sccp_parse_udt(msgb, &result) != 0)
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200445 return -1;
446
Holger Hans Peter Freytherefca5412010-01-27 12:12:46 +0100447 cb = _find_ssn(result.called.ssn);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200448 if (!cb || !cb->read_cb) {
Holger Hans Peter Freytherefca5412010-01-27 12:12:46 +0100449 DEBUGP(DSCCP, "No routing for UDT for called SSN: %u\n", result.called.ssn);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200450 return -1;
451 }
452
453 /* sanity check */
454 return cb->read_cb(msgb, msgb_l3len(msgb), cb->read_context);
455}
456
457/*
458 * handle connection orientated methods
459 */
460static int source_local_reference_is_free(struct sccp_source_reference *reference)
461{
462 struct sccp_connection *connection;
463
464 llist_for_each_entry(connection, &sccp_connections, list) {
465 if (memcmp(reference, &connection->source_local_reference, sizeof(*reference)) == 0)
466 return -1;
467 }
468
469 return 0;
470}
471
472static int destination_local_reference_is_free(struct sccp_source_reference *reference)
473{
474 struct sccp_connection *connection;
475
476 llist_for_each_entry(connection, &sccp_connections, list) {
477 if (memcmp(reference, &connection->destination_local_reference, sizeof(*reference)) == 0)
478 return -1;
479 }
480
481 return 0;
482}
483
484static int assign_source_local_reference(struct sccp_connection *connection)
485{
486 static u_int32_t last_ref = 0x30000;
487 int wrapped = 0;
488
489 do {
490 struct sccp_source_reference reference;
491 reference.octet1 = (last_ref >> 0) & 0xff;
492 reference.octet2 = (last_ref >> 8) & 0xff;
493 reference.octet3 = (last_ref >> 16) & 0xff;
494
495 ++last_ref;
496 /* do not use the reversed word and wrap around */
497 if ((last_ref & 0x00FFFFFF) == 0x00FFFFFF) {
498 DEBUGP(DSCCP, "Wrapped searching for a free code\n");
499 last_ref = 0;
500 ++wrapped;
501 }
502
503 if (source_local_reference_is_free(&reference) == 0) {
504 connection->source_local_reference = reference;
505 return 0;
506 }
507 } while (wrapped != 2);
508
509 DEBUGP(DSCCP, "Finding a free reference failed\n");
510 return -1;
511}
512
513static void _sccp_set_connection_state(struct sccp_connection *connection, int new_state)
514{
515 int old_state = connection->connection_state;
516
517 connection->connection_state = new_state;
518 if (connection->state_cb)
519 connection->state_cb(connection, old_state);
520}
521
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100522static int _sccp_send_refuse(struct sccp_source_reference *src_ref, int cause)
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200523{
524 struct msgb *msgb;
525 struct sccp_connection_refused *ref;
526 u_int8_t *data;
527 int ret;
528
529 msgb = msgb_alloc_headroom(SCCP_MSG_SIZE,
530 SCCP_MSG_HEADROOM, "sccp ref");
531 msgb->l2h = &msgb->data[0];
532
533 ref = (struct sccp_connection_refused *) msgb_put(msgb, sizeof(*ref));
534 ref->type = SCCP_MSG_TYPE_CREF;
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100535 memcpy(&ref->destination_local_reference, src_ref,
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200536 sizeof(struct sccp_source_reference));
537 ref->cause = cause;
538 ref->optional_start = 1;
539
540 data = msgb_put(msgb, 1);
541 data[0] = SCCP_PNC_END_OF_OPTIONAL;
542
543 ret = _send_msg(msgb);
544 msgb_free(msgb);
545 return ret;
546}
547
548static int _sccp_send_connection_confirm(struct sccp_connection *connection)
549{
550 struct msgb *response;
551 struct sccp_connection_confirm *confirm;
552 u_int8_t *optional_data;
553 int ret;
554
555 if (assign_source_local_reference(connection) != 0)
556 return -1;
557
558 response = msgb_alloc_headroom(SCCP_MSG_SIZE,
559 SCCP_MSG_HEADROOM, "sccp confirm");
560 response->l2h = &response->data[0];
561
562 confirm = (struct sccp_connection_confirm *) msgb_put(response, sizeof(*confirm));
563
564 confirm->type = SCCP_MSG_TYPE_CC;
565 memcpy(&confirm->destination_local_reference,
566 &connection->destination_local_reference,
567 sizeof(connection->destination_local_reference));
568 memcpy(&confirm->source_local_reference,
569 &connection->source_local_reference,
570 sizeof(connection->source_local_reference));
571 confirm->proto_class = 2;
572 confirm->optional_start = 1;
573
574 optional_data = (u_int8_t *) msgb_put(response, 1);
575 optional_data[0] = SCCP_PNC_END_OF_OPTIONAL;
576
577 ret = _send_msg(response);
578 msgb_free(response);
579
580 _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_ESTABLISHED);
581 return ret;
582}
583
584static int _sccp_send_connection_request(struct sccp_connection *connection,
585 const struct sockaddr_sccp *called, struct msgb *msg)
586{
587 struct msgb *request;
588 struct sccp_connection_request *req;
589 u_int8_t *data;
590 u_int8_t extra_size = 3 + 1;
591 int ret;
592
593
594 if (msg && (msgb_l3len(msg) < 3 || msgb_l3len(msg) > 130)) {
595 DEBUGP(DSCCP, "Invalid amount of data... %d\n", msgb_l3len(msg));
596 return -1;
597 }
598
599 /* try to find a id */
600 if (assign_source_local_reference(connection) != 0) {
601 DEBUGP(DSCCP, "Assigning a local reference failed.\n");
602 _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_SETUP_ERROR);
603 return -1;
604 }
605
606
607 if (msg)
608 extra_size += 2 + msgb_l3len(msg);
609 request = msgb_alloc_headroom(SCCP_MSG_SIZE,
610 SCCP_MSG_HEADROOM, "sccp connection request");
611 request->l2h = &request->data[0];
612 req = (struct sccp_connection_request *) msgb_put(request, sizeof(*req));
613
614 req->type = SCCP_MSG_TYPE_CR;
615 memcpy(&req->source_local_reference, &connection->source_local_reference,
616 sizeof(connection->source_local_reference));
617 req->proto_class = 2;
618 req->variable_called = 2;
619 req->optional_start = 4;
620
621 /* write the called party address */
622 data = msgb_put(request, 1 + 2);
623 data[0] = 2;
624 data[1] = 0x42;
625 data[2] = called->sccp_ssn;
626
627 /* write the payload */
628 if (msg) {
629 data = msgb_put(request, 2 + msgb_l3len(msg));
630 data[0] = SCCP_PNC_DATA;
631 data[1] = msgb_l3len(msg);
632 memcpy(&data[2], msg->l3h, msgb_l3len(msg));
633 }
634
635 data = msgb_put(request, 1);
636 data[0] = SCCP_PNC_END_OF_OPTIONAL;
637
638 llist_add_tail(&connection->list, &sccp_connections);
639 _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REQUEST);
640
641 ret = _send_msg(request);
642 msgb_free(request);
643
644 return ret;
645}
646
647static int _sccp_send_connection_data(struct sccp_connection *conn, struct msgb *_data)
648{
649 struct msgb *msgb;
650 struct sccp_data_form1 *dt1;
651 u_int8_t *data;
652 int extra_size;
653 int ret;
654
655 if (msgb_l3len(_data) < 2 || msgb_l3len(_data) > 256) {
656 DEBUGP(DSCCP, "data size too big, segmenting unimplemented.\n");
657 return -1;
658 }
659
660 extra_size = 1 + msgb_l3len(_data);
661 msgb = msgb_alloc_headroom(SCCP_MSG_SIZE,
662 SCCP_MSG_HEADROOM, "sccp dt1");
663 msgb->l2h = &msgb->data[0];
664
665 dt1 = (struct sccp_data_form1 *) msgb_put(msgb, sizeof(*dt1));
666 dt1->type = SCCP_MSG_TYPE_DT1;
667 memcpy(&dt1->destination_local_reference, &conn->destination_local_reference,
668 sizeof(struct sccp_source_reference));
669 dt1->segmenting = 0;
670
671 /* copy the data */
672 dt1->variable_start = 1;
673 data = msgb_put(msgb, extra_size);
674 data[0] = extra_size - 1;
675 memcpy(&data[1], _data->l3h, extra_size - 1);
676
677 ret = _send_msg(msgb);
678 msgb_free(msgb);
679
680 return ret;
681}
682
Holger Hans Peter Freyther3b9516e2009-11-18 22:11:28 +0100683static int _sccp_send_connection_it(struct sccp_connection *conn)
684{
685 struct msgb *msgb;
686 struct sccp_data_it *it;
687 int ret;
688
689 msgb = msgb_alloc_headroom(SCCP_MSG_SIZE,
690 SCCP_MSG_HEADROOM, "sccp it");
691 msgb->l2h = &msgb->data[0];
692 it = (struct sccp_data_it *) msgb_put(msgb, sizeof(*it));
693 it->type = SCCP_MSG_TYPE_IT;
694 memcpy(&it->destination_local_reference, &conn->destination_local_reference,
695 sizeof(struct sccp_source_reference));
696 memcpy(&it->source_local_reference, &conn->source_local_reference,
697 sizeof(struct sccp_source_reference));
698
699 it->proto_class = 0x2;
700 it->sequencing[0] = it->sequencing[1] = 0;
701 it->credit = 0;
702
703 ret = _send_msg(msgb);
704 msgb_free(msgb);
705 return ret;
706}
707
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200708static int _sccp_send_connection_released(struct sccp_connection *conn, int cause)
709{
710 struct msgb *msg;
711 struct sccp_connection_released *rel;
712 u_int8_t *data;
713 int ret;
714
715 msg = msgb_alloc_headroom(SCCP_MSG_SIZE, SCCP_MSG_HEADROOM,
716 "sccp: connection released");
717 msg->l2h = &msg->data[0];
718 rel = (struct sccp_connection_released *) msgb_put(msg, sizeof(*rel));
719 rel->type = SCCP_MSG_TYPE_RLSD;
720 rel->release_cause = cause;
721
722 /* copy the source references */
723 memcpy(&rel->destination_local_reference, &conn->destination_local_reference,
724 sizeof(struct sccp_source_reference));
725 memcpy(&rel->source_local_reference, &conn->source_local_reference,
726 sizeof(struct sccp_source_reference));
727
728 data = msgb_put(msg, 1);
729 data[0] = SCCP_PNC_END_OF_OPTIONAL;
730
731 _sccp_set_connection_state(conn, SCCP_CONNECTION_STATE_RELEASE);
732 ret = _send_msg(msg);
733 msgb_free(msg);
734
735 return ret;
736}
737
738/*
739 * Open a connection. The following is going to happen:
740 *
741 * - Verify the packet, e.g. that we have no other connection
742 * that id.
743 * - Ask the user if he wants to accept the connection
744 * - Try to open the connection by assigning a source local reference
745 * and sending the packet
746 */
747static int _sccp_handle_connection_request(struct msgb *msgb)
748{
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100749 struct sccp_parse_result result;
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200750
751 struct sccp_data_callback *cb;
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200752 struct sccp_connection *connection;
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200753
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100754 if (_sccp_parse_connection_request(msgb, &result) != 0)
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200755 return -1;
756
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100757 cb = _find_ssn(result.called.ssn);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200758 if (!cb || !cb->accept_cb) {
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100759 DEBUGP(DSCCP, "No routing for CR for called SSN: %u\n", result.called.ssn);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200760 return -1;
761 }
762
763 /* check if the system wants this connection */
764 connection = talloc_zero(tall_sccp_ctx, struct sccp_connection);
765 if (!connection) {
766 DEBUGP(DSCCP, "Allocation failed\n");
767 return -1;
768 }
769
770 /*
771 * sanity checks:
772 * - Is the source_local_reference in any other connection?
773 * then will call accept, assign a "destination" local reference
774 * and send a connection confirm, otherwise we will send a refuseed
775 * one....
776 */
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100777 if (destination_local_reference_is_free(result.source_local_reference) != 0) {
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200778 DEBUGP(DSCCP, "Need to reject connection with existing reference\n");
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100779 _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200780 talloc_free(connection);
781 return -1;
782 }
783
784 connection->incoming = 1;
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100785 connection->destination_local_reference = *result.source_local_reference;
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200786
787 if (cb->accept_cb(connection, cb->accept_context) != 0) {
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100788 _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_END_USER_ORIGINATED);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200789 _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REFUSED);
790 talloc_free(connection);
791 return 0;
792 }
793
794
795 llist_add_tail(&connection->list, &sccp_connections);
796
797 if (_sccp_send_connection_confirm(connection) != 0) {
798 DEBUGP(DSCCP, "Sending confirm failed... no available source reference?\n");
799
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100800 _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200801 _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REFUSED);
802 llist_del(&connection->list);
803 talloc_free(connection);
804
805 return -1;
806 }
807
808 /*
809 * If we have data let us forward things.
810 */
Holger Hans Peter Freythera8cd2e62010-01-27 12:25:13 +0100811 if (result.data_len != 0 && connection->data_cb) {
812 connection->data_cb(connection, msgb, result.data_len);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200813 }
814
815 return 0;
816}
817
818/* Handle the release confirmed */
819static int _sccp_handle_connection_release_complete(struct msgb *data)
820{
821 static int header_size = sizeof(struct sccp_connection_release_complete);
822
823 struct sccp_connection_release_complete *cmpl;
824 struct sccp_connection *conn;
825
826 /* header check */
827 if (msgb_l2len(data) < header_size) {
828 DEBUGP(DSCCP, "msgb < header_size %u %u\n",
829 msgb_l2len(data), header_size);
830 return -1;
831 }
832
833 cmpl = (struct sccp_connection_release_complete *) data->l2h;
834
835 /* find the connection */
836 llist_for_each_entry(conn, &sccp_connections, list) {
837 if (conn->data_cb
838 && memcmp(&conn->source_local_reference,
839 &cmpl->destination_local_reference,
840 sizeof(conn->source_local_reference)) == 0
841 && memcmp(&conn->destination_local_reference,
842 &cmpl->source_local_reference,
843 sizeof(conn->destination_local_reference)) == 0) {
844 goto found;
845 }
846 }
847
848
849 DEBUGP(DSCCP, "Release complete of unknown connection\n");
850 return -1;
851
852found:
853 llist_del(&conn->list);
854 _sccp_set_connection_state(conn, SCCP_CONNECTION_STATE_RELEASE_COMPLETE);
855 return 0;
856}
857
858/* Handle the Data Form 1 message */
859static int _sccp_handle_connection_dt1(struct msgb *data)
860{
861 static int variable_offset = offsetof(struct sccp_data_form1, variable_start);
862 static int header_size = sizeof(struct sccp_data_form1);
863
864 struct sccp_data_form1 *dt1 = (struct sccp_data_form1 *)data->l2h;
865 struct sccp_connection *conn;
866 int size;
867
868 /* we don't have enough size for the struct */
869 if (msgb_l2len(data) < header_size) {
870 DEBUGP(DSCCP, "msgb > header_size %u %u\n",
871 msgb_l2len(data), header_size);
872 return -1;
873 }
874
875 if (dt1->segmenting != 0) {
876 DEBUGP(DSCCP, "This packet has segmenting, not supported: %d\n", dt1->segmenting);
877 return -1;
878 }
879
880 /* lookup if we have a connection with the given reference */
881 llist_for_each_entry(conn, &sccp_connections, list) {
882 if (conn->data_cb
883 && memcmp(&conn->source_local_reference,
884 &dt1->destination_local_reference,
885 sizeof(conn->source_local_reference)) == 0) {
886
887 /* some more size checks in here */
888 if (msgb_l2len(data) < variable_offset + dt1->variable_start + 1) {
889 DEBUGP(DSCCP, "Not enough space for variable start: %u %u\n",
890 msgb_l2len(data), dt1->variable_start);
891 return -1;
892 }
893
894 size = data->l2h[variable_offset + dt1->variable_start];
895 data->l3h = &data->l2h[dt1->variable_start + variable_offset + 1];
896
897 if (msgb_l3len(data) < size) {
898 DEBUGP(DSCCP, "Not enough room for the payload: %u %u\n",
899 msgb_l3len(data), size);
900 return -1;
901 }
902
903 conn->data_cb(conn, data, size);
904 return 0;
905 }
906 }
907
908 DEBUGP(DSCCP, "No connection found for dt1 data\n");
909 return -1;
910}
911
912/* confirm a connection release */
913static int _sccp_send_connection_release_complete(struct sccp_connection *connection)
914{
915 struct msgb *msgb;
916 struct sccp_connection_release_complete *rlc;
917 int ret;
918
919 msgb = msgb_alloc_headroom(SCCP_MSG_SIZE,
920 SCCP_MSG_HEADROOM, "sccp rlc");
921 msgb->l2h = &msgb->data[0];
922
923 rlc = (struct sccp_connection_release_complete *) msgb_put(msgb, sizeof(*rlc));
924 rlc->type = SCCP_MSG_TYPE_RLC;
925 memcpy(&rlc->destination_local_reference,
926 &connection->destination_local_reference, sizeof(struct sccp_source_reference));
927 memcpy(&rlc->source_local_reference,
928 &connection->source_local_reference, sizeof(struct sccp_source_reference));
929
930 ret = _send_msg(msgb);
931 msgb_free(msgb);
932
933 /*
934 * Remove from the list of active connections and set the state. User code
935 * should now free the entry.
936 */
937 llist_del(&connection->list);
938 _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_RELEASE_COMPLETE);
939
940 return ret;
941}
942
943/* connection released, send a released confirm */
Holger Hans Peter Freyther88fe6ee2010-01-29 03:49:32 +0100944static int _sccp_handle_connection_released(struct msgb *msgb)
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200945{
Holger Hans Peter Freyther88fe6ee2010-01-29 03:49:32 +0100946 struct sccp_parse_result result;
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200947 struct sccp_connection *conn;
948
Holger Hans Peter Freyther88fe6ee2010-01-29 03:49:32 +0100949 if (_sccp_parse_connection_released(msgb, &result) == -1)
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200950 return -1;
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200951
952 /* lookup if we have a connection with the given reference */
953 llist_for_each_entry(conn, &sccp_connections, list) {
954 if (conn->data_cb
955 && memcmp(&conn->source_local_reference,
Holger Hans Peter Freyther88fe6ee2010-01-29 03:49:32 +0100956 result.destination_local_reference,
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200957 sizeof(conn->source_local_reference)) == 0
958 && memcmp(&conn->destination_local_reference,
Holger Hans Peter Freyther88fe6ee2010-01-29 03:49:32 +0100959 result.source_local_reference,
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200960 sizeof(conn->destination_local_reference)) == 0) {
961 goto found;
962 }
963 }
964
965
966 DEBUGP(DSCCP, "Unknown connection was released.\n");
967 return -1;
968
969 /* we have found a connection */
970found:
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200971 /* optional data */
Holger Hans Peter Freyther88fe6ee2010-01-29 03:49:32 +0100972 if (result.data_len != 0 && conn->data_cb) {
973 conn->data_cb(conn, msgb, result.data_len);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200974 }
975
976 /* generate a response */
977 if (_sccp_send_connection_release_complete(conn) != 0) {
978 DEBUGP(DSCCP, "Sending release confirmed failed\n");
979 return -1;
980 }
981
982 return 0;
983}
984
985static int _sccp_handle_connection_refused(struct msgb *msgb)
986{
Holger Hans Peter Freytherfe5de4e2010-01-29 03:58:12 +0100987 struct sccp_parse_result result;
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200988 struct sccp_connection *conn;
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200989
Holger Hans Peter Freytherfe5de4e2010-01-29 03:58:12 +0100990 if (_sccp_parse_connection_refused(msgb, &result) != 0)
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200991 return -1;
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200992
993 /* lookup if we have a connection with the given reference */
994 llist_for_each_entry(conn, &sccp_connections, list) {
995 if (conn->incoming == 0 && conn->data_cb
996 && memcmp(&conn->source_local_reference,
Holger Hans Peter Freytherfe5de4e2010-01-29 03:58:12 +0100997 result.destination_local_reference,
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +0200998 sizeof(conn->source_local_reference)) == 0) {
999 goto found;
1000 }
1001 }
1002
1003 DEBUGP(DSCCP, "Refused but no connection found\n");
1004 return -1;
1005
1006found:
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +02001007 /* optional data */
Holger Hans Peter Freytherfe5de4e2010-01-29 03:58:12 +01001008 if (result.data_len != 0 && conn->data_cb) {
1009 conn->data_cb(conn, msgb, result.data_len);
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +02001010 }
1011
1012
1013 llist_del(&conn->list);
1014 _sccp_set_connection_state(conn, SCCP_CONNECTION_STATE_REFUSED);
1015 return 0;
1016}
1017
1018static int _sccp_handle_connection_confirm(struct msgb *msgb)
1019{
1020 static u_int32_t header_size =
1021 sizeof(struct sccp_connection_confirm);
1022 static const u_int32_t optional_offset =
1023 offsetof(struct sccp_connection_confirm, optional_start);
1024
1025 struct sccp_optional_data optional_data;
1026 struct sccp_connection *conn;
1027 struct sccp_connection_confirm *con;
1028
1029 /* header check */
1030 if (msgb_l2len(msgb) < header_size) {
1031 DEBUGP(DSCCP, "msgb < header_size %u %u\n",
1032 msgb_l2len(msgb), header_size);
1033 return -1;
1034 }
1035
1036 con = (struct sccp_connection_confirm *) msgb->l2h;
1037
1038 /* lookup if we have a connection with the given reference */
1039 llist_for_each_entry(conn, &sccp_connections, list) {
1040 if (conn->incoming == 0 && conn->data_cb
1041 && memcmp(&conn->source_local_reference,
1042 &con->destination_local_reference,
1043 sizeof(conn->source_local_reference)) == 0) {
1044 goto found;
1045 }
1046 }
1047
1048 DEBUGP(DSCCP, "Confirmed but no connection found\n");
1049 return -1;
1050
1051found:
1052 /* copy the addresses of the connection */
1053 conn->destination_local_reference = con->source_local_reference;
1054 _sccp_set_connection_state(conn, SCCP_CONNECTION_STATE_ESTABLISHED);
1055
1056 memset(&optional_data, 0, sizeof(optional_data));
1057 if (_sccp_parse_optional_data(optional_offset + con->optional_start, msgb, &optional_data) != 0) {
1058 DEBUGP(DSCCP, "parsing of optional data failed.\n");
1059 return -1;
1060 }
1061
1062 /* optional data */
1063 if (optional_data.data_len != 0 && conn->data_cb) {
1064 msgb->l3h = &msgb->l2h[optional_data.data_start];
1065 conn->data_cb(conn, msgb, optional_data.data_len);
1066 }
1067
1068 return 0;
1069}
1070
1071
1072int sccp_system_init(int (*outgoing)(struct msgb *data, void *ctx), void *ctx)
1073{
1074 sccp_system.write_data = outgoing;
1075 sccp_system.write_context = ctx;
1076
1077 return 0;
1078}
1079
1080/* oh my god a real SCCP packet. need to dispatch it now */
1081int sccp_system_incoming(struct msgb *msgb)
1082{
1083 if (msgb_l2len(msgb) < 1 ) {
1084 DEBUGP(DSCCP, "Too short packet\n");
1085 return -1;
1086 }
1087
1088 int type = msgb->l2h[0];
1089
1090 switch(type) {
1091 case SCCP_MSG_TYPE_CR:
1092 return _sccp_handle_connection_request(msgb);
1093 break;
1094 case SCCP_MSG_TYPE_RLSD:
1095 return _sccp_handle_connection_released(msgb);
1096 break;
1097 case SCCP_MSG_TYPE_CREF:
1098 return _sccp_handle_connection_refused(msgb);
1099 break;
1100 case SCCP_MSG_TYPE_CC:
1101 return _sccp_handle_connection_confirm(msgb);
1102 break;
1103 case SCCP_MSG_TYPE_RLC:
1104 return _sccp_handle_connection_release_complete(msgb);
1105 break;
1106 case SCCP_MSG_TYPE_DT1:
1107 return _sccp_handle_connection_dt1(msgb);
1108 break;
1109 case SCCP_MSG_TYPE_UDT:
1110 return _sccp_handle_read(msgb);
1111 break;
1112 default:
1113 DEBUGP(DSCCP, "unimplemented msg type: %d\n", type);
1114 };
1115
1116 return -1;
1117}
1118
1119/* create a packet from the data */
1120int sccp_connection_write(struct sccp_connection *connection, struct msgb *data)
1121{
1122 if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
1123 || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
1124 DEBUGP(DSCCP, "sccp_connection_write: Wrong connection state: %p %d\n",
1125 connection, connection->connection_state);
1126 return -1;
1127 }
1128
1129 return _sccp_send_connection_data(connection, data);
1130}
1131
Holger Hans Peter Freyther3b9516e2009-11-18 22:11:28 +01001132/*
1133 * Send a Inactivity Test message. The owner of the connection
1134 * should start a timer and call this method regularily. Calling
1135 * this every 60 seconds should be good enough.
1136 */
1137int sccp_connection_send_it(struct sccp_connection *connection)
1138{
1139 if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
1140 || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
1141 DEBUGP(DSCCP, "sccp_connection_write: Wrong connection state: %p %d\n",
1142 connection, connection->connection_state);
1143 return -1;
1144 }
1145
1146 return _sccp_send_connection_it(connection);
1147}
1148
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +02001149/* send a connection release and wait for the connection released */
1150int sccp_connection_close(struct sccp_connection *connection, int cause)
1151{
1152 if (connection->connection_state < SCCP_CONNECTION_STATE_CONFIRM
1153 || connection->connection_state > SCCP_CONNECTION_STATE_ESTABLISHED) {
1154 DEBUGPC(DSCCP, "Can not close the connection. It was never opened: %p %d\n",
1155 connection, connection->connection_state);
1156 return -1;
1157 }
1158
1159 return _sccp_send_connection_released(connection, cause);
1160}
1161
1162int sccp_connection_free(struct sccp_connection *connection)
1163{
1164 if (connection->connection_state > SCCP_CONNECTION_STATE_NONE
1165 && connection->connection_state < SCCP_CONNECTION_STATE_RELEASE_COMPLETE) {
1166 DEBUGP(DSCCP, "The connection needs to be released before it is freed");
1167 return -1;
1168 }
1169
1170 talloc_free(connection);
1171 return 0;
1172}
1173
1174struct sccp_connection *sccp_connection_socket(void)
1175{
1176 return talloc_zero(tall_sccp_ctx, struct sccp_connection);
1177}
1178
1179int sccp_connection_connect(struct sccp_connection *conn,
1180 const struct sockaddr_sccp *local,
1181 struct msgb *data)
1182{
1183 return _sccp_send_connection_request(conn, local, data);
1184}
1185
1186int sccp_connection_set_incoming(const struct sockaddr_sccp *sock,
1187 int (*accept_cb)(struct sccp_connection *, void *), void *context)
1188{
1189 struct sccp_data_callback *cb;
1190
1191 if (!sock)
1192 return -2;
1193
1194 cb = _find_ssn(sock->sccp_ssn);
1195 if (!cb)
1196 return -1;
1197
1198 cb->accept_cb = accept_cb;
1199 cb->accept_context = context;
1200 return 0;
1201}
1202
1203int sccp_write(struct msgb *data, const struct sockaddr_sccp *in,
1204 const struct sockaddr_sccp *out, int class)
1205{
1206 return _sccp_send_data(class, in, out, data);
1207}
1208
1209int sccp_set_read(const struct sockaddr_sccp *sock,
1210 int (*read_cb)(struct msgb *, unsigned int, void *), void *context)
1211{
1212 struct sccp_data_callback *cb;
1213
1214 if (!sock)
1215 return -2;
1216
1217 cb = _find_ssn(sock->sccp_ssn);
1218 if (!cb)
1219 return -1;
1220
1221 cb->read_cb = read_cb;
1222 cb->read_context = context;
1223 return 0;
1224}
1225
1226static_assert(sizeof(struct sccp_source_reference) <= sizeof(u_int32_t), enough_space);
1227
1228u_int32_t sccp_src_ref_to_int(struct sccp_source_reference *ref)
1229{
1230 u_int32_t src_ref = 0;
1231 memcpy(&src_ref, ref, sizeof(*ref));
1232 return src_ref;
1233}
1234
1235struct sccp_source_reference sccp_src_ref_from_int(u_int32_t int_ref)
1236{
1237 struct sccp_source_reference ref;
1238 memcpy(&ref, &int_ref, sizeof(ref));
1239 return ref;
1240}
1241
Holger Hans Peter Freythera692fbc2010-01-13 09:55:43 +01001242int sccp_determine_msg_type(struct msgb *msg)
1243{
1244 if (msgb_l2len(msg) < 1)
1245 return -1;
1246
1247 return msg->l2h[0];
1248}
1249
Holger Hans Peter Freytherac967702009-07-29 07:37:48 +02001250static __attribute__((constructor)) void on_dso_load(void)
1251{
1252 tall_sccp_ctx = talloc_named_const(NULL, 1, "sccp");
1253}
1254
1255static __attribute__((destructor)) void on_dso_unload(void)
1256{
1257 talloc_report_full(tall_sccp_ctx, stderr);
1258}