-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpri_aoc.c
1764 lines (1595 loc) · 53.8 KB
/
pri_aoc.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) 2010 Digium, Inc.
*
* Richard Mudgett <[email protected]>
* David Vossel <[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 Advice Of Charge (AOC) facility support.
*
* \author Richard Mudgett <[email protected]>
*/
#include "compat.h"
#include "libpri.h"
#include "pri_internal.h"
#include "pri_facility.h"
/* ------------------------------------------------------------------- */
/*!
* \internal
* \brief Fill in the AOC subcmd amount from the ETSI amount.
*
* \param subcmd_amount AOC subcmd amount.
* \param etsi_amount AOC ETSI amount.
*
* \return Nothing
*/
static void aoc_etsi_subcmd_amount(struct pri_aoc_amount *subcmd_amount, const struct roseEtsiAOCAmount *etsi_amount)
{
subcmd_amount->cost = etsi_amount->currency;
subcmd_amount->multiplier = etsi_amount->multiplier;
}
/*!
* \internal
* \brief Fill in the ETSI amount from the AOC subcmd amount.
*
* \param subcmd_amount AOC subcmd amount.
* \param etsi_amount AOC ETSI amount.
*
* \return Nothing
*/
static void aoc_enc_etsi_subcmd_amount(const struct pri_aoc_amount *subcmd_amount, struct roseEtsiAOCAmount *etsi_amount)
{
etsi_amount->currency = subcmd_amount->cost;
etsi_amount->multiplier = subcmd_amount->multiplier;
}
/*!
* \internal
* \brief Fill in the AOC subcmd time from the ETSI time.
*
* \param subcmd_time AOC subcmd time.
* \param etsi_time AOC ETSI time.
*
* \return Nothing
*/
static void aoc_etsi_subcmd_time(struct pri_aoc_time *subcmd_time, const struct roseEtsiAOCTime *etsi_time)
{
subcmd_time->length = etsi_time->length;
subcmd_time->scale = etsi_time->scale;
}
/*!
* \internal
* \brief Fill in the ETSI Time from the AOC subcmd time.
*
* \param subcmd_time AOC subcmd time.
* \param etsi_time AOC ETSI time.
*
* \return Nothing
*/
static void aoc_enc_etsi_subcmd_time(const struct pri_aoc_time *subcmd_time, struct roseEtsiAOCTime *etsi_time)
{
etsi_time->length = subcmd_time->length;
etsi_time->scale = subcmd_time->scale;
}
/*!
* \internal
* \brief Fill in the AOC subcmd recorded currency from the ETSI recorded currency.
*
* \param subcmd_recorded AOC subcmd recorded currency.
* \param etsi_recorded AOC ETSI recorded currency.
*
* \return Nothing
*/
static void aoc_etsi_subcmd_recorded_currency(struct pri_aoc_recorded_currency *subcmd_recorded, const struct roseEtsiAOCRecordedCurrency *etsi_recorded)
{
aoc_etsi_subcmd_amount(&subcmd_recorded->amount, &etsi_recorded->amount);
libpri_copy_string(subcmd_recorded->currency, (char *) etsi_recorded->currency,
sizeof(subcmd_recorded->currency));
}
/*!
* \internal
* \brief Fill in the the ETSI recorded currency from the subcmd currency info
*
* \param subcmd_recorded AOC subcmd recorded currency.
* \param etsi_recorded AOC ETSI recorded currency.
*
* \return Nothing
*/
static void aoc_enc_etsi_subcmd_recorded_currency(const struct pri_aoc_recorded_currency *subcmd_recorded, struct roseEtsiAOCRecordedCurrency *etsi_recorded)
{
aoc_enc_etsi_subcmd_amount(&subcmd_recorded->amount, &etsi_recorded->amount);
libpri_copy_string((char *) etsi_recorded->currency,
subcmd_recorded->currency,
sizeof(etsi_recorded->currency));
}
/*!
* \internal
* \brief Fill in the AOC subcmd recorded units from the ETSI recorded units.
*
* \param subcmd_recorded AOC subcmd recorded units list.
* \param etsi_recorded AOC ETSI recorded units list.
*
* \return Nothing
*/
static void aoc_etsi_subcmd_recorded_units(struct pri_aoc_recorded_units *subcmd_recorded, const struct roseEtsiAOCRecordedUnitsList *etsi_recorded)
{
int idx;
/* Fill in the itemized list of recorded units. */
for (idx = 0; idx < etsi_recorded->num_records
&& idx < ARRAY_LEN(subcmd_recorded->item); ++idx) {
if (etsi_recorded->list[idx].not_available) {
subcmd_recorded->item[idx].number = -1;
} else {
subcmd_recorded->item[idx].number = etsi_recorded->list[idx].number_of_units;
}
if (etsi_recorded->list[idx].type_of_unit_present) {
subcmd_recorded->item[idx].type = etsi_recorded->list[idx].type_of_unit;
} else {
subcmd_recorded->item[idx].type = -1;
}
}
subcmd_recorded->num_items = idx;
}
/*!
* \internal
* \brief Fill in the ETSI recorded units from the AOC subcmd recorded units.
*
* \param subcmd_recorded AOC subcmd recorded units list.
* \param etsi_recorded AOC ETSI recorded units list.
*
* \return Nothing
*/
static void aoc_enc_etsi_subcmd_recorded_units(const struct pri_aoc_recorded_units *subcmd_recorded, struct roseEtsiAOCRecordedUnitsList *etsi_recorded)
{
int i;
/* Fill in the itemized list of recorded units. */
for (i = 0; i < subcmd_recorded->num_items; i++) {
if (subcmd_recorded->item[i].number >= 0) {
etsi_recorded->list[i].number_of_units = subcmd_recorded->item[i].number;
} else {
etsi_recorded->list[i].not_available = 1;
}
if (subcmd_recorded->item[i].type > 0) {
etsi_recorded->list[i].type_of_unit = subcmd_recorded->item[i].type;
etsi_recorded->list[i].type_of_unit_present = 1;
}
}
etsi_recorded->num_records = i;
if (!etsi_recorded->num_records) {
etsi_recorded->list[0].not_available = 1;
etsi_recorded->list[0].type_of_unit_present = 0;
etsi_recorded->num_records = 1;
}
}
/*!
* \brief Handle the ETSI ChargingRequest.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param call Q.931 call leg.
* \param invoke Decoded ROSE invoke message contents.
*
* \return Nothing
*/
void aoc_etsi_aoc_request(struct pri *ctrl, q931_call *call, const struct rose_msg_invoke *invoke)
{
struct pri_subcommand *subcmd;
int request;
if (!ctrl->aoc_support) {
send_facility_error(ctrl, call, invoke->invoke_id, ROSE_ERROR_Gen_NotSubscribed);
return;
}
switch (invoke->args.etsi.ChargingRequest.charging_case) {
case 0:/* chargingInformationAtCallSetup */
request = PRI_AOC_REQUEST_S;
break;
case 1:/* chargingDuringACall */
request = PRI_AOC_REQUEST_D;
break;
case 2:/* chargingAtTheEndOfACall */
request = PRI_AOC_REQUEST_E;
break;
default:
send_facility_error(ctrl, call, invoke->invoke_id, ROSE_ERROR_Gen_NotImplemented);
return;
}
subcmd = q931_alloc_subcommand(ctrl);
if (!subcmd) {
send_facility_error(ctrl, call, invoke->invoke_id, ROSE_ERROR_Gen_NotAvailable);
return;
}
subcmd->cmd = PRI_SUBCMD_AOC_CHARGING_REQ;
subcmd->u.aoc_request.invoke_id = invoke->invoke_id;
subcmd->u.aoc_request.charging_request = request;
}
/*!
* \internal
* \brief Fill in the AOC-S subcmd currency info list of chargeable items.
*
* \param aoc_s AOC-S info list of chargeable items.
* \param info ETSI info list of chargeable items.
*
* \return Nothing
*/
static void aoc_etsi_subcmd_aoc_s_currency_info(struct pri_subcmd_aoc_s *aoc_s, const struct roseEtsiAOCSCurrencyInfoList *info)
{
int idx;
/* Fill in the itemized list of chargeable items. */
for (idx = 0; idx < info->num_records && idx < ARRAY_LEN(aoc_s->item); ++idx) {
/* What is being charged. */
switch (info->list[idx].charged_item) {
case 0:/* basicCommunication */
aoc_s->item[idx].chargeable = PRI_AOC_CHARGED_ITEM_BASIC_COMMUNICATION;
break;
case 1:/* callAttempt */
aoc_s->item[idx].chargeable = PRI_AOC_CHARGED_ITEM_CALL_ATTEMPT;
break;
case 2:/* callSetup */
aoc_s->item[idx].chargeable = PRI_AOC_CHARGED_ITEM_CALL_SETUP;
break;
case 3:/* userToUserInfo */
aoc_s->item[idx].chargeable = PRI_AOC_CHARGED_ITEM_USER_USER_INFO;
break;
case 4:/* operationOfSupplementaryServ */
aoc_s->item[idx].chargeable = PRI_AOC_CHARGED_ITEM_SUPPLEMENTARY_SERVICE;
break;
default:
aoc_s->item[idx].chargeable = PRI_AOC_CHARGED_ITEM_NOT_AVAILABLE;
break;
}
/* Rate method being used. */
switch (info->list[idx].currency_type) {
case 0:/* specialChargingCode */
aoc_s->item[idx].rate_type = PRI_AOC_RATE_TYPE_SPECIAL_CODE;
aoc_s->item[idx].rate.special = info->list[idx].u.special_charging_code;
break;
case 1:/* durationCurrency */
aoc_s->item[idx].rate_type = PRI_AOC_RATE_TYPE_DURATION;
aoc_etsi_subcmd_amount(&aoc_s->item[idx].rate.duration.amount,
&info->list[idx].u.duration.amount);
aoc_etsi_subcmd_time(&aoc_s->item[idx].rate.duration.time,
&info->list[idx].u.duration.time);
if (info->list[idx].u.duration.granularity_present) {
aoc_etsi_subcmd_time(&aoc_s->item[idx].rate.duration.granularity,
&info->list[idx].u.duration.granularity);
} else {
aoc_s->item[idx].rate.duration.granularity.length = 0;
aoc_s->item[idx].rate.duration.granularity.scale =
PRI_AOC_TIME_SCALE_HUNDREDTH_SECOND;
}
aoc_s->item[idx].rate.duration.charging_type =
info->list[idx].u.duration.charging_type;
libpri_copy_string(aoc_s->item[idx].rate.duration.currency,
(char *) info->list[idx].u.duration.currency,
sizeof(aoc_s->item[idx].rate.duration.currency));
break;
case 2:/* flatRateCurrency */
aoc_s->item[idx].rate_type = PRI_AOC_RATE_TYPE_FLAT;
aoc_etsi_subcmd_amount(&aoc_s->item[idx].rate.flat.amount,
&info->list[idx].u.flat_rate.amount);
libpri_copy_string(aoc_s->item[idx].rate.flat.currency,
(char *) info->list[idx].u.flat_rate.currency,
sizeof(aoc_s->item[idx].rate.flat.currency));
break;
case 3:/* volumeRateCurrency */
aoc_s->item[idx].rate_type = PRI_AOC_RATE_TYPE_VOLUME;
aoc_etsi_subcmd_amount(&aoc_s->item[idx].rate.volume.amount,
&info->list[idx].u.volume_rate.amount);
aoc_s->item[idx].rate.volume.unit = info->list[idx].u.volume_rate.unit;
libpri_copy_string(aoc_s->item[idx].rate.volume.currency,
(char *) info->list[idx].u.volume_rate.currency,
sizeof(aoc_s->item[idx].rate.volume.currency));
break;
case 4:/* freeOfCharge */
aoc_s->item[idx].rate_type = PRI_AOC_RATE_TYPE_FREE;
break;
default:
case 5:/* currencyInfoNotAvailable */
aoc_s->item[idx].rate_type = PRI_AOC_RATE_TYPE_NOT_AVAILABLE;
break;
}
}
aoc_s->num_items = idx;
}
/*!
* \internal
* \brief Fill in the currency info list of chargeable items from a aoc_s subcmd
*
* \param aoc_s AOC-S info list of chargeable items.
* \param info ETSI info list of chargeable items.
*
* \return Nothing
*/
static void enc_etsi_subcmd_aoc_s_currency_info(const struct pri_subcmd_aoc_s *aoc_s, struct roseEtsiAOCSCurrencyInfoList *info)
{
int idx;
for (idx = 0; idx < aoc_s->num_items && idx < ARRAY_LEN(info->list); ++idx) {
/* What is being charged. */
switch (aoc_s->item[idx].chargeable) {
default:
case PRI_AOC_CHARGED_ITEM_BASIC_COMMUNICATION:
info->list[idx].charged_item = 0;/* basicCommunication */
break;
case PRI_AOC_CHARGED_ITEM_CALL_ATTEMPT:
info->list[idx].charged_item = 1;/* callAttempt */
break;
case PRI_AOC_CHARGED_ITEM_CALL_SETUP:
info->list[idx].charged_item = 2;/* callSetup */
break;
case PRI_AOC_CHARGED_ITEM_USER_USER_INFO:
info->list[idx].charged_item = 3;/* userToUserInfo */
break;
case PRI_AOC_CHARGED_ITEM_SUPPLEMENTARY_SERVICE:
info->list[idx].charged_item = 4;/* operationOfSupplementaryServ */
break;
}
/* Rate method being used. */
switch (aoc_s->item[idx].rate_type) {
case PRI_AOC_RATE_TYPE_SPECIAL_CODE:
info->list[idx].currency_type = 0;/* specialChargingCode */
info->list[idx].u.special_charging_code = aoc_s->item[idx].rate.special;
break;
case PRI_AOC_RATE_TYPE_DURATION:
info->list[idx].currency_type = 1;/* durationCurrency */
aoc_enc_etsi_subcmd_amount(&aoc_s->item[idx].rate.duration.amount,
&info->list[idx].u.duration.amount);
aoc_enc_etsi_subcmd_time(&aoc_s->item[idx].rate.duration.time,
&info->list[idx].u.duration.time);
if (aoc_s->item[idx].rate.duration.granularity.length) {
info->list[idx].u.duration.granularity_present = 1;
aoc_enc_etsi_subcmd_time(&aoc_s->item[idx].rate.duration.granularity,
&info->list[idx].u.duration.granularity);
} else {
info->list[idx].u.duration.granularity_present = 0;
}
info->list[idx].u.duration.charging_type = aoc_s->item[idx].rate.duration.charging_type;
libpri_copy_string((char *) info->list[idx].u.duration.currency,
aoc_s->item[idx].rate.duration.currency,
sizeof((char *) info->list[idx].u.duration.currency));
break;
case PRI_AOC_RATE_TYPE_FLAT:
info->list[idx].currency_type = 2;/* flatRateCurrency */
aoc_enc_etsi_subcmd_amount(&aoc_s->item[idx].rate.flat.amount,
&info->list[idx].u.flat_rate.amount);
libpri_copy_string((char *) info->list[idx].u.flat_rate.currency,
aoc_s->item[idx].rate.flat.currency,
sizeof((char *) info->list[idx].u.flat_rate.currency));
break;
case PRI_AOC_RATE_TYPE_VOLUME:
info->list[idx].currency_type = 3;/* volumeRateCurrency */
aoc_enc_etsi_subcmd_amount(&aoc_s->item[idx].rate.volume.amount,
&info->list[idx].u.volume_rate.amount);
info->list[idx].u.volume_rate.unit = aoc_s->item[idx].rate.volume.unit;
libpri_copy_string((char *) info->list[idx].u.volume_rate.currency,
aoc_s->item[idx].rate.volume.currency,
sizeof((char *) info->list[idx].u.volume_rate.currency));
break;
case PRI_AOC_RATE_TYPE_FREE:
info->list[idx].currency_type = 4;/* freeOfCharge */
break;
default:
case PRI_AOC_RATE_TYPE_NOT_AVAILABLE:
info->list[idx].currency_type = 5;/* currencyInfoNotAvailable */
break;
}
}
if (!idx) {
/* We cannot send an empty list so create a dummy list element. */
info->list[idx].charged_item = 0;/* basicCommunication */
info->list[idx].currency_type = 5;/* currencyInfoNotAvailable */
++idx;
}
info->num_records = idx;
}
/*!
* \brief Handle the ETSI AOCSCurrency message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param invoke Decoded ROSE invoke message contents.
*
* \return Nothing
*/
void aoc_etsi_aoc_s_currency(struct pri *ctrl, const struct rose_msg_invoke *invoke)
{
struct pri_subcommand *subcmd;
if (!ctrl->aoc_support) {
return;
}
subcmd = q931_alloc_subcommand(ctrl);
if (!subcmd) {
return;
}
subcmd->cmd = PRI_SUBCMD_AOC_S;
if (!invoke->args.etsi.AOCSCurrency.type) {
subcmd->u.aoc_s.num_items = 0;
return;
}
/* Fill in the itemized list of chargeable items. */
aoc_etsi_subcmd_aoc_s_currency_info(&subcmd->u.aoc_s,
&invoke->args.etsi.AOCSCurrency.currency_info);
}
/*!
* \brief Handle the ETSI AOCSSpecialArr message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param invoke Decoded ROSE invoke message contents.
*
* \return Nothing
*/
void aoc_etsi_aoc_s_special_arrangement(struct pri *ctrl, const struct rose_msg_invoke *invoke)
{
struct pri_subcommand *subcmd;
if (!ctrl->aoc_support) {
return;
}
subcmd = q931_alloc_subcommand(ctrl);
if (!subcmd) {
return;
}
subcmd->cmd = PRI_SUBCMD_AOC_S;
if (!invoke->args.etsi.AOCSSpecialArr.type) {
subcmd->u.aoc_s.num_items = 0;
return;
}
subcmd->u.aoc_s.num_items = 1;
subcmd->u.aoc_s.item[0].chargeable = PRI_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT;
subcmd->u.aoc_s.item[0].rate_type = PRI_AOC_RATE_TYPE_SPECIAL_CODE;
subcmd->u.aoc_s.item[0].rate.special =
invoke->args.etsi.AOCSSpecialArr.special_arrangement;
}
/*!
* \internal
* \brief Determine the AOC-D subcmd billing_id value.
*
* \param billing_id_present TRUE if billing_id valid.
* \param billing_id ETSI billing id from ROSE.
*
* \return enum PRI_AOC_D_BILLING_ID value
*/
static enum PRI_AOC_D_BILLING_ID aoc_etsi_subcmd_aoc_d_billing_id(int billing_id_present, int billing_id)
{
enum PRI_AOC_D_BILLING_ID value;
if (billing_id_present) {
switch (billing_id) {
case 0:/* normalCharging */
value = PRI_AOC_D_BILLING_ID_NORMAL;
break;
case 1:/* reverseCharging */
value = PRI_AOC_D_BILLING_ID_REVERSE;
break;
case 2:/* creditCardCharging */
value = PRI_AOC_D_BILLING_ID_CREDIT_CARD;
break;
default:
value = PRI_AOC_D_BILLING_ID_NOT_AVAILABLE;
break;
}
} else {
value = PRI_AOC_D_BILLING_ID_NOT_AVAILABLE;
}
return value;
}
/*!
* \brief Handle the ETSI AOCDCurrency message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param invoke Decoded ROSE invoke message contents.
*
* \return Nothing
*/
void aoc_etsi_aoc_d_currency(struct pri *ctrl, const struct rose_msg_invoke *invoke)
{
struct pri_subcommand *subcmd;
if (!ctrl->aoc_support) {
return;
}
subcmd = q931_alloc_subcommand(ctrl);
if (!subcmd) {
return;
}
subcmd->cmd = PRI_SUBCMD_AOC_D;
switch (invoke->args.etsi.AOCDCurrency.type) {
default:
case 0:/* charge_not_available */
subcmd->u.aoc_d.charge = PRI_AOC_DE_CHARGE_NOT_AVAILABLE;
break;
case 1:/* free_of_charge */
subcmd->u.aoc_d.charge = PRI_AOC_DE_CHARGE_FREE;
break;
case 2:/* specific_currency */
subcmd->u.aoc_d.charge = PRI_AOC_DE_CHARGE_CURRENCY;
aoc_etsi_subcmd_recorded_currency(&subcmd->u.aoc_d.recorded.money,
&invoke->args.etsi.AOCDCurrency.specific.recorded);
subcmd->u.aoc_d.billing_accumulation =
invoke->args.etsi.AOCDCurrency.specific.type_of_charging_info;
subcmd->u.aoc_d.billing_id = aoc_etsi_subcmd_aoc_d_billing_id(
invoke->args.etsi.AOCDCurrency.specific.billing_id_present,
invoke->args.etsi.AOCDCurrency.specific.billing_id);
break;
}
}
/*!
* \brief Handle the ETSI AOCDChargingUnit message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param invoke Decoded ROSE invoke message contents.
*
* \return Nothing
*/
void aoc_etsi_aoc_d_charging_unit(struct pri *ctrl, const struct rose_msg_invoke *invoke)
{
struct pri_subcommand *subcmd;
if (!ctrl->aoc_support) {
return;
}
subcmd = q931_alloc_subcommand(ctrl);
if (!subcmd) {
return;
}
subcmd->cmd = PRI_SUBCMD_AOC_D;
switch (invoke->args.etsi.AOCDChargingUnit.type) {
default:
case 0:/* charge_not_available */
subcmd->u.aoc_d.charge = PRI_AOC_DE_CHARGE_NOT_AVAILABLE;
break;
case 1:/* free_of_charge */
subcmd->u.aoc_d.charge = PRI_AOC_DE_CHARGE_FREE;
break;
case 2:/* specific_charging_units */
subcmd->u.aoc_d.charge = PRI_AOC_DE_CHARGE_UNITS;
aoc_etsi_subcmd_recorded_units(&subcmd->u.aoc_d.recorded.unit,
&invoke->args.etsi.AOCDChargingUnit.specific.recorded);
subcmd->u.aoc_d.billing_accumulation =
invoke->args.etsi.AOCDChargingUnit.specific.type_of_charging_info;
subcmd->u.aoc_d.billing_id = aoc_etsi_subcmd_aoc_d_billing_id(
invoke->args.etsi.AOCDChargingUnit.specific.billing_id_present,
invoke->args.etsi.AOCDChargingUnit.specific.billing_id);
break;
}
}
/*!
* \internal
* \brief Fill in the AOC-E subcmd charging association from the ETSI charging association.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param subcmd_association AOC-E subcmd charging association.
* \param etsi_association AOC-E ETSI charging association.
*
* \return Nothing
*/
static void aoc_etsi_subcmd_aoc_e_charging_association(struct pri *ctrl, struct pri_aoc_e_charging_association *subcmd_association, const struct roseEtsiAOCChargingAssociation *etsi_association)
{
struct q931_party_number q931_number;
switch (etsi_association->type) {
case 0:/* charge_identifier */
subcmd_association->charging_type = PRI_AOC_E_CHARGING_ASSOCIATION_ID;
subcmd_association->charge.id = etsi_association->id;
break;
case 1:/* charged_number */
subcmd_association->charging_type = PRI_AOC_E_CHARGING_ASSOCIATION_NUMBER;
q931_party_number_init(&q931_number);
rose_copy_number_to_q931(ctrl, &q931_number, &etsi_association->number);
q931_party_number_copy_to_pri(&subcmd_association->charge.number, &q931_number);
break;
default:
subcmd_association->charging_type = PRI_AOC_E_CHARGING_ASSOCIATION_NOT_AVAILABLE;
break;
}
}
/*!
* \internal
* \brief Determine the AOC-E subcmd billing_id value.
*
* \param billing_id_present TRUE if billing_id valid.
* \param billing_id ETSI billing id from ROSE.
*
* \return enum PRI_AOC_E_BILLING_ID value
*/
static enum PRI_AOC_E_BILLING_ID aoc_etsi_subcmd_aoc_e_billing_id(int billing_id_present, int billing_id)
{
enum PRI_AOC_E_BILLING_ID value;
if (billing_id_present) {
switch (billing_id) {
case 0:/* normalCharging */
value = PRI_AOC_E_BILLING_ID_NORMAL;
break;
case 1:/* reverseCharging */
value = PRI_AOC_E_BILLING_ID_REVERSE;
break;
case 2:/* creditCardCharging */
value = PRI_AOC_E_BILLING_ID_CREDIT_CARD;
break;
case 3:/* callForwardingUnconditional */
value = PRI_AOC_E_BILLING_ID_CALL_FORWARDING_UNCONDITIONAL;
break;
case 4:/* callForwardingBusy */
value = PRI_AOC_E_BILLING_ID_CALL_FORWARDING_BUSY;
break;
case 5:/* callForwardingNoReply */
value = PRI_AOC_E_BILLING_ID_CALL_FORWARDING_NO_REPLY;
break;
case 6:/* callDeflection */
value = PRI_AOC_E_BILLING_ID_CALL_DEFLECTION;
break;
case 7:/* callTransfer */
value = PRI_AOC_E_BILLING_ID_CALL_TRANSFER;
break;
default:
value = PRI_AOC_E_BILLING_ID_NOT_AVAILABLE;
break;
}
} else {
value = PRI_AOC_E_BILLING_ID_NOT_AVAILABLE;
}
return value;
}
/*!
* \internal
* \brief Determine the ETSI AOC-E billing_id value from the subcmd.
*
* \param billing_id from upper layer.
*
* \retval -1 failure
* \retval etsi billing id
*/
static int aoc_subcmd_aoc_e_etsi_billing_id(enum PRI_AOC_E_BILLING_ID billing_id)
{
switch (billing_id) {
case PRI_AOC_E_BILLING_ID_NORMAL:
return 0;/* normalCharging */
case PRI_AOC_E_BILLING_ID_REVERSE:
return 1;/* reverseCharging */
case PRI_AOC_E_BILLING_ID_CREDIT_CARD:
return 2;/* creditCardCharging */
case PRI_AOC_E_BILLING_ID_CALL_FORWARDING_UNCONDITIONAL:
return 3;/* callForwardingUnconditional */
case PRI_AOC_E_BILLING_ID_CALL_FORWARDING_BUSY:
return 4;/* callForwardingBusy */
case PRI_AOC_E_BILLING_ID_CALL_FORWARDING_NO_REPLY:
return 5;/* callForwardingNoReply */
case PRI_AOC_E_BILLING_ID_CALL_DEFLECTION:
return 6;/* callDeflection */
case PRI_AOC_E_BILLING_ID_CALL_TRANSFER:
return 7;/* callTransfer */
case PRI_AOC_E_BILLING_ID_NOT_AVAILABLE:
break;
}
return -1;
}
/*!
* \internal
* \brief Determine the ETSI AOC-D billing_id value from the subcmd.
*
* \param billing_id from upper layer.
*
* \retval -1 failure
* \retval etsi billing id
*/
static int aoc_subcmd_aoc_d_etsi_billing_id(enum PRI_AOC_D_BILLING_ID billing_id)
{
switch (billing_id) {
case PRI_AOC_D_BILLING_ID_NORMAL:
return 0;/* normalCharging */
case PRI_AOC_D_BILLING_ID_REVERSE:
return 1;/* reverseCharging */
case PRI_AOC_D_BILLING_ID_CREDIT_CARD:
return 2;/* creditCardCharging */
case PRI_AOC_D_BILLING_ID_NOT_AVAILABLE:
break;
}
return -1;
}
/*!
* \brief Handle the ETSI AOCECurrency message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param call Q.931 call leg.
* \param invoke Decoded ROSE invoke message contents.
*
* \return Nothing
*/
void aoc_etsi_aoc_e_currency(struct pri *ctrl, q931_call *call, const struct rose_msg_invoke *invoke)
{
struct pri_subcommand *subcmd;
if (!ctrl->aoc_support) {
return;
}
subcmd = q931_alloc_subcommand(ctrl);
if (!subcmd) {
return;
}
subcmd->cmd = PRI_SUBCMD_AOC_E;
subcmd->u.aoc_e.associated.charging_type =
PRI_AOC_E_CHARGING_ASSOCIATION_NOT_AVAILABLE;
if (!invoke->args.etsi.AOCECurrency.type) {
subcmd->u.aoc_e.charge = PRI_AOC_DE_CHARGE_NOT_AVAILABLE;
return;
}
/* Fill in charging association if present. */
if (invoke->args.etsi.AOCECurrency.currency_info.charging_association_present) {
aoc_etsi_subcmd_aoc_e_charging_association(ctrl, &subcmd->u.aoc_e.associated,
&invoke->args.etsi.AOCECurrency.currency_info.charging_association);
}
/* Call was free of charge. */
if (invoke->args.etsi.AOCECurrency.currency_info.free_of_charge) {
subcmd->u.aoc_e.charge = PRI_AOC_DE_CHARGE_FREE;
return;
}
/* Fill in currency cost of call. */
subcmd->u.aoc_e.charge = PRI_AOC_DE_CHARGE_CURRENCY;
aoc_etsi_subcmd_recorded_currency(&subcmd->u.aoc_e.recorded.money,
&invoke->args.etsi.AOCECurrency.currency_info.specific.recorded);
subcmd->u.aoc_e.billing_id = aoc_etsi_subcmd_aoc_e_billing_id(
invoke->args.etsi.AOCECurrency.currency_info.specific.billing_id_present,
invoke->args.etsi.AOCECurrency.currency_info.specific.billing_id);
}
/*!
* \brief Handle the ETSI AOCEChargingUnit message.
*
* \param ctrl D channel controller for diagnostic messages or global options.
* \param call Q.931 call leg.
* \param invoke Decoded ROSE invoke message contents.
*
* \return Nothing
*/
void aoc_etsi_aoc_e_charging_unit(struct pri *ctrl, q931_call *call, const struct rose_msg_invoke *invoke)
{
struct pri_subcommand *subcmd;
unsigned idx;
/* Fill in legacy stuff. */
call->aoc_units = 0;
if (invoke->args.etsi.AOCEChargingUnit.type == 1
&& !invoke->args.etsi.AOCEChargingUnit.charging_unit.free_of_charge) {
for (idx =
invoke->args.etsi.AOCEChargingUnit.charging_unit.specific.recorded.num_records;
idx--;) {
if (!invoke->args.etsi.AOCEChargingUnit.charging_unit.specific.recorded.
list[idx].not_available) {
call->aoc_units +=
invoke->args.etsi.AOCEChargingUnit.charging_unit.specific.
recorded.list[idx].number_of_units;
}
}
}
if (!ctrl->aoc_support) {
return;
}
subcmd = q931_alloc_subcommand(ctrl);
if (!subcmd) {
return;
}
subcmd->cmd = PRI_SUBCMD_AOC_E;
subcmd->u.aoc_e.associated.charging_type =
PRI_AOC_E_CHARGING_ASSOCIATION_NOT_AVAILABLE;
if (!invoke->args.etsi.AOCEChargingUnit.type) {
subcmd->u.aoc_e.charge = PRI_AOC_DE_CHARGE_NOT_AVAILABLE;
return;
}
/* Fill in charging association if present. */
if (invoke->args.etsi.AOCEChargingUnit.charging_unit.charging_association_present) {
aoc_etsi_subcmd_aoc_e_charging_association(ctrl, &subcmd->u.aoc_e.associated,
&invoke->args.etsi.AOCEChargingUnit.charging_unit.charging_association);
}
/* Call was free of charge. */
if (invoke->args.etsi.AOCEChargingUnit.charging_unit.free_of_charge) {
subcmd->u.aoc_e.charge = PRI_AOC_DE_CHARGE_FREE;
return;
}
/* Fill in unit cost of call. */
subcmd->u.aoc_e.charge = PRI_AOC_DE_CHARGE_UNITS;
aoc_etsi_subcmd_recorded_units(&subcmd->u.aoc_e.recorded.unit,
&invoke->args.etsi.AOCEChargingUnit.charging_unit.specific.recorded);
subcmd->u.aoc_e.billing_id = aoc_etsi_subcmd_aoc_e_billing_id(
invoke->args.etsi.AOCEChargingUnit.charging_unit.specific.billing_id_present,
invoke->args.etsi.AOCEChargingUnit.charging_unit.specific.billing_id);
}
void pri_aoc_events_enable(struct pri *ctrl, int enable)
{
if (ctrl) {
ctrl->aoc_support = enable ? 1 : 0;
}
}
/*!
* \internal
* \brief Encode the ETSI AOCECurrency invoke 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 aoc_e the AOC-E data to encode.
*
* \retval Start of the next ASN.1 component to encode on success.
* \retval NULL on error.
*/
static unsigned char *enc_etsi_aoce_currency(struct pri *ctrl, unsigned char *pos,
unsigned char *end, const struct pri_subcmd_aoc_e *aoc_e)
{
struct rose_msg_invoke msg;
struct q931_party_number q931_number;
pos = facility_encode_header(ctrl, pos, end, NULL);
if (!pos) {
return NULL;
}
memset(&msg, 0, sizeof(msg));
msg.operation = ROSE_ETSI_AOCECurrency;
msg.invoke_id = get_invokeid(ctrl);
if (aoc_e->charge == PRI_AOC_DE_CHARGE_FREE) {
msg.args.etsi.AOCECurrency.type = 1; /* currency_info */
msg.args.etsi.AOCECurrency.currency_info.free_of_charge = 1;
} else if ((aoc_e->charge == PRI_AOC_DE_CHARGE_CURRENCY) && (aoc_e->recorded.money.amount.cost >= 0)) {
msg.args.etsi.AOCECurrency.type = 1; /* currency_info */
aoc_enc_etsi_subcmd_recorded_currency(&aoc_e->recorded.money,
&msg.args.etsi.AOCECurrency.currency_info.specific.recorded);
} else {
msg.args.etsi.AOCECurrency.type = 0; /* charge_not_available */
}
if (aoc_subcmd_aoc_e_etsi_billing_id(aoc_e->billing_id) != -1) {
msg.args.etsi.AOCECurrency.currency_info.specific.billing_id_present = 1;
msg.args.etsi.AOCECurrency.currency_info.specific.billing_id =
aoc_subcmd_aoc_e_etsi_billing_id(aoc_e->billing_id);
}
switch (aoc_e->associated.charging_type) {
case PRI_AOC_E_CHARGING_ASSOCIATION_NUMBER:
msg.args.etsi.AOCECurrency.currency_info.charging_association_present = 1;
msg.args.etsi.AOCECurrency.currency_info.charging_association.type = 1; /* charged_number */
pri_copy_party_number_to_q931(&q931_number, &aoc_e->associated.charge.number);
q931_copy_number_to_rose(ctrl,
&msg.args.etsi.AOCECurrency.currency_info.charging_association.number,
&q931_number);
break;
case PRI_AOC_E_CHARGING_ASSOCIATION_ID:
msg.args.etsi.AOCECurrency.currency_info.charging_association_present = 1;
msg.args.etsi.AOCECurrency.currency_info.charging_association.type = 0; /* charge_identifier */
msg.args.etsi.AOCECurrency.currency_info.charging_association.id =
aoc_e->associated.charge.id;
break;
default:
/* do nothing */
break;
}
pos = rose_encode_invoke(ctrl, pos, end, &msg);
return pos;
}
/*!
* \internal
* \brief Encode the ETSI AOCEChargingUnit invoke 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 aoc_e the AOC-E data to encode.
*
* \retval Start of the next ASN.1 component to encode on success.
* \retval NULL on error.
*/
static unsigned char *enc_etsi_aoce_charging_unit(struct pri *ctrl, unsigned char *pos,
unsigned char *end, const struct pri_subcmd_aoc_e *aoc_e)
{
struct rose_msg_invoke msg;
struct q931_party_number q931_number;
pos = facility_encode_header(ctrl, pos, end, NULL);
if (!pos) {
return NULL;
}
memset(&msg, 0, sizeof(msg));
msg.operation = ROSE_ETSI_AOCEChargingUnit;
msg.invoke_id = get_invokeid(ctrl);
if (aoc_e->charge == PRI_AOC_DE_CHARGE_FREE) {
msg.args.etsi.AOCEChargingUnit.type = 1; /* charging_unit */
msg.args.etsi.AOCEChargingUnit.charging_unit.free_of_charge = 1;
} else if ((aoc_e->charge == PRI_AOC_DE_CHARGE_UNITS) && (aoc_e->recorded.unit.num_items > 0)) {
msg.args.etsi.AOCEChargingUnit.type = 1; /* charging_unit */
aoc_enc_etsi_subcmd_recorded_units(&aoc_e->recorded.unit,
&msg.args.etsi.AOCEChargingUnit.charging_unit.specific.recorded);
} else {
msg.args.etsi.AOCEChargingUnit.type = 0; /* charge_not_available */
}
if (aoc_subcmd_aoc_e_etsi_billing_id(aoc_e->billing_id) != -1) {
msg.args.etsi.AOCEChargingUnit.charging_unit.specific.billing_id_present = 1;
msg.args.etsi.AOCEChargingUnit.charging_unit.specific.billing_id =
aoc_subcmd_aoc_e_etsi_billing_id(aoc_e->billing_id);
}
switch (aoc_e->associated.charging_type) {
case PRI_AOC_E_CHARGING_ASSOCIATION_NUMBER:
msg.args.etsi.AOCEChargingUnit.charging_unit.charging_association_present = 1;
msg.args.etsi.AOCEChargingUnit.charging_unit.charging_association.type = 1; /* charged_number */
pri_copy_party_number_to_q931(&q931_number, &aoc_e->associated.charge.number);
q931_copy_number_to_rose(ctrl,
&msg.args.etsi.AOCEChargingUnit.charging_unit.charging_association.number,
&q931_number);
break;
case PRI_AOC_E_CHARGING_ASSOCIATION_ID:
msg.args.etsi.AOCEChargingUnit.charging_unit.charging_association_present = 1;