-
Notifications
You must be signed in to change notification settings - Fork 14
/
pri_cc.c
7883 lines (7281 loc) · 227 KB
/
pri_cc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* libpri: An implementation of Primary Rate ISDN
*
* Copyright (C) 2009 Digium, Inc.
*
* Richard Mudgett <[email protected]>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2 as published by the
* Free Software Foundation. See the LICENSE file included with
* this program for more details.
*
* In addition, when this program is distributed with Asterisk in
* any form that would qualify as a 'combined work' or as a
* 'derivative work' (but not mere aggregation), you can redistribute
* and/or modify the combination under the terms of the license
* provided with that copy of Asterisk, instead of the license
* terms granted here.
*/
/*!
* \file
* \brief Call Completion controller
*
* \author Richard Mudgett <[email protected]>
*/
#include "compat.h"
#include "libpri.h"
#include "pri_internal.h"
#include "pri_facility.h"
#include <stdlib.h>
/* Define CC_SANITY_CHECKS to add some consistency sanity checking. */
//#define CC_SANITY_CHECKS 1
#define CC_SANITY_CHECKS 1// BUGBUG
/*! Maximum times CCBSStatusRequest can have no response before canceling CC. */
#define RAW_STATUS_COUNT_MAX 3
/* ------------------------------------------------------------------- */
/*!
* \brief Find a cc_record by the PTMP reference_id.
*
* \param ctrl D channel controller.
* \param reference_id CCBS reference ID to look for in cc_record pool.
*
* \retval cc_record on success.
* \retval NULL on error.
*/
struct pri_cc_record *pri_cc_find_by_reference(struct pri *ctrl, unsigned reference_id)
{
struct pri_cc_record *cc_record;
for (cc_record = ctrl->cc.pool; cc_record; cc_record = cc_record->next) {
if (cc_record->ccbs_reference_id == reference_id) {
/* Found the record */
break;
}
}
return cc_record;
}
/*!
* \brief Find a cc_record by the PTMP linkage_id.
*
* \param ctrl D channel controller.
* \param linkage_id Call linkage ID to look for in cc_record pool.
*
* \retval cc_record on success.
* \retval NULL on error.
*/
struct pri_cc_record *pri_cc_find_by_linkage(struct pri *ctrl, unsigned linkage_id)
{
struct pri_cc_record *cc_record;
for (cc_record = ctrl->cc.pool; cc_record; cc_record = cc_record->next) {
if (cc_record->call_linkage_id == linkage_id) {
/* Found the record */
break;
}
}
return cc_record;
}
/*!
* \internal
* \brief Find a cc_record by the cc_id.
*
* \param ctrl D channel controller.
* \param cc_id ID to look for in cc_record pool.
*
* \retval cc_record on success.
* \retval NULL on error.
*/
static struct pri_cc_record *pri_cc_find_by_id(struct pri *ctrl, long cc_id)
{
struct pri_cc_record *cc_record;
for (cc_record = ctrl->cc.pool; cc_record; cc_record = cc_record->next) {
if (cc_record->record_id == cc_id) {
/* Found the record */
break;
}
}
return cc_record;
}
/*!
* \internal
* \brief Find the given ie_type in the string of q931 ies.
*
* \param ie_type Q.931 ie type to find in q931_ies.
* \param length Length of the given q931_ies
* \param q931_ies Given q931_ies
*
* \retval found-ie on success.
* \retval NULL on error.
*/
static const struct q931_ie *pri_cc_find_ie(unsigned ie_type, unsigned length, const unsigned char *q931_ies)
{
const unsigned char *pos;
const unsigned char *end;
const unsigned char *next;
const struct q931_ie *cur;
end = q931_ies + length;
for (pos = q931_ies; pos < end; pos = next) {
cur = (const struct q931_ie *) pos;
if (cur->ie & 0x80) {
/* Single octet ie. */
next = pos + 1;
} else {
/* Variable length ie. */
next = cur->data + cur->len;
}
if (cur->ie == ie_type && next <= end) {
/* Found the ie and it is within the given q931_ies body. */
return cur;
}
}
return NULL;
}
/*!
* \internal
* \brief Compare the specified ie type in the CC record q931_ies to the given q931_ies.
*
* \details
* The individual q931 ie is compared with memcmp().
*
* \param ie_type Q.931 ie type to compare.
* \param record_ies CC record q931_ies
* \param length Length of the given q931_ies
* \param q931_ies Given q931_ies
*
* \retval == 0 when record_ies == q931_ies.
* \retval != 0 when record_ies != q931_ies.
*/
static int pri_cc_cmp_ie(unsigned ie_type, const struct q931_saved_ie_contents *record_ies, unsigned length, const unsigned char *q931_ies)
{
const struct q931_ie *left;
const struct q931_ie *right;
left = pri_cc_find_ie(ie_type, record_ies->length, record_ies->data);
right = pri_cc_find_ie(ie_type, length, q931_ies);
if (!left && !right) {
/* Neither has the requested ie to compare so they match. */
return 0;
}
if (!left || !right) {
/* One or the other does not have the requested ie to compare. */
return 1;
}
if (left->len != right->len) {
/* They are not the same length. */
return 1;
}
return memcmp(left->data, right->data, right->len);
}
/*!
* \internal
* \brief Compare the CC record q931_ies to the given q931_ies.
*
* \note
* Only the first BC, HLC, and LLC ies in the given q931_ies are compared.
*
* \param record_ies CC record q931_ies
* \param length Length of the given q931_ies
* \param q931_ies Given q931_ies
*
* \retval == 0 when record_ies == q931_ies.
* \retval != 0 when record_ies != q931_ies.
*/
static int pri_cc_cmp_q931_ies(const struct q931_saved_ie_contents *record_ies, unsigned length, const unsigned char *q931_ies)
{
return pri_cc_cmp_ie(Q931_BEARER_CAPABILITY, record_ies, length, q931_ies)
|| pri_cc_cmp_ie(Q931_HIGH_LAYER_COMPAT, record_ies, length, q931_ies)
|| pri_cc_cmp_ie(Q931_LOW_LAYER_COMPAT, record_ies, length, q931_ies);
}
/*!
* \brief Find a cc_record by an incoming call addressing data.
*
* \param ctrl D channel controller.
* \param party_a Party A address.
* \param party_b Party B address.
* \param length Length of the given q931_ies.
* \param q931_ies BC, HLC, LLC ies to compare with CC records.
*
* \retval cc_record on success.
* \retval NULL on error.
*/
struct pri_cc_record *pri_cc_find_by_addressing(struct pri *ctrl, const struct q931_party_address *party_a, const struct q931_party_address *party_b, unsigned length, const unsigned char *q931_ies)
{
struct pri_cc_record *cc_record;
struct q931_party_address addr_a;
struct q931_party_address addr_b;
addr_a = *party_a;
addr_b = *party_b;
for (cc_record = ctrl->cc.pool; cc_record; cc_record = cc_record->next) {
/* Do not compare the number presentation. */
addr_a.number.presentation = cc_record->party_a.number.presentation;
addr_b.number.presentation = cc_record->party_b.number.presentation;
if (!q931_cmp_party_id_to_address(&cc_record->party_a, &addr_a)
&& !q931_party_address_cmp(&cc_record->party_b, &addr_b)
&& !pri_cc_cmp_q931_ies(&cc_record->saved_ie_contents, length, q931_ies)) {
/* Found the record */
break;
}
}
return cc_record;
}
/*!
* \internal
* \brief Allocate a new cc_record reference id.
*
* \param ctrl D channel controller.
*
* \retval reference_id on success.
* \retval CC_PTMP_INVALID_ID on error.
*/
static int pri_cc_new_reference_id(struct pri *ctrl)
{
long reference_id;
long first_id;
ctrl->cc.last_reference_id = (ctrl->cc.last_reference_id + 1) & 0x7F;
reference_id = ctrl->cc.last_reference_id;
first_id = reference_id;
while (pri_cc_find_by_reference(ctrl, reference_id)) {
ctrl->cc.last_reference_id = (ctrl->cc.last_reference_id + 1) & 0x7F;
reference_id = ctrl->cc.last_reference_id;
if (reference_id == first_id) {
/* We probably have a resource leak. */
pri_error(ctrl, "PTMP call completion reference id exhaustion!\n");
reference_id = CC_PTMP_INVALID_ID;
break;
}
}
return reference_id;
}
/*!
* \internal
* \brief Allocate a new cc_record linkage id.
*
* \param ctrl D channel controller.
*
* \retval linkage_id on success.
* \retval CC_PTMP_INVALID_ID on error.
*/
static int pri_cc_new_linkage_id(struct pri *ctrl)
{
long linkage_id;
long first_id;
ctrl->cc.last_linkage_id = (ctrl->cc.last_linkage_id + 1) & 0x7F;
linkage_id = ctrl->cc.last_linkage_id;
first_id = linkage_id;
while (pri_cc_find_by_linkage(ctrl, linkage_id)) {
ctrl->cc.last_linkage_id = (ctrl->cc.last_linkage_id + 1) & 0x7F;
linkage_id = ctrl->cc.last_linkage_id;
if (linkage_id == first_id) {
/* We probably have a resource leak. */
pri_error(ctrl, "PTMP call completion linkage id exhaustion!\n");
linkage_id = CC_PTMP_INVALID_ID;
break;
}
}
return linkage_id;
}
/*!
* \internal
* \brief Allocate a new cc_record id.
*
* \param ctrl D channel controller.
*
* \retval cc_id on success.
* \retval -1 on error.
*/
static long pri_cc_new_id(struct pri *ctrl)
{
long record_id;
long first_id;
record_id = ++ctrl->cc.last_record_id;
first_id = record_id;
while (pri_cc_find_by_id(ctrl, record_id)) {
record_id = ++ctrl->cc.last_record_id;
if (record_id == first_id) {
/*
* We have a resource leak.
* We should never need to allocate 64k records on a D channel.
*/
pri_error(ctrl, "Too many call completion records!\n");
record_id = -1;
break;
}
}
return record_id;
}
/*!
* \internal
* \brief Disassociate the signaling link call from the cc_record.
*
* \param cc_record CC record to disassociate from the signaling link call.
*
* \return Nothing
*/
static void pri_cc_disassociate_signaling_link(struct pri_cc_record *cc_record)
{
if (cc_record->signaling) {
cc_record->signaling->cc.record = NULL;
cc_record->signaling = NULL;
}
}
/*!
* \internal
* \brief Delete the given call completion record
*
* \param ctrl D channel controller.
* \param doomed Call completion record to destroy
*
* \return Nothing
*/
static void pri_cc_delete_record(struct pri *ctrl, struct pri_cc_record *doomed)
{
struct pri_cc_record **prev;
struct pri_cc_record *current;
/* Unlink CC signaling link associations. */
if (doomed->original_call) {
doomed->original_call->cc.record = NULL;
doomed->original_call = NULL;
}
pri_cc_disassociate_signaling_link(doomed);
for (prev = &ctrl->cc.pool, current = ctrl->cc.pool; current;
prev = ¤t->next, current = current->next) {
if (current == doomed) {
*prev = current->next;
free(doomed);
return;
}
}
/* The doomed node is not in the call completion database */
}
/*!
* \brief Allocate a new cc_record.
*
* \param ctrl D channel controller.
* \param call Q.931 call leg.
*
* \retval pointer to new call completion record
* \retval NULL if failed
*/
struct pri_cc_record *pri_cc_new_record(struct pri *ctrl, q931_call *call)
{
struct pri_cc_record *cc_record;
long record_id;
record_id = pri_cc_new_id(ctrl);
if (record_id < 0) {
return NULL;
}
cc_record = calloc(1, sizeof(*cc_record));
if (!cc_record) {
return NULL;
}
/* Initialize the new record */
cc_record->ctrl = ctrl;
cc_record->record_id = record_id;
cc_record->call_linkage_id = CC_PTMP_INVALID_ID;/* So it will never be found this way */
cc_record->ccbs_reference_id = CC_PTMP_INVALID_ID;/* So it will never be found this way */
cc_record->party_a = call->cc.party_a;
cc_record->party_b = call->called;
cc_record->saved_ie_contents = call->cc.saved_ie_contents;
cc_record->bc = call->bc;
cc_record->option.recall_mode = ctrl->cc.option.recall_mode;
/*
* Append the new record to the end of the list so they are in
* cronological order for interrogations.
*/
if (ctrl->cc.pool) {
struct pri_cc_record *cur;
for (cur = ctrl->cc.pool; cur->next; cur = cur->next) {
}
cur->next = cc_record;
} else {
ctrl->cc.pool = cc_record;
}
return cc_record;
}
/*!
* \internal
* \brief Encode ETSI PTP call completion event operation message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param pos Starting position to encode the facility ie contents.
* \param end End of facility ie contents encoding data buffer.
* \param operation PTP call completion event operation to encode.
*
* \retval Start of the next ASN.1 component to encode on success.
* \retval NULL on error.
*/
static unsigned char *enc_etsi_ptp_cc_operation(struct pri *ctrl, unsigned char *pos,
unsigned char *end, enum rose_operation operation)
{
struct rose_msg_invoke msg;
pos = facility_encode_header(ctrl, pos, end, NULL);
if (!pos) {
return NULL;
}
memset(&msg, 0, sizeof(msg));
msg.invoke_id = get_invokeid(ctrl);
msg.operation = operation;
pos = rose_encode_invoke(ctrl, pos, end, &msg);
return pos;
}
/*!
* \internal
* \brief Encode ETSI PTMP call completion available message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param pos Starting position to encode the facility ie contents.
* \param end End of facility ie contents encoding data buffer.
* \param cc_record Call completion record to process event.
*
* \retval Start of the next ASN.1 component to encode on success.
* \retval NULL on error.
*/
static unsigned char *enc_etsi_ptmp_cc_available(struct pri *ctrl, unsigned char *pos,
unsigned char *end, struct pri_cc_record *cc_record)
{
struct rose_msg_invoke msg;
pos = facility_encode_header(ctrl, pos, end, NULL);
if (!pos) {
return NULL;
}
memset(&msg, 0, sizeof(msg));
msg.invoke_id = get_invokeid(ctrl);
msg.operation = ROSE_ETSI_CallInfoRetain;
msg.args.etsi.CallInfoRetain.call_linkage_id = cc_record->call_linkage_id;
pos = rose_encode_invoke(ctrl, pos, end, &msg);
return pos;
}
/*!
* \internal
* \brief Encode and queue a cc-available message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param call Call leg from which to encode call completion available.
* \param cc_record Call completion record to process event.
* \param msgtype Q.931 message type to put facility ie in.
*
* \retval 0 on success.
* \retval -1 on error.
*/
static int rose_cc_available_encode(struct pri *ctrl, q931_call *call, struct pri_cc_record *cc_record, int msgtype)
{
unsigned char buffer[256];
unsigned char *end;
switch (ctrl->switchtype) {
case PRI_SWITCH_EUROISDN_E1:
case PRI_SWITCH_EUROISDN_T1:
if (PTMP_MODE(ctrl)) {
end =
enc_etsi_ptmp_cc_available(ctrl, buffer, buffer + sizeof(buffer),
cc_record);
} else {
end =
enc_etsi_ptp_cc_operation(ctrl, buffer, buffer + sizeof(buffer),
ROSE_ETSI_CCBS_T_Available);
}
break;
case PRI_SWITCH_QSIG:
/* Q.SIG does not have a cc-available type message. */
return 0;
default:
return -1;
}
if (!end) {
return -1;
}
return pri_call_apdu_queue(call, msgtype, buffer, end - buffer, NULL);
}
/*!
* \internal
* \brief Encode ETSI PTMP EraseCallLinkageID message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param pos Starting position to encode the facility ie contents.
* \param end End of facility ie contents encoding data buffer.
* \param cc_record Call completion record to process event.
*
* \retval Start of the next ASN.1 component to encode on success.
* \retval NULL on error.
*/
static unsigned char *enc_etsi_ptmp_erase_call_linkage(struct pri *ctrl,
unsigned char *pos, unsigned char *end, struct pri_cc_record *cc_record)
{
struct rose_msg_invoke msg;
pos = facility_encode_header(ctrl, pos, end, NULL);
if (!pos) {
return NULL;
}
memset(&msg, 0, sizeof(msg));
msg.invoke_id = get_invokeid(ctrl);
msg.operation = ROSE_ETSI_EraseCallLinkageID;
msg.args.etsi.EraseCallLinkageID.call_linkage_id = cc_record->call_linkage_id;
pos = rose_encode_invoke(ctrl, pos, end, &msg);
return pos;
}
/*!
* \internal
* \brief Encode and queue an EraseCallLinkageID message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param call Call leg from which to encode EraseCallLinkageID.
* \param cc_record Call completion record to process event.
*
* \retval 0 on success.
* \retval -1 on error.
*/
static int rose_erase_call_linkage_encode(struct pri *ctrl, q931_call *call, struct pri_cc_record *cc_record)
{
unsigned char buffer[256];
unsigned char *end;
end =
enc_etsi_ptmp_erase_call_linkage(ctrl, buffer, buffer + sizeof(buffer),
cc_record);
if (!end) {
return -1;
}
return pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer, NULL);
}
/*!
* \internal
* \brief Encode and send an EraseCallLinkageID message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param call Call leg from which to encode EraseCallLinkageID.
* \param cc_record Call completion record to process event.
*
* \retval 0 on success.
* \retval -1 on error.
*/
static int send_erase_call_linkage_id(struct pri *ctrl, q931_call *call, struct pri_cc_record *cc_record)
{
if (rose_erase_call_linkage_encode(ctrl, call, cc_record)
|| q931_facility(ctrl, call)) {
pri_message(ctrl,
"Could not schedule facility message for EraseCallLinkageID.\n");
return -1;
}
return 0;
}
/*!
* \internal
* \brief Encode ETSI PTMP CCBSErase message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param pos Starting position to encode the facility ie contents.
* \param end End of facility ie contents encoding data buffer.
* \param cc_record Call completion record to process event.
* \param reason CCBS Erase reason
* normal-unspecified(0), t-CCBS2-timeout(1), t-CCBS3-timeout(2), basic-call-failed(3)
*
* \retval Start of the next ASN.1 component to encode on success.
* \retval NULL on error.
*/
static unsigned char *enc_etsi_ptmp_ccbs_erase(struct pri *ctrl,
unsigned char *pos, unsigned char *end, struct pri_cc_record *cc_record, int reason)
{
struct rose_msg_invoke msg;
pos = facility_encode_header(ctrl, pos, end, NULL);
if (!pos) {
return NULL;
}
memset(&msg, 0, sizeof(msg));
msg.invoke_id = get_invokeid(ctrl);
msg.operation = ROSE_ETSI_CCBSErase;
if (cc_record->saved_ie_contents.length
<= sizeof(msg.args.etsi.CCBSErase.q931ie_contents)) {
/* Saved BC, HLC, and LLC from initial SETUP */
msg.args.etsi.CCBSErase.q931ie.length = cc_record->saved_ie_contents.length;
memcpy(msg.args.etsi.CCBSErase.q931ie.contents, cc_record->saved_ie_contents.data,
cc_record->saved_ie_contents.length);
} else {
pri_error(ctrl, "CCBSErase q931 ie contents did not fit.\n");
}
q931_copy_address_to_rose(ctrl, &msg.args.etsi.CCBSErase.address_of_b,
&cc_record->party_b);
msg.args.etsi.CCBSErase.recall_mode = cc_record->option.recall_mode;
msg.args.etsi.CCBSErase.ccbs_reference = cc_record->ccbs_reference_id;
msg.args.etsi.CCBSErase.reason = reason;
pos = rose_encode_invoke(ctrl, pos, end, &msg);
return pos;
}
/*!
* \internal
* \brief Encode and queue an CCBSErase message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param call Call leg from which to encode CCBSErase.
* \param cc_record Call completion record to process event.
* \param reason CCBS Erase reason
* normal-unspecified(0), t-CCBS2-timeout(1), t-CCBS3-timeout(2), basic-call-failed(3)
*
* \retval 0 on success.
* \retval -1 on error.
*/
static int rose_ccbs_erase_encode(struct pri *ctrl, q931_call *call, struct pri_cc_record *cc_record, int reason)
{
unsigned char buffer[256];
unsigned char *end;
end =
enc_etsi_ptmp_ccbs_erase(ctrl, buffer, buffer + sizeof(buffer), cc_record,
reason);
if (!end) {
return -1;
}
return pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer, NULL);
}
/*!
* \internal
* \brief Encode and send an CCBSErase message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param call Call leg from which to encode EraseCallLinkageID.
* \param cc_record Call completion record to process event.
* \param reason CCBS Erase reason
* normal-unspecified(0), t-CCBS2-timeout(1), t-CCBS3-timeout(2), basic-call-failed(3)
*
* \retval 0 on success.
* \retval -1 on error.
*/
static int send_ccbs_erase(struct pri *ctrl, q931_call *call, struct pri_cc_record *cc_record, int reason)
{
/*
* XXX May need to add called-party-ie with Party A number in FACILITY message. (CCBSErase)
* ETSI EN 300-195-1 Section 5.41 MSN interaction.
*/
if (rose_ccbs_erase_encode(ctrl, call, cc_record, reason)
|| q931_facility(ctrl, call)) {
pri_message(ctrl,
"Could not schedule facility message for CCBSErase.\n");
return -1;
}
return 0;
}
/*!
* \internal
* \brief Encode ETSI PTMP CCBSStatusRequest result message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param pos Starting position to encode the facility ie contents.
* \param end End of facility ie contents encoding data buffer.
* \param cc_record Call completion record to process event.
* \param is_free TRUE if the Party A status is available.
*
* \retval Start of the next ASN.1 component to encode on success.
* \retval NULL on error.
*/
static unsigned char *enc_etsi_ptmp_ccbs_status_request_rsp(struct pri *ctrl,
unsigned char *pos, unsigned char *end, struct pri_cc_record *cc_record, int is_free)
{
struct rose_msg_result msg;
pos = facility_encode_header(ctrl, pos, end, NULL);
if (!pos) {
return NULL;
}
memset(&msg, 0, sizeof(msg));
msg.invoke_id = cc_record->response.invoke_id;
msg.operation = ROSE_ETSI_CCBSStatusRequest;
msg.args.etsi.CCBSStatusRequest.free = is_free;
pos = rose_encode_result(ctrl, pos, end, &msg);
return pos;
}
/*!
* \internal
* \brief Encode ETSI PTMP CCBSStatusRequest message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param pos Starting position to encode the facility ie contents.
* \param end End of facility ie contents encoding data buffer.
* \param cc_record Call completion record to process event.
*
* \retval Start of the next ASN.1 component to encode on success.
* \retval NULL on error.
*/
static unsigned char *enc_etsi_ptmp_ccbs_status_request(struct pri *ctrl,
unsigned char *pos, unsigned char *end, struct pri_cc_record *cc_record)
{
struct rose_msg_invoke msg;
pos = facility_encode_header(ctrl, pos, end, NULL);
if (!pos) {
return NULL;
}
memset(&msg, 0, sizeof(msg));
msg.invoke_id = get_invokeid(ctrl);
msg.operation = ROSE_ETSI_CCBSStatusRequest;
if (cc_record->saved_ie_contents.length
<= sizeof(msg.args.etsi.CCBSStatusRequest.q931ie_contents)) {
/* Saved BC, HLC, and LLC from initial SETUP */
msg.args.etsi.CCBSStatusRequest.q931ie.length =
cc_record->saved_ie_contents.length;
memcpy(msg.args.etsi.CCBSStatusRequest.q931ie.contents,
cc_record->saved_ie_contents.data, cc_record->saved_ie_contents.length);
} else {
pri_error(ctrl, "CCBSStatusRequest q931 ie contents did not fit.\n");
}
msg.args.etsi.CCBSStatusRequest.recall_mode = cc_record->option.recall_mode;
msg.args.etsi.CCBSStatusRequest.ccbs_reference = cc_record->ccbs_reference_id;
pos = rose_encode_invoke(ctrl, pos, end, &msg);
return pos;
}
/*!
* \internal
* \brief Encode ETSI PTMP CCBSRequest/CCNRRequest message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param pos Starting position to encode the facility ie contents.
* \param end End of facility ie contents encoding data buffer.
* \param cc_record Call completion record to process event.
*
* \retval Start of the next ASN.1 component to encode on success.
* \retval NULL on error.
*/
static unsigned char *enc_etsi_ptmp_cc_request(struct pri *ctrl,
unsigned char *pos, unsigned char *end, struct pri_cc_record *cc_record)
{
struct rose_msg_invoke msg;
pos = facility_encode_header(ctrl, pos, end, NULL);
if (!pos) {
return NULL;
}
memset(&msg, 0, sizeof(msg));
msg.invoke_id = get_invokeid(ctrl);
msg.operation = cc_record->is_ccnr ? ROSE_ETSI_CCNRRequest : ROSE_ETSI_CCBSRequest;
msg.args.etsi.CCBSRequest.call_linkage_id = cc_record->call_linkage_id;
pos = rose_encode_invoke(ctrl, pos, end, &msg);
return pos;
}
/*!
* \internal
* \brief Encode ETSI PTP CCBS_T_Request/CCNR_T_Request message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param pos Starting position to encode the facility ie contents.
* \param end End of facility ie contents encoding data buffer.
* \param cc_record Call completion record to process event.
*
* \retval Start of the next ASN.1 component to encode on success.
* \retval NULL on error.
*/
static unsigned char *enc_etsi_ptp_cc_request(struct pri *ctrl,
unsigned char *pos, unsigned char *end, struct pri_cc_record *cc_record)
{
struct rose_msg_invoke msg;
pos = facility_encode_header(ctrl, pos, end, NULL);
if (!pos) {
return NULL;
}
memset(&msg, 0, sizeof(msg));
msg.invoke_id = get_invokeid(ctrl);
msg.operation = cc_record->is_ccnr
? ROSE_ETSI_CCNR_T_Request : ROSE_ETSI_CCBS_T_Request;
if (cc_record->saved_ie_contents.length
<= sizeof(msg.args.etsi.CCBS_T_Request.q931ie_contents)) {
/* Saved BC, HLC, and LLC from initial SETUP */
msg.args.etsi.CCBS_T_Request.q931ie.length = cc_record->saved_ie_contents.length;
memcpy(msg.args.etsi.CCBS_T_Request.q931ie.contents,
cc_record->saved_ie_contents.data, cc_record->saved_ie_contents.length);
} else {
pri_error(ctrl, "CCBS_T_Request q931 ie contents did not fit.\n");
}
q931_copy_address_to_rose(ctrl, &msg.args.etsi.CCBS_T_Request.destination,
&cc_record->party_b);
if (cc_record->party_a.number.valid && cc_record->party_a.number.str[0]) {
q931_copy_id_address_to_rose(ctrl, &msg.args.etsi.CCBS_T_Request.originating,
&cc_record->party_a);
msg.args.etsi.CCBS_T_Request.presentation_allowed_indicator_present = 1;
if ((cc_record->party_a.number.presentation & PRI_PRES_RESTRICTION)
== PRI_PRES_ALLOWED) {
msg.args.etsi.CCBS_T_Request.presentation_allowed_indicator = 1;
}
}
//msg.args.etsi.CCBS_T_Request.retention_supported = 0;
pos = rose_encode_invoke(ctrl, pos, end, &msg);
return pos;
}
/*!
* \internal
* \brief Encode Q.SIG ccbsRequest/ccnrRequest message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param pos Starting position to encode the facility ie contents.
* \param end End of facility ie contents encoding data buffer.
* \param cc_record Call completion record to process event.
*
* \retval Start of the next ASN.1 component to encode on success.
* \retval NULL on error.
*/
static unsigned char *enc_qsig_cc_request(struct pri *ctrl,
unsigned char *pos, unsigned char *end, struct pri_cc_record *cc_record)
{
struct fac_extension_header header;
struct rose_msg_invoke msg;
memset(&header, 0, sizeof(header));
header.nfe_present = 1;
header.nfe.source_entity = 0; /* endPINX */
header.nfe.destination_entity = 0; /* endPINX */
header.interpretation_present = 1;
header.interpretation = 1; /* clearCallIfAnyInvokePduNotRecognised */
pos = facility_encode_header(ctrl, pos, end, &header);
if (!pos) {
return NULL;
}
memset(&msg, 0, sizeof(msg));
msg.invoke_id = get_invokeid(ctrl);
msg.operation = cc_record->is_ccnr
? ROSE_QSIG_CcnrRequest : ROSE_QSIG_CcbsRequest;
/* Fill in Party B address. */
q931_copy_number_to_rose(ctrl, &msg.args.qsig.CcbsRequest.number_b,
&cc_record->party_b.number);
q931_copy_subaddress_to_rose(ctrl, &msg.args.qsig.CcbsRequest.subaddr_b,
&cc_record->party_b.subaddress);
/* Fill in Party A address. */
q931_copy_presented_number_unscreened_to_rose(ctrl,
&msg.args.qsig.CcbsRequest.number_a, &cc_record->party_a.number);
q931_copy_subaddress_to_rose(ctrl, &msg.args.qsig.CcbsRequest.subaddr_a,
&cc_record->party_a.subaddress);
/* Fill in service Q.931 ie information. */
if (cc_record->saved_ie_contents.length
<= sizeof(msg.args.qsig.CcbsRequest.q931ie_contents)) {
/* Saved BC, HLC, and LLC from initial SETUP */
msg.args.qsig.CcbsRequest.q931ie.length = cc_record->saved_ie_contents.length;
memcpy(msg.args.qsig.CcbsRequest.q931ie.contents,
cc_record->saved_ie_contents.data, cc_record->saved_ie_contents.length);
} else {
pri_error(ctrl, "CcbsRequest q931 ie contents did not fit.\n");
}
//msg.args.qsig.CcbsRequest.can_retain_service = 0;
switch (ctrl->cc.option.signaling_retention_req) {
case 0:/* Want release signaling link. */
cc_record->option.retain_signaling_link = 0;
msg.args.qsig.CcbsRequest.retain_sig_connection_present = 1;
msg.args.qsig.CcbsRequest.retain_sig_connection = 0;
break;
case 1:/* Demand retain signaling link. */
cc_record->option.retain_signaling_link = 1;
msg.args.qsig.CcbsRequest.retain_sig_connection_present = 1;
msg.args.qsig.CcbsRequest.retain_sig_connection = 1;
break;
case 2:/* Don't care about signaling link retention. */
default:
cc_record->option.retain_signaling_link = 0;
break;
}
if (!cc_record->party_a.number.valid || cc_record->party_a.number.str[0] == '\0') {
/*
* Party A number is not available for the other end to initiate
* a signaling link to us. We must require that the signaling link
* be retained.
*/
cc_record->option.retain_signaling_link = 1;
msg.args.qsig.CcbsRequest.retain_sig_connection_present = 1;
msg.args.qsig.CcbsRequest.retain_sig_connection = 1;
}
pos = rose_encode_invoke(ctrl, pos, end, &msg);