2
* libpri: An implementation of Primary Rate ISDN
4
* Written by Matthew Fredrickson <creslin@digium.com>
6
* Copyright (C) 2004-2005, Digium
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.
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.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
#include "pri_internal.h"
30
#include "pri_facility.h"
36
static unsigned char get_invokeid(struct pri *pri)
38
return ++pri->last_invoke;
41
struct addressingdataelements_presentednumberunscreened {
42
char partyaddress[21];
43
char partysubaddress[21];
49
static void dump_apdu(struct pri *pri, unsigned char *c, int len)
51
#define MAX_APDU_LENGTH 255
53
char message[(2 + MAX_APDU_LENGTH * 3 + 6 + MAX_APDU_LENGTH + 3)] = ""; /* please adjust here, if you make changes below! */
55
if (len > MAX_APDU_LENGTH)
58
snprintf(message, sizeof(message)-1, " [");
60
snprintf((char *)(message+strlen(message)), sizeof(message)-strlen(message)-1, " %02x", c[i]);
61
snprintf((char *)(message+strlen(message)), sizeof(message)-strlen(message)-1, " ] - [");
62
for (i=0; i<len; i++) {
63
if (c[i] < 20 || c[i] >= 128)
64
snprintf((char *)(message+strlen(message)), sizeof(message)-strlen(message)-1, "�");
66
snprintf((char *)(message+strlen(message)), sizeof(message)-strlen(message)-1, "%c", c[i]);
68
snprintf((char *)(message+strlen(message)), sizeof(message)-strlen(message)-1, "]\n");
69
pri_message(pri, message);
72
int redirectingreason_from_q931(struct pri *pri, int redirectingreason)
74
switch(pri->switchtype) {
76
switch(redirectingreason) {
77
case PRI_REDIR_UNKNOWN:
78
return QSIG_DIVERT_REASON_UNKNOWN;
79
case PRI_REDIR_FORWARD_ON_BUSY:
80
return QSIG_DIVERT_REASON_CFB;
81
case PRI_REDIR_FORWARD_ON_NO_REPLY:
82
return QSIG_DIVERT_REASON_CFNR;
83
case PRI_REDIR_UNCONDITIONAL:
84
return QSIG_DIVERT_REASON_CFU;
85
case PRI_REDIR_DEFLECTION:
86
case PRI_REDIR_DTE_OUT_OF_ORDER:
87
case PRI_REDIR_FORWARDED_BY_DTE:
88
pri_message(pri, "!! Don't know how to convert Q.931 redirection reason %d to Q.SIG\n", redirectingreason);
91
return QSIG_DIVERT_REASON_UNKNOWN;
94
switch(redirectingreason) {
95
case PRI_REDIR_UNKNOWN:
96
return Q952_DIVERT_REASON_UNKNOWN;
97
case PRI_REDIR_FORWARD_ON_BUSY:
98
return Q952_DIVERT_REASON_CFB;
99
case PRI_REDIR_FORWARD_ON_NO_REPLY:
100
return Q952_DIVERT_REASON_CFNR;
101
case PRI_REDIR_DEFLECTION:
102
return Q952_DIVERT_REASON_CD;
103
case PRI_REDIR_UNCONDITIONAL:
104
return Q952_DIVERT_REASON_CFU;
105
case PRI_REDIR_DTE_OUT_OF_ORDER:
106
case PRI_REDIR_FORWARDED_BY_DTE:
107
pri_message(pri, "!! Don't know how to convert Q.931 redirection reason %d to Q.952\n", redirectingreason);
110
return Q952_DIVERT_REASON_UNKNOWN;
115
static int redirectingreason_for_q931(struct pri *pri, int redirectingreason)
117
switch(pri->switchtype) {
118
case PRI_SWITCH_QSIG:
119
switch(redirectingreason) {
120
case QSIG_DIVERT_REASON_UNKNOWN:
121
return PRI_REDIR_UNKNOWN;
122
case QSIG_DIVERT_REASON_CFU:
123
return PRI_REDIR_UNCONDITIONAL;
124
case QSIG_DIVERT_REASON_CFB:
125
return PRI_REDIR_FORWARD_ON_BUSY;
126
case QSIG_DIVERT_REASON_CFNR:
127
return PRI_REDIR_FORWARD_ON_NO_REPLY;
129
pri_message(pri, "!! Unknown Q.SIG diversion reason %d\n", redirectingreason);
130
return PRI_REDIR_UNKNOWN;
133
switch(redirectingreason) {
134
case Q952_DIVERT_REASON_UNKNOWN:
135
return PRI_REDIR_UNKNOWN;
136
case Q952_DIVERT_REASON_CFU:
137
return PRI_REDIR_UNCONDITIONAL;
138
case Q952_DIVERT_REASON_CFB:
139
return PRI_REDIR_FORWARD_ON_BUSY;
140
case Q952_DIVERT_REASON_CFNR:
141
return PRI_REDIR_FORWARD_ON_NO_REPLY;
142
case Q952_DIVERT_REASON_CD:
143
return PRI_REDIR_DEFLECTION;
144
case Q952_DIVERT_REASON_IMMEDIATE:
145
pri_message(pri, "!! Dont' know how to convert Q.952 diversion reason IMMEDIATE to PRI analog\n");
146
return PRI_REDIR_UNKNOWN; /* ??? */
148
pri_message(pri, "!! Unknown Q.952 diversion reason %d\n", redirectingreason);
149
return PRI_REDIR_UNKNOWN;
154
int typeofnumber_from_q931(struct pri *pri, int ton)
157
case PRI_TON_INTERNATIONAL:
158
return Q932_TON_INTERNATIONAL;
159
case PRI_TON_NATIONAL:
160
return Q932_TON_NATIONAL;
161
case PRI_TON_NET_SPECIFIC:
162
return Q932_TON_NET_SPECIFIC;
163
case PRI_TON_SUBSCRIBER:
164
return Q932_TON_SUBSCRIBER;
165
case PRI_TON_ABBREVIATED:
166
return Q932_TON_ABBREVIATED;
167
case PRI_TON_RESERVED:
169
pri_message(pri, "!! Unsupported Q.931 TypeOfNumber value (%d)\n", ton);
171
case PRI_TON_UNKNOWN:
172
return Q932_TON_UNKNOWN;
176
static int typeofnumber_for_q931(struct pri *pri, int ton)
179
case Q932_TON_UNKNOWN:
180
return PRI_TON_UNKNOWN;
181
case Q932_TON_INTERNATIONAL:
182
return PRI_TON_INTERNATIONAL;
183
case Q932_TON_NATIONAL:
184
return PRI_TON_NATIONAL;
185
case Q932_TON_NET_SPECIFIC:
186
return PRI_TON_NET_SPECIFIC;
187
case Q932_TON_SUBSCRIBER:
188
return PRI_TON_SUBSCRIBER;
189
case Q932_TON_ABBREVIATED:
190
return PRI_TON_ABBREVIATED;
192
pri_message(pri, "!! Invalid Q.932 TypeOfNumber %d\n", ton);
193
return PRI_TON_UNKNOWN;
197
int asn1_name_decode(void * data, int len, char *namebuf, int buflen)
199
struct rose_component *comp = (struct rose_component*)data;
200
int datalen = 0, res = 0;
202
if (comp->len == ASN1_LEN_INDEF) {
203
datalen = strlen((char *)comp->data);
206
datalen = res = comp->len;
208
if (datalen > buflen) {
212
memcpy(namebuf, comp->data, datalen);
216
int asn1_string_encode(unsigned char asn1_type, void *data, int len, int max_len, void *src, int src_len)
218
struct rose_component *comp = NULL;
220
if (len < 2 + src_len)
223
if (max_len && (src_len > max_len))
226
comp = (struct rose_component *)data;
227
comp->type = asn1_type;
229
memcpy(comp->data, src, src_len);
234
int asn1_copy_string(char * buf, int buflen, struct rose_component *comp)
239
if ((comp->len > buflen) && (comp->len != ASN1_LEN_INDEF))
242
if (comp->len == ASN1_LEN_INDEF) {
243
datalen = strlen((char*)comp->data);
246
res = datalen = comp->len;
248
memcpy(buf, comp->data, datalen);
254
static int rose_number_digits_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
257
struct rose_component *comp = NULL;
258
unsigned char *vdata = data;
263
GET_COMPONENT(comp, i, vdata, len);
264
CHECK_COMPONENT(comp, ASN1_NUMERICSTRING, "Don't know what to do with PublicPartyNumber ROSE component type 0x%x\n");
265
if(comp->len > 20 && comp->len != ASN1_LEN_INDEF) {
266
pri_message(pri, "!! Oversized NumberDigits component (%d)\n", comp->len);
269
if (comp->len == ASN1_LEN_INDEF) {
270
datalen = strlen((char *)comp->data);
273
res = datalen = comp->len;
275
memcpy(value->partyaddress, comp->data, datalen);
276
value->partyaddress[datalen] = '\0';
285
static int rose_public_party_number_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
288
struct rose_component *comp = NULL;
289
unsigned char *vdata = data;
297
GET_COMPONENT(comp, i, vdata, len);
298
CHECK_COMPONENT(comp, ASN1_ENUMERATED, "Don't know what to do with PublicPartyNumber ROSE component type 0x%x\n");
299
ASN1_GET_INTEGER(comp, ton);
300
NEXT_COMPONENT(comp, i);
301
ton = typeofnumber_for_q931(pri, ton);
303
res = rose_number_digits_decode(pri, call, &vdata[i], len-i, value);
314
static int rose_address_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
317
struct rose_component *comp = NULL;
318
unsigned char *vdata = data;
322
GET_COMPONENT(comp, i, vdata, len);
325
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0): /* [0] unknownPartyNumber */
326
res = rose_number_digits_decode(pri, call, comp->data, comp->len, value);
329
value->npi = PRI_NPI_UNKNOWN;
330
value->ton = PRI_TON_UNKNOWN;
332
case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0): /* [0] unknownPartyNumber */
333
res = asn1_copy_string(value->partyaddress, sizeof(value->partyaddress), comp);
336
value->npi = PRI_NPI_UNKNOWN;
337
value->ton = PRI_TON_UNKNOWN;
339
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1): /* [1] publicPartyNumber */
340
res = rose_public_party_number_decode(pri, call, comp->data, comp->len, value);
343
value->npi = PRI_NPI_E163_E164;
345
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_2): /* [2] nsapEncodedNumber */
346
pri_message(pri, "!! NsapEncodedNumber isn't handled\n");
348
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_3): /* [3] dataPartyNumber */
349
if(rose_number_digits_decode(pri, call, comp->data, comp->len, value))
351
value->npi = PRI_NPI_X121 /* ??? */;
352
value->ton = PRI_TON_UNKNOWN /* ??? */;
353
pri_message(pri, "!! dataPartyNumber isn't handled\n");
355
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_4): /* [4] telexPartyNumber */
356
res = rose_number_digits_decode(pri, call, comp->data, comp->len, value);
359
value->npi = PRI_NPI_F69 /* ??? */;
360
value->ton = PRI_TON_UNKNOWN /* ??? */;
361
pri_message(pri, "!! telexPartyNumber isn't handled\n");
363
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_5): /* [5] priavePartyNumber */
364
pri_message(pri, "!! privatePartyNumber isn't handled\n");
365
value->npi = PRI_NPI_PRIVATE;
367
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_8): /* [8] nationalStandardPartyNumber */
368
res = rose_number_digits_decode(pri, call, comp->data, comp->len, value);
371
value->npi = PRI_NPI_NATIONAL;
372
value->ton = PRI_TON_NATIONAL;
375
pri_message(pri, "!! Unknown Party number component received 0x%X\n", comp->type);
378
ASN1_FIXUP_LEN(comp, res);
379
NEXT_COMPONENT(comp, i);
381
pri_message(pri, "!! not all information is handled from Address component\n");
389
static int rose_presented_number_unscreened_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
393
struct rose_component *comp = NULL;
394
unsigned char *vdata = data;
396
/* Fill in default values */
397
value->ton = PRI_TON_UNKNOWN;
398
value->npi = PRI_NPI_E163_E164;
399
value->pres = -1; /* Data is not available */
402
GET_COMPONENT(comp, i, vdata, len);
405
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0): /* [0] presentationAllowedNumber */
406
value->pres = PRES_ALLOWED_USER_NUMBER_NOT_SCREENED;
407
size = rose_address_decode(pri, call, comp->data, comp->len, value);
408
ASN1_FIXUP_LEN(comp, size);
410
case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1): /* [1] IMPLICIT presentationRestricted */
411
if (comp->len != 0) { /* must be NULL */
412
pri_error(pri, "!! Invalid PresentationRestricted component received (len != 0)\n");
415
value->pres = PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
417
case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2): /* [2] IMPLICIT numberNotAvailableDueToInterworking */
418
if (comp->len != 0) { /* must be NULL */
419
pri_error(pri, "!! Invalid NumberNotAvailableDueToInterworking component received (len != 0)\n");
422
value->pres = PRES_NUMBER_NOT_AVAILABLE;
424
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_3): /* [3] presentationRestrictedNumber */
425
value->pres = PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
426
size = rose_address_decode(pri, call, comp->data, comp->len, value) + 2;
427
ASN1_FIXUP_LEN(comp, size);
430
pri_message(pri, "Invalid PresentedNumberUnscreened component 0x%X\n", comp->type);
439
static int rose_diverting_leg_information2_decode(struct pri *pri, q931_call *call, struct rose_component *sequence, int len)
442
int diversion_counter;
443
int diversion_reason;
444
char origcalledname[50] = "", redirectingname[50] = "";
445
struct addressingdataelements_presentednumberunscreened divertingnr;
446
struct addressingdataelements_presentednumberunscreened originalcallednr;
447
struct rose_component *comp = NULL;
448
unsigned char *vdata = sequence->data;
452
if (sequence->type != (ASN1_CONSTRUCTOR | ASN1_SEQUENCE)) { /* Constructed Sequence */
453
pri_message(pri, "Invalid DivertingLegInformation2Type argument\n");
457
if (sequence->len == ASN1_LEN_INDEF) {
458
len -= 4; /* For the 2 extra characters at the end
459
* and two characters of header */
464
/* diversionCounter stuff */
465
GET_COMPONENT(comp, i, vdata, len);
466
CHECK_COMPONENT(comp, ASN1_INTEGER, "Don't know what to do it diversionCounter is of type 0x%x\n");
467
ASN1_GET_INTEGER(comp, diversion_counter);
468
NEXT_COMPONENT(comp, i);
470
/* diversionReason stuff */
471
GET_COMPONENT(comp, i, vdata, len);
472
CHECK_COMPONENT(comp, ASN1_ENUMERATED, "Invalid diversionReason type 0x%X of ROSE divertingLegInformation2 component received\n");
473
ASN1_GET_INTEGER(comp, diversion_reason);
474
NEXT_COMPONENT(comp, i);
476
diversion_reason = redirectingreason_for_q931(pri, diversion_reason);
478
if(pri->debug & PRI_DEBUG_APDU)
479
pri_message(pri, " Redirection reason: %d, total diversions: %d\n", diversion_reason, diversion_counter);
480
pri_message(NULL, "Length of message is %d\n", len);
482
for(; i < len; NEXT_COMPONENT(comp, i)) {
483
GET_COMPONENT(comp, i, vdata, len);
485
case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0):
486
call->origredirectingreason = redirectingreason_for_q931(pri, comp->data[0]);
487
if (pri->debug & PRI_DEBUG_APDU)
488
pri_message(pri, " Received reason for original redirection %d\n", call->origredirectingreason);
490
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1):
491
res = rose_presented_number_unscreened_decode(pri, call, comp->data, comp->len, &divertingnr);
492
/* TODO: Fix indefinite length form hacks */
493
ASN1_FIXUP_LEN(comp, res);
497
if (pri->debug & PRI_DEBUG_APDU) {
498
pri_message(pri, " Received divertingNr '%s'\n", divertingnr.partyaddress);
499
pri_message(pri, " ton = %d, pres = %d, npi = %d\n", divertingnr.ton, divertingnr.pres, divertingnr.npi);
502
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_2):
503
res = rose_presented_number_unscreened_decode(pri, call, comp->data, comp->len, &originalcallednr);
506
ASN1_FIXUP_LEN(comp, res);
508
if (pri->debug & PRI_DEBUG_APDU) {
509
pri_message(pri, " Received originalcallednr '%s'\n", originalcallednr.partyaddress);
510
pri_message(pri, " ton = %d, pres = %d, npi = %d\n", originalcallednr.ton, originalcallednr.pres, originalcallednr.npi);
513
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_3):
514
res = asn1_name_decode(comp->data, comp->len, redirectingname, sizeof(redirectingname));
517
ASN1_FIXUP_LEN(comp, res);
519
if (pri->debug & PRI_DEBUG_APDU)
520
pri_message(pri, " Received RedirectingName '%s'\n", redirectingname);
522
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_4):
523
res = asn1_name_decode(comp->data, comp->len, origcalledname, sizeof(origcalledname));
526
ASN1_FIXUP_LEN(comp, res);
528
if (pri->debug & PRI_DEBUG_APDU)
529
pri_message(pri, " Received Originally Called Name '%s'\n", origcalledname);
532
if (comp->type == 0 && comp->len == 0) {
533
break; /* Found termination characters */
535
pri_message(pri, "!! Invalid DivertingLegInformation2 component received 0x%X\n", comp->type);
540
if (divertingnr.pres >= 0) {
541
call->redirectingplan = divertingnr.npi;
542
call->redirectingpres = divertingnr.pres;
543
call->redirectingreason = diversion_reason;
544
libpri_copy_string(call->redirectingnum, divertingnr.partyaddress, sizeof(call->redirectingnum));
546
if (originalcallednr.pres >= 0) {
547
call->origcalledplan = originalcallednr.npi;
548
call->origcalledpres = originalcallednr.pres;
549
libpri_copy_string(call->origcallednum, originalcallednr.partyaddress, sizeof(call->origcallednum));
551
libpri_copy_string(call->redirectingname, redirectingname, sizeof(call->redirectingname));
552
libpri_copy_string(call->origcalledname, origcalledname, sizeof(call->origcalledname));
560
static int rose_diverting_leg_information2_encode(struct pri *pri, q931_call *call)
562
int i = 0, j, compsp = 0;
563
struct rose_component *comp, *compstk[10];
564
unsigned char buffer[256];
567
if (!strlen(call->callername)) {
571
buffer[i] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
573
/* Interpretation component */
574
ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 0x00 /* Discard unrecognized invokes */);
576
ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
578
ASN1_PUSH(compstk, compsp, comp);
579
/* Invoke component contents */
581
ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
584
/* ROSE operationId component */
585
ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, ROSE_DIVERTING_LEG_INFORMATION2);
587
/* ROSE ARGUMENT component */
588
ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE), buffer, i);
589
ASN1_PUSH(compstk, compsp, comp);
590
/* ROSE DivertingLegInformation2.diversionCounter component */
591
/* Always is 1 because other isn't available in the current design */
592
ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, 1);
594
/* ROSE DivertingLegInformation2.diversionReason component */
595
ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, redirectingreason_from_q931(pri, call->redirectingreason));
597
/* ROSE DivertingLegInformation2.divertingNr component */
598
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1), buffer, i);
600
ASN1_PUSH(compstk, compsp, comp);
601
/* Redirecting information always not screened */
603
switch(call->redirectingpres) {
604
case PRES_ALLOWED_USER_NUMBER_NOT_SCREENED:
605
case PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN:
606
if (call->redirectingnum && strlen(call->redirectingnum)) {
607
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0), buffer, i);
608
ASN1_PUSH(compstk, compsp, comp);
609
/* NPI of redirected number is not supported in the current design */
610
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1), buffer, i);
611
ASN1_PUSH(compstk, compsp, comp);
612
ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, typeofnumber_from_q931(pri, call->redirectingplan >> 4));
613
j = asn1_string_encode(ASN1_NUMERICSTRING, &buffer[i], len - i, 20, call->redirectingnum, strlen(call->redirectingnum));
618
ASN1_FIXUP(compstk, compsp, buffer, i);
619
ASN1_FIXUP(compstk, compsp, buffer, i);
623
case PRES_PROHIB_USER_NUMBER_PASSED_SCREEN:
624
case PRES_PROHIB_USER_NUMBER_NOT_SCREENED:
625
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1), buffer, i);
627
/* Don't know how to handle this */
628
case PRES_ALLOWED_NETWORK_NUMBER:
629
case PRES_PROHIB_NETWORK_NUMBER:
630
case PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN:
631
case PRES_PROHIB_USER_NUMBER_FAILED_SCREEN:
632
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1), buffer, i);
635
pri_message(pri, "!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres);
636
case PRES_NUMBER_NOT_AVAILABLE:
637
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i);
640
ASN1_FIXUP(compstk, compsp, buffer, i);
642
/* ROSE DivertingLegInformation2.originalCalledNr component */
643
/* This information isn't supported by current design - duplicate divertingNr */
644
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_2), buffer, i);
645
ASN1_PUSH(compstk, compsp, comp);
646
/* Redirecting information always not screened */
647
switch(call->redirectingpres) {
648
case PRES_ALLOWED_USER_NUMBER_NOT_SCREENED:
649
case PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN:
650
if (call->redirectingnum && strlen(call->redirectingnum)) {
651
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0), buffer, i);
652
ASN1_PUSH(compstk, compsp, comp);
653
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1), buffer, i);
654
ASN1_PUSH(compstk, compsp, comp);
655
ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, typeofnumber_from_q931(pri, call->redirectingplan >> 4));
657
j = asn1_string_encode(ASN1_NUMERICSTRING, &buffer[i], len - i, 20, call->redirectingnum, strlen(call->redirectingnum));
662
ASN1_FIXUP(compstk, compsp, buffer, i);
663
ASN1_FIXUP(compstk, compsp, buffer, i);
667
case PRES_PROHIB_USER_NUMBER_PASSED_SCREEN:
668
case PRES_PROHIB_USER_NUMBER_NOT_SCREENED:
669
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1), buffer, i);
671
/* Don't know how to handle this */
672
case PRES_ALLOWED_NETWORK_NUMBER:
673
case PRES_PROHIB_NETWORK_NUMBER:
674
case PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN:
675
case PRES_PROHIB_USER_NUMBER_FAILED_SCREEN:
676
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1), buffer, i);
679
pri_message(pri, "!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres);
680
case PRES_NUMBER_NOT_AVAILABLE:
681
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i);
684
ASN1_FIXUP(compstk, compsp, buffer, i);
686
/* Fix length of stacked components */
688
ASN1_FIXUP(compstk, compsp, buffer, i);
691
if (pri_call_apdu_queue(call, Q931_SETUP, buffer, i, NULL, NULL))
697
/* Sending callername information functions */
698
static int add_callername_facility_ies(struct pri *pri, q931_call *c, int cpe)
702
unsigned char buffer[256];
703
unsigned char namelen = 0;
704
struct rose_component *comp = NULL, *compstk[10];
707
static unsigned char op_tag[] = {
708
0x2a, /* informationFollowing 42 */
717
if (!strlen(c->callername)) {
721
buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
722
/* Interpretation component */
724
ASN1_ADD_SIMPLE(comp, COMP_TYPE_NFE, buffer, i);
725
ASN1_PUSH(compstk, compsp, comp);
726
ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0), buffer, i, 0);
727
ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i, 0);
728
ASN1_FIXUP(compstk, compsp, buffer, i);
730
ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 0);
732
ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
733
ASN1_PUSH(compstk, compsp, comp);
735
ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
738
res = asn1_string_encode(ASN1_OBJECTIDENTIFIER, &buffer[i], sizeof(buffer)-i, sizeof(op_tag), op_tag, sizeof(op_tag));
743
ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 0);
744
ASN1_FIXUP(compstk, compsp, buffer, i);
747
if (pri_call_apdu_queue(c, Q931_SETUP, buffer, i, NULL, NULL))
752
/* Now the ADPu that contains the information that needs sent.
753
* We can reuse the buffer since the queue function doesn't
757
namelen = strlen(c->callername);
759
namelen = 50; /* truncate the name */
762
buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
763
/* Interpretation component */
765
ASN1_ADD_SIMPLE(comp, COMP_TYPE_NFE, buffer, i);
766
ASN1_PUSH(compstk, compsp, comp);
767
ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0), buffer, i, 0);
768
ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i, 0);
769
ASN1_FIXUP(compstk, compsp, buffer, i);
771
ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 0);
773
ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
774
ASN1_PUSH(compstk, compsp, comp);
777
ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
779
/* Operation ID: Calling name */
780
ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, SS_CNID_CALLINGNAME);
782
res = asn1_string_encode((ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0), &buffer[i], sizeof(buffer)-i, 50, c->callername, namelen);
786
ASN1_FIXUP(compstk, compsp, buffer, i);
789
mymessage = Q931_SETUP;
791
mymessage = Q931_FACILITY;
793
if (pri_call_apdu_queue(c, mymessage, buffer, i, NULL, NULL))
800
/* MWI related encode and decode functions */
801
static void mwi_activate_encode_cb(void *data)
806
extern int mwi_message_send(struct pri* pri, q931_call *call, struct pri_sr *req, int activate)
809
unsigned char buffer[255] = "";
810
int destlen = strlen(req->called);
811
struct rose_component *comp = NULL, *compstk[10];
817
} else if (destlen > 20)
818
destlen = 20; /* Destination number cannot be greater then 20 digits */
820
buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
821
/* Interpretation component */
823
ASN1_ADD_SIMPLE(comp, COMP_TYPE_NFE, buffer, i);
824
ASN1_PUSH(compstk, compsp, comp);
825
ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0), buffer, i, 0);
826
ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i, 0);
827
ASN1_FIXUP(compstk, compsp, buffer, i);
829
ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 0);
831
ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
832
ASN1_PUSH(compstk, compsp, comp);
834
ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
836
ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, (activate) ? SS_MWI_ACTIVATE : SS_MWI_DEACTIVATE);
837
ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE), buffer, i);
838
ASN1_PUSH(compstk, compsp, comp);
840
res = asn1_string_encode((ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0), &buffer[i], sizeof(buffer)-i, destlen, req->called, destlen);
846
/* Enumeration: basicService */
847
ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 1 /* contents: Voice */);
848
ASN1_FIXUP(compstk, compsp, buffer, i);
849
ASN1_FIXUP(compstk, compsp, buffer, i);
851
return pri_call_apdu_queue(call, Q931_SETUP, buffer, i, mwi_activate_encode_cb, NULL);
856
extern int eect_initiate_transfer(struct pri *pri, q931_call *c1, q931_call *c2)
858
/* Did all the tests to see if we're on the same PRI and
859
* are on a compatible switchtype */
863
unsigned char buffer[255] = "";
864
unsigned short call_reference = c2->cr;
865
struct rose_component *comp = NULL, *compstk[10];
867
static unsigned char op_tag[] = {
877
buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
878
/* Interpretation component */
880
ASN1_ADD_SIMPLE(comp, COMP_TYPE_NFE, buffer, i);
881
ASN1_PUSH(compstk, compsp, comp);
882
ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0), buffer, i, 0);
883
ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i, 0);
884
ASN1_FIXUP(compstk, compsp, buffer, i);
886
ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 0);
888
ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
889
ASN1_PUSH(compstk, compsp, comp);
891
ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
893
res = asn1_string_encode(ASN1_OBJECTIDENTIFIER, &buffer[i], sizeof(buffer)-i, sizeof(op_tag), op_tag, sizeof(op_tag));
898
ASN1_ADD_SIMPLE(comp, (ASN1_SEQUENCE | ASN1_CONSTRUCTOR), buffer, i);
899
ASN1_PUSH(compstk, compsp, comp);
900
ASN1_ADD_WORDCOMP(comp, ASN1_INTEGER, buffer, i, call_reference);
901
ASN1_FIXUP(compstk, compsp, buffer, i);
902
ASN1_FIXUP(compstk, compsp, buffer, i);
904
res = pri_call_apdu_queue(c1, Q931_FACILITY, buffer, i, NULL, NULL);
906
pri_message(pri, "Could not queue ADPU in facility message\n");
910
/* Remember that if we queue a facility IE for a facility message we
911
* have to explicitly send the facility message ourselves */
913
res = q931_facility(c1->pri, c1);
915
pri_message(pri, "Could not schedule facility message for call %d\n", c1->cr);
924
static int aoc_aoce_charging_request_decode(struct pri *pri, q931_call *call, unsigned char *data, int len)
926
int chargingcase = -1;
927
unsigned char *vdata = data;
928
struct rose_component *comp = NULL;
931
if (pri->debug & PRI_DEBUG_AOC)
932
dump_apdu (pri, data, len);
935
GET_COMPONENT(comp, pos1, vdata, len);
936
CHECK_COMPONENT(comp, ASN1_ENUMERATED, "!! Invalid AOC Charging Request argument. Expected Enumerated (0x0A) but Received 0x%02X\n");
937
ASN1_GET_INTEGER(comp, chargingcase);
938
if (chargingcase >= 0 && chargingcase <= 2) {
939
if (pri->debug & PRI_DEBUG_APDU)
940
pri_message(pri, "Channel %d/%d, Call %d - received AOC charging request - charging case: %i\n",
941
call->ds1no, call->channelno, call->cr, chargingcase);
943
pri_message(pri, "!! unkown AOC ChargingCase: 0x%02X", chargingcase);
946
NEXT_COMPONENT(comp, pos1);
947
} while (pos1 < len);
949
pri_message(pri, "!! Only reached position %i in %i bytes long AOC-E structure:", pos1, len );
950
dump_apdu (pri, data, len);
951
return -1; /* Aborted before */
957
static int aoc_aoce_charging_unit_decode(struct pri *pri, q931_call *call, unsigned char *data, int len)
959
long chargingunits = 0, chargetype = -1, temp, chargeIdentifier = -1;
960
unsigned char *vdata = data;
961
struct rose_component *comp1 = NULL, *comp2 = NULL, *comp3 = NULL;
962
int pos1 = 0, pos2, pos3, sublen2, sublen3;
963
struct addressingdataelements_presentednumberunscreened chargednr;
965
if (pri->debug & PRI_DEBUG_AOC)
966
dump_apdu (pri, data, len);
969
GET_COMPONENT(comp1, pos1, vdata, len); /* AOCEChargingUnitInfo */
970
CHECK_COMPONENT(comp1, ASN1_SEQUENCE, "!! Invalid AOC-E Charging Unit argument. Expected Sequence (0x30) but Received 0x%02X\n");
971
SUB_COMPONENT(comp1, pos1);
972
GET_COMPONENT(comp1, pos1, vdata, len);
973
switch (comp1->type) {
974
case (ASN1_SEQUENCE | ASN1_CONSTRUCTOR): /* specificChargingUnits */
975
sublen2 = comp1->len;
978
SUB_COMPONENT(comp2, pos2);
980
GET_COMPONENT(comp2, pos2, vdata, len);
981
switch (comp2->type) {
982
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1): /* RecordedUnitsList (0xA1) */
983
SUB_COMPONENT(comp2, pos2);
984
GET_COMPONENT(comp2, pos2, vdata, len);
985
CHECK_COMPONENT(comp2, ASN1_SEQUENCE, "!! Invalid AOC-E Charging Unit argument. Expected Sequence (0x30) but received 0x02%X\n"); /* RecordedUnits */
986
sublen3 = pos2 + comp2->len;
989
SUB_COMPONENT(comp3, pos3);
991
GET_COMPONENT(comp3, pos3, vdata, len);
992
switch (comp3->type) {
993
case ASN1_INTEGER: /* numberOfUnits */
994
ASN1_GET_INTEGER(comp3, temp);
995
chargingunits += temp;
996
case ASN1_NULL: /* notAvailable */
999
pri_message(pri, "!! Don't know how to handle 0x%02X in AOC-E RecordedUnits\n", comp3->type);
1001
NEXT_COMPONENT(comp3, pos3);
1002
} while (pos3 < sublen3);
1003
if (pri->debug & PRI_DEBUG_AOC)
1004
pri_message(pri, "Channel %d/%d, Call %d - received AOC-E charging: %i unit%s\n",
1005
call->ds1no, call->channelno, call->cr, chargingunits, (chargingunits == 1) ? "" : "s");
1007
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_2): /* AOCEBillingID (0xA2) */
1008
SUB_COMPONENT(comp2, pos2);
1009
GET_COMPONENT(comp2, pos2, vdata, len);
1010
ASN1_GET_INTEGER(comp2, chargetype);
1011
pri_message(pri, "!! not handled: Channel %d/%d, Call %d - received AOC-E billing ID: %i\n",
1012
call->ds1no, call->channelno, call->cr, chargetype);
1015
pri_message(pri, "!! Don't know how to handle 0x%02X in AOC-E RecordedUnitsList\n", comp2->type);
1017
NEXT_COMPONENT(comp2, pos2);
1018
} while (pos2 < sublen2);
1020
case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1): /* freeOfCharge (0x81) */
1021
if (pri->debug & PRI_DEBUG_AOC)
1022
pri_message(pri, "Channel %d/%d, Call %d - received AOC-E free of charge\n", call->ds1no, call->channelno, call->cr);
1026
pri_message(pri, "!! Invalid AOC-E specificChargingUnits. Expected Sequence (0x30) or Object Identifier (0x81/0x01) but received 0x%02X\n", comp1->type);
1028
NEXT_COMPONENT(comp1, pos1);
1029
GET_COMPONENT(comp1, pos1, vdata, len); /* get optional chargingAssociation. will 'break' when reached end of structure */
1030
switch (comp1->type) {
1031
/* TODO: charged number is untested - please report! */
1032
case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0): /* chargedNumber (0xA0) */
1033
if(rose_presented_number_unscreened_decode(pri, call, comp1->data, comp1->len, &chargednr) != 0)
1035
pri_message(pri, "!! not handled: Received ChargedNr '%s' \n", chargednr.partyaddress);
1036
pri_message(pri, " ton = %d, pres = %d, npi = %d\n", chargednr.ton, chargednr.pres, chargednr.npi);
1039
ASN1_GET_INTEGER(comp1, chargeIdentifier);
1042
pri_message(pri, "!! Invalid AOC-E chargingAssociation. Expected Object Identifier (0xA0) or Integer (0x02) but received 0x%02X\n", comp1->type);
1044
NEXT_COMPONENT(comp1, pos1);
1045
} while (pos1 < len);
1048
pri_message(pri, "!! Only reached position %i in %i bytes long AOC-E structure:", pos1, len );
1049
dump_apdu (pri, data, len);
1050
return -1; /* oops - aborted before */
1052
call->aoc_units = chargingunits;
1057
static int aoc_aoce_charging_unit_encode(struct pri *pri, q931_call *c, long chargedunits)
1059
/* sample data: [ 91 a1 12 02 02 3a 78 02 01 24 30 09 30 07 a1 05 30 03 02 01 01 ] */
1060
int i = 0, res = 0, compsp = 0;
1061
unsigned char buffer[255] = "";
1062
struct rose_component *comp = NULL, *compstk[10];
1064
/* ROSE protocol (0x91)*/
1065
buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_ROSE);
1067
/* ROSE Component (0xA1,len)*/
1068
ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
1069
ASN1_PUSH(compstk, compsp, comp);
1071
/* ROSE invokeId component (0x02,len,id)*/
1072
ASN1_ADD_WORDCOMP(comp, INVOKE_IDENTIFIER, buffer, i, ++pri->last_invoke);
1074
/* ROSE operationId component (0x02,0x01,0x24)*/
1075
ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, ROSE_AOC_AOCE_CHARGING_UNIT);
1077
/* AOCEChargingUnitInfo (0x30,len) */
1078
ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE), buffer, i);
1079
ASN1_PUSH(compstk, compsp, comp);
1081
if (chargedunits > 0) {
1082
/* SpecificChargingUnits (0x30,len) */
1083
ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE), buffer, i);
1084
ASN1_PUSH(compstk, compsp, comp);
1086
/* RecordedUnitsList (0xA1,len) */
1087
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1), buffer, i);
1088
ASN1_PUSH(compstk, compsp, comp);
1090
/* RecordedUnits (0x30,len) */
1091
ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE), buffer, i);
1092
ASN1_PUSH(compstk, compsp, comp);
1094
/* NumberOfUnits (0x02,len,charge) */
1095
ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, chargedunits);
1097
ASN1_FIXUP(compstk, compsp, buffer, i);
1098
ASN1_FIXUP(compstk, compsp, buffer, i);
1099
ASN1_FIXUP(compstk, compsp, buffer, i);
1101
/* freeOfCharge (0x81,0) */
1102
ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1), buffer, i);
1104
ASN1_FIXUP(compstk, compsp, buffer, i);
1105
ASN1_FIXUP(compstk, compsp, buffer, i);
1107
if (pri->debug & PRI_DEBUG_AOC)
1108
dump_apdu (pri, buffer, i);
1110
/* code below is untested */
1111
res = pri_call_apdu_queue(c, Q931_FACILITY, buffer, i, NULL, NULL);
1113
pri_message(pri, "Could not queue ADPU in facility message\n");
1117
/* Remember that if we queue a facility IE for a facility message we
1118
* have to explicitly send the facility message ourselves */
1119
res = q931_facility(c->pri, c);
1121
pri_message(pri, "Could not schedule facility message for call %d\n", c->cr);
1129
extern int rose_invoke_decode(struct pri *pri, q931_call *call, unsigned char *data, int len)
1133
unsigned char *vdata = data;
1134
struct rose_component *comp = NULL, *invokeid = NULL, *operationid = NULL;
1137
/* Invoke ID stuff */
1138
GET_COMPONENT(comp, i, vdata, len);
1139
CHECK_COMPONENT(comp, INVOKE_IDENTIFIER, "Don't know what to do if first ROSE component is of type 0x%x\n");
1141
NEXT_COMPONENT(comp, i);
1144
GET_COMPONENT(comp, i, vdata, len);
1145
CHECK_COMPONENT(comp, ASN1_INTEGER, "Don't know what to do if second ROSE component is of type 0x%x\n");
1147
ASN1_GET_INTEGER(comp, operation_tag);
1148
NEXT_COMPONENT(comp, i);
1150
/* No argument - return with error */
1155
GET_COMPONENT(comp, i, vdata, len);
1159
if (pri->debug & PRI_DEBUG_APDU)
1160
pri_message(pri, " [ Handling operation %d ]\n", operation_tag);
1161
switch (operation_tag) {
1162
case SS_CNID_CALLINGNAME:
1163
if (pri->debug & PRI_DEBUG_APDU)
1164
pri_message(pri, " Handle Name display operation\n");
1165
switch (comp->type) {
1166
case ROSE_NAME_PRESENTATION_ALLOWED_SIMPLE:
1167
memcpy(call->callername, comp->data, comp->len);
1168
call->callername[comp->len] = 0;
1169
if (pri->debug & PRI_DEBUG_APDU)
1170
pri_message(pri, " Received caller name '%s'\n", call->callername);
1173
if (pri->debug & PRI_DEBUG_APDU)
1174
pri_message(pri, "Do not handle argument of type 0x%X\n", comp->type);
1178
case ROSE_DIVERTING_LEG_INFORMATION2:
1179
if (pri->debug & PRI_DEBUG_APDU)
1180
pri_message(pri, " Handle DivertingLegInformation2\n");
1181
return rose_diverting_leg_information2_decode(pri, call, comp, len-i);
1182
case ROSE_AOC_NO_CHARGING_INFO_AVAILABLE:
1183
if (pri->debug & PRI_DEBUG_APDU) {
1184
pri_message(pri, "ROSE %i: AOC No Charging Info Available - not handled!", operation_tag);
1185
dump_apdu (pri, comp->data, comp->len);
1188
case ROSE_AOC_CHARGING_REQUEST:
1189
return aoc_aoce_charging_request_decode(pri, call, (u_int8_t *)comp, comp->len + 2);
1190
case ROSE_AOC_AOCS_CURRENCY:
1191
if (pri->debug & PRI_DEBUG_APDU) {
1192
pri_message(pri, "ROSE %i: AOC-S Currency - not handled!", operation_tag);
1193
dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
1196
case ROSE_AOC_AOCS_SPECIAL_ARR:
1197
if (pri->debug & PRI_DEBUG_APDU) {
1198
pri_message(pri, "ROSE %i: AOC-S Special Array - not handled!", operation_tag);
1199
dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
1202
case ROSE_AOC_AOCD_CURRENCY:
1203
if (pri->debug & PRI_DEBUG_APDU) {
1204
pri_message(pri, "ROSE %i: AOC-D Currency - not handled!", operation_tag);
1205
dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
1208
case ROSE_AOC_AOCD_CHARGING_UNIT:
1209
if (pri->debug & PRI_DEBUG_APDU) {
1210
pri_message(pri, "ROSE %i: AOC-D Charging Unit - not handled!", operation_tag);
1211
dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
1214
case ROSE_AOC_AOCE_CURRENCY:
1215
if (pri->debug & PRI_DEBUG_APDU) {
1216
pri_message(pri, "ROSE %i: AOC-E Currency - not handled!", operation_tag);
1217
dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
1220
case ROSE_AOC_AOCE_CHARGING_UNIT:
1221
return aoc_aoce_charging_unit_decode(pri, call, (u_int8_t *)comp, comp->len + 2);
1222
if (0) { /* the following function is currently not used - just to make the compiler happy */
1223
aoc_aoce_charging_unit_encode(pri, call, call->aoc_units); /* use this function to forward the aoc-e on a bridged channel */
1226
case ROSE_AOC_IDENTIFICATION_OF_CHARGE:
1227
if (pri->debug & PRI_DEBUG_APDU) {
1228
pri_message(pri, "ROSE %i: AOC Identification Of Charge - not handled!", operation_tag);
1229
dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
1233
if (pri->debug & PRI_DEBUG_APDU) {
1234
pri_message(pri, "!! Unable to handle ROSE operation %d", operation_tag);
1235
dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
1244
extern int pri_call_apdu_queue(q931_call *call, int messagetype, void *apdu, int apdu_len, void (*function)(void *data), void *data)
1246
struct apdu_event *cur = NULL;
1247
struct apdu_event *new_event = NULL;
1249
if (!call || !messagetype || !apdu || (apdu_len < 1) || (apdu_len > 255))
1252
new_event = malloc(sizeof(struct apdu_event));
1255
memset(new_event, 0, sizeof(struct apdu_event));
1256
new_event->message = messagetype;
1257
new_event->callback = function;
1258
new_event->data = data;
1259
memcpy(new_event->apdu, apdu, apdu_len);
1260
new_event->apdu_len = apdu_len;
1262
pri_error(call->pri, "!! Malloc failed!\n");
1271
cur->next = new_event;
1273
call->apdus = new_event;
1278
extern int pri_call_apdu_queue_cleanup(q931_call *call)
1280
struct apdu_event *cur_event = NULL, *free_event = NULL;
1282
if (call && call->apdus) {
1283
cur_event = call->apdus;
1285
/* TODO: callbacks, some way of giving return res on status of apdu */
1286
free_event = cur_event;
1287
cur_event = cur_event->next;
1296
extern int pri_call_add_standard_apdus(struct pri *pri, q931_call *call)
1298
if (!pri->sendfacility)
1301
if (pri->switchtype == PRI_SWITCH_QSIG) { /* For Q.SIG it does network and cpe operations */
1302
if (call->redirectingnum[0])
1303
rose_diverting_leg_information2_encode(pri, call);
1304
add_callername_facility_ies(pri, call, 1);
1308
if (pri->localtype == PRI_NETWORK) {
1309
switch (pri->switchtype) {
1310
case PRI_SWITCH_NI2:
1311
add_callername_facility_ies(pri, call, 0);
1317
} else if (pri->localtype == PRI_CPE) {
1318
switch (pri->switchtype) {
1319
case PRI_SWITCH_NI2:
1320
add_callername_facility_ies(pri, call, 1);