~ubuntu-branches/ubuntu/saucy/libpri/saucy

« back to all changes in this revision

Viewing changes to pri_facility.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2005-12-07 21:25:46 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051207212546-lv02jlyw3pm9ho0q
Tags: 1.2.1-1
* New upstream release
* Disable bristuff for new upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libpri: An implementation of Primary Rate ISDN
 
3
 *
 
4
 * Written by Matthew Fredrickson <creslin@digium.com>
 
5
 *
 
6
 * Copyright (C) 2004-2005, Digium
 
7
 * All Rights Reserved.
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; either version 2 of the License, or
 
12
 * (at your option) any later version.
 
13
 * 
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 * 
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 
22
 *
 
23
 */
 
24
 
 
25
#include "compat.h"
 
26
#include "libpri.h"
 
27
#include "pri_internal.h"
 
28
#include "pri_q921.h"
 
29
#include "pri_q931.h"
 
30
#include "pri_facility.h"
 
31
 
 
32
#include <stdio.h>
 
33
#include <stdlib.h>
 
34
#include <string.h>
 
35
 
 
36
static unsigned char get_invokeid(struct pri *pri)
 
37
{
 
38
        return ++pri->last_invoke;
 
39
}
 
40
 
 
41
struct addressingdataelements_presentednumberunscreened {
 
42
        char partyaddress[21];
 
43
        char partysubaddress[21];
 
44
        int  npi;
 
45
        int  ton;
 
46
        int  pres;
 
47
};
 
48
 
 
49
static void dump_apdu(struct pri *pri, unsigned char *c, int len) 
 
50
{
 
51
        #define MAX_APDU_LENGTH 255
 
52
        int i;
 
53
        char message[(2 + MAX_APDU_LENGTH * 3 + 6 + MAX_APDU_LENGTH + 3)] = ""; /* please adjust here, if you make changes below! */
 
54
        
 
55
        if (len > MAX_APDU_LENGTH)
 
56
                return;
 
57
        
 
58
        snprintf(message, sizeof(message)-1, " [");     
 
59
        for (i=0; i<len; i++)
 
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, "�");
 
65
                else
 
66
                        snprintf((char *)(message+strlen(message)), sizeof(message)-strlen(message)-1, "%c", c[i]);
 
67
        }
 
68
        snprintf((char *)(message+strlen(message)), sizeof(message)-strlen(message)-1, "]\n");
 
69
        pri_message(pri, message);
 
70
}
 
71
 
 
72
int redirectingreason_from_q931(struct pri *pri, int redirectingreason)
 
73
{
 
74
        switch(pri->switchtype) {
 
75
                case PRI_SWITCH_QSIG:
 
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);
 
89
                                        /* Fall through */
 
90
                                default:
 
91
                                        return QSIG_DIVERT_REASON_UNKNOWN;
 
92
                        }
 
93
                default:
 
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);
 
108
                                        /* Fall through */
 
109
                                default:
 
110
                                        return Q952_DIVERT_REASON_UNKNOWN;
 
111
                        }
 
112
        }
 
113
}
 
114
 
 
115
static int redirectingreason_for_q931(struct pri *pri, int redirectingreason)
 
116
{
 
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;
 
128
                                default:
 
129
                                        pri_message(pri, "!! Unknown Q.SIG diversion reason %d\n", redirectingreason);
 
130
                                        return PRI_REDIR_UNKNOWN;
 
131
                        }
 
132
                default:
 
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;       /* ??? */
 
147
                                default:
 
148
                                        pri_message(pri, "!! Unknown Q.952 diversion reason %d\n", redirectingreason);
 
149
                                        return PRI_REDIR_UNKNOWN;
 
150
                        }
 
151
        }
 
152
}
 
153
 
 
154
int typeofnumber_from_q931(struct pri *pri, int ton)
 
155
{
 
156
        switch(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:
 
168
                default:
 
169
                        pri_message(pri, "!! Unsupported Q.931 TypeOfNumber value (%d)\n", ton);
 
170
                        /* fall through */
 
171
                case PRI_TON_UNKNOWN:
 
172
                        return Q932_TON_UNKNOWN;
 
173
        }
 
174
}
 
175
 
 
176
static int typeofnumber_for_q931(struct pri *pri, int ton)
 
177
{
 
178
        switch (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;
 
191
                default:
 
192
                        pri_message(pri, "!! Invalid Q.932 TypeOfNumber %d\n", ton);
 
193
                        return PRI_TON_UNKNOWN;
 
194
        }
 
195
}
 
196
 
 
197
int asn1_name_decode(void * data, int len, char *namebuf, int buflen)
 
198
{
 
199
        struct rose_component *comp = (struct rose_component*)data;
 
200
        int datalen = 0, res = 0;
 
201
 
 
202
        if (comp->len == ASN1_LEN_INDEF) {
 
203
                datalen = strlen((char *)comp->data);
 
204
                res = datalen + 2;
 
205
        } else
 
206
                datalen = res = comp->len;
 
207
 
 
208
        if (datalen > buflen) {
 
209
                /* Truncate */
 
210
                datalen = buflen;
 
211
        }
 
212
        memcpy(namebuf, comp->data, datalen);
 
213
        return res + 2;
 
214
}
 
215
 
 
216
int asn1_string_encode(unsigned char asn1_type, void *data, int len, int max_len, void *src, int src_len)
 
217
{
 
218
        struct rose_component *comp = NULL;
 
219
        
 
220
        if (len < 2 + src_len)
 
221
                return -1;
 
222
 
 
223
        if (max_len && (src_len > max_len))
 
224
                src_len = max_len;
 
225
 
 
226
        comp = (struct rose_component *)data;
 
227
        comp->type = asn1_type;
 
228
        comp->len = src_len;
 
229
        memcpy(comp->data, src, src_len);
 
230
        
 
231
        return 2 + src_len;
 
232
}
 
233
 
 
234
int asn1_copy_string(char * buf, int buflen, struct rose_component *comp)
 
235
{
 
236
        int res;
 
237
        int datalen;
 
238
 
 
239
        if ((comp->len > buflen) && (comp->len != ASN1_LEN_INDEF))
 
240
                return -1;
 
241
 
 
242
        if (comp->len == ASN1_LEN_INDEF) {
 
243
                datalen = strlen((char*)comp->data);
 
244
                res = datalen + 2;
 
245
        } else
 
246
                res = datalen = comp->len;
 
247
 
 
248
        memcpy(buf, comp->data, datalen);
 
249
        buf[datalen] = 0;
 
250
 
 
251
        return res;
 
252
}
 
253
 
 
254
static int rose_number_digits_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
 
255
{
 
256
        int i = 0;
 
257
        struct rose_component *comp = NULL;
 
258
        unsigned char *vdata = data;
 
259
        int datalen = 0;
 
260
        int res = 0;
 
261
 
 
262
        do {
 
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);
 
267
                        return -1;
 
268
                }
 
269
                if (comp->len == ASN1_LEN_INDEF) {
 
270
                        datalen = strlen((char *)comp->data);
 
271
                        res = datalen + 2;
 
272
                } else
 
273
                        res = datalen = comp->len;
 
274
                        
 
275
                memcpy(value->partyaddress, comp->data, datalen);
 
276
                value->partyaddress[datalen] = '\0';
 
277
 
 
278
                return res + 2;
 
279
        }
 
280
        while(0);
 
281
        
 
282
        return -1;
 
283
}
 
284
 
 
285
static int rose_public_party_number_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
 
286
{
 
287
        int i = 0;
 
288
        struct rose_component *comp = NULL;
 
289
        unsigned char *vdata = data;
 
290
        int ton;
 
291
        int res = 0;
 
292
 
 
293
        if (len < 2)
 
294
                return -1;
 
295
 
 
296
        do {
 
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);
 
302
 
 
303
                res = rose_number_digits_decode(pri, call, &vdata[i], len-i, value);
 
304
                if (res < 0)
 
305
                        return -1;
 
306
                value->ton = ton;
 
307
 
 
308
                return res + 3;
 
309
 
 
310
        } while(0);
 
311
        return -1;
 
312
}
 
313
 
 
314
static int rose_address_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
 
315
{
 
316
        int i = 0;
 
317
        struct rose_component *comp = NULL;
 
318
        unsigned char *vdata = data;
 
319
        int res = 0;
 
320
 
 
321
        do {
 
322
                GET_COMPONENT(comp, i, vdata, len);
 
323
 
 
324
                switch(comp->type) {
 
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);
 
327
                        if (res < 0)
 
328
                                return -1;
 
329
                        value->npi = PRI_NPI_UNKNOWN;
 
330
                        value->ton = PRI_TON_UNKNOWN;
 
331
                        break;
 
332
                case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0):      /* [0] unknownPartyNumber */
 
333
                        res = asn1_copy_string(value->partyaddress, sizeof(value->partyaddress), comp);
 
334
                        if (res < 0)
 
335
                                return -1;
 
336
                        value->npi = PRI_NPI_UNKNOWN;
 
337
                        value->ton = PRI_TON_UNKNOWN;
 
338
                        break;
 
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);
 
341
                        if (res < 0)
 
342
                                return -1;
 
343
                        value->npi = PRI_NPI_E163_E164;
 
344
                        break;
 
345
                case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_2):   /* [2] nsapEncodedNumber */
 
346
                        pri_message(pri, "!! NsapEncodedNumber isn't handled\n");
 
347
                        return -1;
 
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))
 
350
                                return -1;
 
351
                        value->npi = PRI_NPI_X121 /* ??? */;
 
352
                        value->ton = PRI_TON_UNKNOWN /* ??? */;
 
353
                        pri_message(pri, "!! dataPartyNumber isn't handled\n");
 
354
                        return -1;
 
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);
 
357
                        if (res < 0)
 
358
                                return -1;
 
359
                        value->npi = PRI_NPI_F69 /* ??? */;
 
360
                        value->ton = PRI_TON_UNKNOWN /* ??? */;
 
361
                        pri_message(pri, "!! telexPartyNumber isn't handled\n");
 
362
                        return -1;
 
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;
 
366
                        return -1;
 
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);
 
369
                        if (res < 0)
 
370
                                return -1;
 
371
                        value->npi = PRI_NPI_NATIONAL;
 
372
                        value->ton = PRI_TON_NATIONAL;
 
373
                        break;
 
374
                default:
 
375
                        pri_message(pri, "!! Unknown Party number component received 0x%X\n", comp->type);
 
376
                        return -1;
 
377
                }
 
378
                ASN1_FIXUP_LEN(comp, res);
 
379
                NEXT_COMPONENT(comp, i);
 
380
                if(i < len)
 
381
                        pri_message(pri, "!! not all information is handled from Address component\n");
 
382
                return res + 2;
 
383
        }
 
384
        while (0);
 
385
 
 
386
        return -1;
 
387
}
 
388
 
 
389
static int rose_presented_number_unscreened_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
 
390
{
 
391
        int i = 0;
 
392
        int size = 0;
 
393
        struct rose_component *comp = NULL;
 
394
        unsigned char *vdata = data;
 
395
 
 
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 */
 
400
 
 
401
        do {
 
402
                GET_COMPONENT(comp, i, vdata, len);
 
403
 
 
404
                switch(comp->type) {
 
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);
 
409
                        return size + 2;
 
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");
 
413
                                return -1;
 
414
                        }
 
415
                        value->pres = PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
 
416
                        return 2;
 
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");
 
420
                                return -1;
 
421
                        }
 
422
                        value->pres = PRES_NUMBER_NOT_AVAILABLE;
 
423
                        return 2;
 
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);
 
428
                        return size + 2;
 
429
                default:
 
430
                        pri_message(pri, "Invalid PresentedNumberUnscreened component 0x%X\n", comp->type);
 
431
                }
 
432
                return -1;
 
433
        }
 
434
        while (0);
 
435
 
 
436
        return -1;
 
437
}
 
438
 
 
439
static int rose_diverting_leg_information2_decode(struct pri *pri, q931_call *call, struct rose_component *sequence, int len)
 
440
{
 
441
        int i = 0;
 
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;
 
449
        int res = 0;
 
450
 
 
451
        /* Data checks */
 
452
        if (sequence->type != (ASN1_CONSTRUCTOR | ASN1_SEQUENCE)) { /* Constructed Sequence */
 
453
                pri_message(pri, "Invalid DivertingLegInformation2Type argument\n");
 
454
                return -1;
 
455
        }
 
456
 
 
457
        if (sequence->len == ASN1_LEN_INDEF) {
 
458
                len -= 4; /* For the 2 extra characters at the end
 
459
                           * and two characters of header */
 
460
        } else
 
461
                len -= 2;
 
462
 
 
463
        do {
 
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);
 
469
 
 
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);
 
475
 
 
476
                diversion_reason = redirectingreason_for_q931(pri, diversion_reason);
 
477
        
 
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);
 
481
 
 
482
                for(; i < len; NEXT_COMPONENT(comp, i)) {
 
483
                        GET_COMPONENT(comp, i, vdata, len);
 
484
                        switch(comp->type) {
 
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);
 
489
                                break;
 
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);
 
494
                                comp->len = res;
 
495
                                if (res < 0)
 
496
                                        return -1;
 
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);
 
500
                                }
 
501
                                break;
 
502
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_2):
 
503
                                res = rose_presented_number_unscreened_decode(pri, call, comp->data, comp->len, &originalcallednr);
 
504
                                if (res < 0)
 
505
                                        return -1;
 
506
                                ASN1_FIXUP_LEN(comp, res);
 
507
                                comp->len = 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);
 
511
                                }
 
512
                                break;
 
513
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_3):
 
514
                                res = asn1_name_decode(comp->data, comp->len, redirectingname, sizeof(redirectingname));
 
515
                                if (res < 0)
 
516
                                        return -1;
 
517
                                ASN1_FIXUP_LEN(comp, res);
 
518
                                comp->len = res;
 
519
                                if (pri->debug & PRI_DEBUG_APDU)
 
520
                                        pri_message(pri, "    Received RedirectingName '%s'\n", redirectingname);
 
521
                                break;
 
522
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_4):
 
523
                                res = asn1_name_decode(comp->data, comp->len, origcalledname, sizeof(origcalledname));
 
524
                                if (res < 0)
 
525
                                        return -1;
 
526
                                ASN1_FIXUP_LEN(comp, res);
 
527
                                comp->len = res;
 
528
                                if (pri->debug & PRI_DEBUG_APDU)
 
529
                                        pri_message(pri, "    Received Originally Called Name '%s'\n", origcalledname);
 
530
                                break;
 
531
                        default:
 
532
                                if (comp->type == 0 && comp->len == 0) {
 
533
                                        break; /* Found termination characters */
 
534
                                }
 
535
                                pri_message(pri, "!! Invalid DivertingLegInformation2 component received 0x%X\n", comp->type);
 
536
                                return -1;
 
537
                        }
 
538
                }
 
539
 
 
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));
 
545
                }
 
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));
 
550
                }
 
551
                libpri_copy_string(call->redirectingname, redirectingname, sizeof(call->redirectingname));
 
552
                libpri_copy_string(call->origcalledname, origcalledname, sizeof(call->origcalledname));
 
553
                return 0;
 
554
        }
 
555
        while (0);
 
556
 
 
557
        return -1;
 
558
}
 
559
                                
 
560
static int rose_diverting_leg_information2_encode(struct pri *pri, q931_call *call)
 
561
{
 
562
        int i = 0, j, compsp = 0;
 
563
        struct rose_component *comp, *compstk[10];
 
564
        unsigned char buffer[256];
 
565
        int len = 253;
 
566
        
 
567
        if (!strlen(call->callername)) {
 
568
                return -1;
 
569
        }
 
570
 
 
571
        buffer[i] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
 
572
        i++;
 
573
        /* Interpretation component */
 
574
        ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 0x00 /* Discard unrecognized invokes */);
 
575
        
 
576
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
 
577
        
 
578
        ASN1_PUSH(compstk, compsp, comp);
 
579
        /* Invoke component contents */
 
580
        /*      Invoke ID */
 
581
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
 
582
        /*      Operation Tag */
 
583
        
 
584
        /* ROSE operationId component */
 
585
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, ROSE_DIVERTING_LEG_INFORMATION2);
 
586
 
 
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);
 
593
        
 
594
        /* ROSE DivertingLegInformation2.diversionReason component */
 
595
        ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, redirectingreason_from_q931(pri, call->redirectingreason));
 
596
                
 
597
        /* ROSE DivertingLegInformation2.divertingNr component */
 
598
        ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1), buffer, i);
 
599
        
 
600
        ASN1_PUSH(compstk, compsp, comp);
 
601
                /* Redirecting information always not screened */
 
602
        
 
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));
 
614
                                if (j < 0)
 
615
                                        return -1;
 
616
                                        
 
617
                                i += j;
 
618
                                ASN1_FIXUP(compstk, compsp, buffer, i);
 
619
                                ASN1_FIXUP(compstk, compsp, buffer, i);
 
620
                                break;
 
621
                        }
 
622
                        /* fall through */
 
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);
 
626
                        break;
 
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);
 
633
                        break;
 
634
                default:
 
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);
 
638
                        break;
 
639
        }
 
640
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
641
 
 
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));
 
656
        
 
657
                                j = asn1_string_encode(ASN1_NUMERICSTRING, &buffer[i], len - i, 20, call->redirectingnum, strlen(call->redirectingnum));
 
658
                                if (j < 0)
 
659
                                        return -1;
 
660
                                
 
661
                                i += j;
 
662
                                ASN1_FIXUP(compstk, compsp, buffer, i);
 
663
                                ASN1_FIXUP(compstk, compsp, buffer, i);
 
664
                                break;
 
665
                        }
 
666
                                /* fall through */
 
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);
 
670
                        break;
 
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);
 
677
                        break;
 
678
                default:
 
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);
 
682
                        break;
 
683
        }
 
684
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
685
                
 
686
        /* Fix length of stacked components */
 
687
        while(compsp > 0) {
 
688
                ASN1_FIXUP(compstk, compsp, buffer, i);
 
689
        }
 
690
        
 
691
        if (pri_call_apdu_queue(call, Q931_SETUP, buffer, i, NULL, NULL))
 
692
                return -1;
 
693
                
 
694
        return 0;
 
695
}
 
696
 
 
697
/* Sending callername information functions */
 
698
static int add_callername_facility_ies(struct pri *pri, q931_call *c, int cpe)
 
699
{
 
700
        int res = 0;
 
701
        int i = 0;
 
702
        unsigned char buffer[256];
 
703
        unsigned char namelen = 0;
 
704
        struct rose_component *comp = NULL, *compstk[10];
 
705
        int compsp = 0;
 
706
        int mymessage = 0;
 
707
        static unsigned char op_tag[] = { 
 
708
                0x2a, /* informationFollowing 42 */
 
709
                0x86,
 
710
                0x48,
 
711
                0xce,
 
712
                0x15,
 
713
                0x00,
 
714
                0x04
 
715
        };
 
716
                
 
717
        if (!strlen(c->callername)) {
 
718
                return -1;
 
719
        }
 
720
 
 
721
        buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
 
722
        /* Interpretation component */
 
723
 
 
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);
 
729
 
 
730
        ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 0);
 
731
 
 
732
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
 
733
        ASN1_PUSH(compstk, compsp, comp);
 
734
        /* Invoke ID */
 
735
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
 
736
 
 
737
        /* Operation Tag */
 
738
        res = asn1_string_encode(ASN1_OBJECTIDENTIFIER, &buffer[i], sizeof(buffer)-i, sizeof(op_tag), op_tag, sizeof(op_tag));
 
739
        if (res < 0)
 
740
                return -1;
 
741
        i += res;
 
742
 
 
743
        ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 0);
 
744
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
745
 
 
746
        if (!cpe) {
 
747
                if (pri_call_apdu_queue(c, Q931_SETUP, buffer, i, NULL, NULL))
 
748
                        return -1;
 
749
        }
 
750
 
 
751
 
 
752
        /* Now the ADPu that contains the information that needs sent.
 
753
         * We can reuse the buffer since the queue function doesn't
 
754
         * need it. */
 
755
 
 
756
        i = 0;
 
757
        namelen = strlen(c->callername);
 
758
        if (namelen > 50) {
 
759
                namelen = 50; /* truncate the name */
 
760
        }
 
761
 
 
762
        buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
 
763
        /* Interpretation component */
 
764
 
 
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);
 
770
 
 
771
        ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 0);
 
772
 
 
773
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
 
774
        ASN1_PUSH(compstk, compsp, comp);
 
775
 
 
776
        /* Invoke ID */
 
777
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
 
778
 
 
779
        /* Operation ID: Calling name */
 
780
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, SS_CNID_CALLINGNAME);
 
781
 
 
782
        res = asn1_string_encode((ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0), &buffer[i], sizeof(buffer)-i,  50, c->callername, namelen);
 
783
        if (res < 0)
 
784
                return -1;
 
785
        i += res;
 
786
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
787
 
 
788
        if (cpe) 
 
789
                mymessage = Q931_SETUP;
 
790
        else
 
791
                mymessage = Q931_FACILITY;
 
792
 
 
793
        if (pri_call_apdu_queue(c, mymessage, buffer, i, NULL, NULL))
 
794
                return -1;
 
795
        
 
796
        return 0;
 
797
}
 
798
/* End Callername */
 
799
 
 
800
/* MWI related encode and decode functions */
 
801
static void mwi_activate_encode_cb(void *data)
 
802
{
 
803
        return;
 
804
}
 
805
 
 
806
extern int mwi_message_send(struct pri* pri, q931_call *call, struct pri_sr *req, int activate)
 
807
{
 
808
        int i = 0;
 
809
        unsigned char buffer[255] = "";
 
810
        int destlen = strlen(req->called);
 
811
        struct rose_component *comp = NULL, *compstk[10];
 
812
        int compsp = 0;
 
813
        int res;
 
814
 
 
815
        if (destlen <= 0) {
 
816
                return -1;
 
817
        } else if (destlen > 20)
 
818
                destlen = 20;  /* Destination number cannot be greater then 20 digits */
 
819
 
 
820
        buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
 
821
        /* Interpretation component */
 
822
 
 
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);
 
828
 
 
829
        ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 0);
 
830
 
 
831
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
 
832
        ASN1_PUSH(compstk, compsp, comp);
 
833
 
 
834
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
 
835
 
 
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);
 
839
        /* PartyNumber */
 
840
        res = asn1_string_encode((ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0), &buffer[i], sizeof(buffer)-i, destlen, req->called, destlen);
 
841
        
 
842
        if (res < 0)
 
843
                return -1;
 
844
        i += res;
 
845
 
 
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);
 
850
 
 
851
        return pri_call_apdu_queue(call, Q931_SETUP, buffer, i, mwi_activate_encode_cb, NULL);
 
852
}
 
853
/* End MWI */
 
854
 
 
855
/* EECT functions */
 
856
extern int eect_initiate_transfer(struct pri *pri, q931_call *c1, q931_call *c2)
 
857
{
 
858
        /* Did all the tests to see if we're on the same PRI and
 
859
         * are on a compatible switchtype */
 
860
        /* TODO */
 
861
        int i = 0;
 
862
        int res = 0;
 
863
        unsigned char buffer[255] = "";
 
864
        unsigned short call_reference = c2->cr;
 
865
        struct rose_component *comp = NULL, *compstk[10];
 
866
        int compsp = 0;
 
867
        static unsigned char op_tag[] = {
 
868
                0x2A,
 
869
                0x86,
 
870
                0x48,
 
871
                0xCE,
 
872
                0x15,
 
873
                0x00,
 
874
                0x08,
 
875
        };
 
876
 
 
877
        buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
 
878
        /* Interpretation component */
 
879
 
 
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);
 
885
 
 
886
        ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 0);
 
887
 
 
888
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
 
889
        ASN1_PUSH(compstk, compsp, comp);
 
890
 
 
891
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
 
892
 
 
893
        res = asn1_string_encode(ASN1_OBJECTIDENTIFIER, &buffer[i], sizeof(buffer)-i, sizeof(op_tag), op_tag, sizeof(op_tag));
 
894
        if (res < 0)
 
895
                return -1;
 
896
        i += res;
 
897
 
 
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);
 
903
 
 
904
        res = pri_call_apdu_queue(c1, Q931_FACILITY, buffer, i, NULL, NULL);
 
905
        if (res) {
 
906
                pri_message(pri, "Could not queue ADPU in facility message\n");
 
907
                return -1;
 
908
        }
 
909
 
 
910
        /* Remember that if we queue a facility IE for a facility message we
 
911
         * have to explicitly send the facility message ourselves */
 
912
 
 
913
        res = q931_facility(c1->pri, c1);
 
914
        if (res) {
 
915
                pri_message(pri, "Could not schedule facility message for call %d\n", c1->cr);
 
916
                return -1;
 
917
        }
 
918
 
 
919
        return 0;
 
920
}
 
921
/* End EECT */
 
922
 
 
923
/* AOC */
 
924
static int aoc_aoce_charging_request_decode(struct pri *pri, q931_call *call, unsigned char *data, int len) 
 
925
{
 
926
        int chargingcase = -1;
 
927
        unsigned char *vdata = data;
 
928
        struct rose_component *comp = NULL;
 
929
        int pos1 = 0;
 
930
 
 
931
        if (pri->debug & PRI_DEBUG_AOC)
 
932
                dump_apdu (pri, data, len);
 
933
 
 
934
        do {
 
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);
 
942
                } else {
 
943
                        pri_message(pri, "!! unkown AOC ChargingCase: 0x%02X", chargingcase);
 
944
                        chargingcase = -1;
 
945
                }
 
946
                NEXT_COMPONENT(comp, pos1);
 
947
        } while (pos1 < len);
 
948
        if (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 */
 
952
        }
 
953
        return 0;
 
954
}
 
955
        
 
956
 
 
957
static int aoc_aoce_charging_unit_decode(struct pri *pri, q931_call *call, unsigned char *data, int len) 
 
958
{
 
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;
 
964
 
 
965
        if (pri->debug & PRI_DEBUG_AOC)
 
966
                dump_apdu (pri, data, len);
 
967
 
 
968
        do {
 
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; 
 
976
                                pos2 = pos1;
 
977
                                comp2 = comp1;
 
978
                                SUB_COMPONENT(comp2, pos2);
 
979
                                do {
 
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;
 
987
                                                        pos3 = pos2;
 
988
                                                        comp3 = comp2;
 
989
                                                        SUB_COMPONENT(comp3, pos3);
 
990
                                                        do {
 
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 */
 
997
                                                                                break;
 
998
                                                                        default:
 
999
                                                                                pri_message(pri, "!! Don't know how to handle 0x%02X in AOC-E RecordedUnits\n", comp3->type);
 
1000
                                                                }
 
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");
 
1006
                                                        break;
 
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);
 
1013
                                                        break;
 
1014
                                                default:
 
1015
                                                        pri_message(pri, "!! Don't know how to handle 0x%02X in AOC-E RecordedUnitsList\n", comp2->type);
 
1016
                                        }
 
1017
                                        NEXT_COMPONENT(comp2, pos2);
 
1018
                                } while (pos2 < sublen2);
 
1019
                                break;
 
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);
 
1023
                                chargingunits = 0;
 
1024
                                break;
 
1025
                        default:
 
1026
                                pri_message(pri, "!! Invalid AOC-E specificChargingUnits. Expected Sequence (0x30) or Object Identifier (0x81/0x01) but received 0x%02X\n", comp1->type);
 
1027
                }
 
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)
 
1034
                                        return -1;
 
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);
 
1037
                                break;
 
1038
                        case ASN1_INTEGER:
 
1039
                                ASN1_GET_INTEGER(comp1, chargeIdentifier);
 
1040
                                break;
 
1041
                        default:
 
1042
                                pri_message(pri, "!! Invalid AOC-E chargingAssociation. Expected Object Identifier (0xA0) or Integer (0x02) but received 0x%02X\n", comp1->type);
 
1043
                }
 
1044
                NEXT_COMPONENT(comp1, pos1);
 
1045
        } while (pos1 < len);
 
1046
 
 
1047
        if (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 */
 
1051
        }
 
1052
        call->aoc_units = chargingunits;
 
1053
        
 
1054
        return 0;
 
1055
}
 
1056
 
 
1057
static int aoc_aoce_charging_unit_encode(struct pri *pri, q931_call *c, long chargedunits)
 
1058
{
 
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];
 
1063
 
 
1064
        /* ROSE protocol (0x91)*/
 
1065
        buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_ROSE);
 
1066
 
 
1067
        /* ROSE Component (0xA1,len)*/
 
1068
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
 
1069
        ASN1_PUSH(compstk, compsp, comp); 
 
1070
 
 
1071
        /* ROSE invokeId component (0x02,len,id)*/
 
1072
        ASN1_ADD_WORDCOMP(comp, INVOKE_IDENTIFIER, buffer, i, ++pri->last_invoke);
 
1073
 
 
1074
        /* ROSE operationId component (0x02,0x01,0x24)*/
 
1075
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, ROSE_AOC_AOCE_CHARGING_UNIT);
 
1076
 
 
1077
        /* AOCEChargingUnitInfo (0x30,len) */
 
1078
        ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE), buffer, i);
 
1079
        ASN1_PUSH(compstk, compsp, comp);
 
1080
 
 
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);
 
1085
 
 
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);
 
1089
                
 
1090
                /* RecordedUnits (0x30,len) */
 
1091
                ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE), buffer, i);
 
1092
                ASN1_PUSH(compstk, compsp, comp);
 
1093
                
 
1094
                /* NumberOfUnits (0x02,len,charge) */
 
1095
                ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, chargedunits);
 
1096
 
 
1097
                ASN1_FIXUP(compstk, compsp, buffer, i);
 
1098
                ASN1_FIXUP(compstk, compsp, buffer, i);
 
1099
                ASN1_FIXUP(compstk, compsp, buffer, i);
 
1100
        } else {
 
1101
                /* freeOfCharge (0x81,0) */
 
1102
                ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1), buffer, i);
 
1103
        }
 
1104
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1105
        ASN1_FIXUP(compstk, compsp, buffer, i); 
 
1106
        
 
1107
        if (pri->debug & PRI_DEBUG_AOC)
 
1108
                dump_apdu (pri, buffer, i);
 
1109
                
 
1110
        /* code below is untested */
 
1111
        res = pri_call_apdu_queue(c, Q931_FACILITY, buffer, i, NULL, NULL);
 
1112
        if (res) {
 
1113
                pri_message(pri, "Could not queue ADPU in facility message\n");
 
1114
                return -1;
 
1115
        }
 
1116
 
 
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);
 
1120
        if (res) {
 
1121
                pri_message(pri, "Could not schedule facility message for call %d\n", c->cr);
 
1122
                return -1;
 
1123
        }
 
1124
 
 
1125
        return 0;
 
1126
}
 
1127
/* End AOC */
 
1128
 
 
1129
extern int rose_invoke_decode(struct pri *pri, q931_call *call, unsigned char *data, int len)
 
1130
{
 
1131
        int i = 0;
 
1132
        int operation_tag;
 
1133
        unsigned char *vdata = data;
 
1134
        struct rose_component *comp = NULL, *invokeid = NULL, *operationid = NULL;
 
1135
        
 
1136
        do {
 
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");
 
1140
                invokeid = comp;
 
1141
                NEXT_COMPONENT(comp, i);
 
1142
 
 
1143
                /* Operation Tag */
 
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");
 
1146
                operationid = comp;
 
1147
                ASN1_GET_INTEGER(comp, operation_tag);
 
1148
                NEXT_COMPONENT(comp, i);
 
1149
 
 
1150
                /* No argument - return with error */
 
1151
                if (i >= len) 
 
1152
                        return -1;
 
1153
 
 
1154
                /* Arguement Tag */
 
1155
                GET_COMPONENT(comp, i, vdata, len);
 
1156
                if (!comp->type)
 
1157
                        return -1;
 
1158
 
 
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);
 
1171
                                        return 0;
 
1172
                                default:
 
1173
                                        if (pri->debug & PRI_DEBUG_APDU)
 
1174
                                                pri_message(pri, "Do not handle argument of type 0x%X\n", comp->type);
 
1175
                                        return -1;
 
1176
                        }
 
1177
                        break;
 
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);
 
1186
                        }
 
1187
                        return -1;
 
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);
 
1194
                        }
 
1195
                        return -1;
 
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);
 
1200
                        }
 
1201
                        return -1;
 
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);
 
1206
                        }
 
1207
                        return -1;
 
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);
 
1212
                        }
 
1213
                        return -1;
 
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);
 
1218
                        }
 
1219
                        return -1;
 
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 */ 
 
1224
                                return 0;
 
1225
                        }
 
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);
 
1230
                        }
 
1231
                        return -1;
 
1232
                default:
 
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);
 
1236
                        }
 
1237
                        return -1;
 
1238
                }
 
1239
        } while(0);
 
1240
        
 
1241
        return -1;
 
1242
}
 
1243
 
 
1244
extern int pri_call_apdu_queue(q931_call *call, int messagetype, void *apdu, int apdu_len, void (*function)(void *data), void *data)
 
1245
{
 
1246
        struct apdu_event *cur = NULL;
 
1247
        struct apdu_event *new_event = NULL;
 
1248
 
 
1249
        if (!call || !messagetype || !apdu || (apdu_len < 1) || (apdu_len > 255))
 
1250
                return -1;
 
1251
 
 
1252
        new_event = malloc(sizeof(struct apdu_event));
 
1253
 
 
1254
        if (new_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;
 
1261
        } else {
 
1262
                pri_error(call->pri, "!! Malloc failed!\n");
 
1263
                return -1;
 
1264
        }
 
1265
        
 
1266
        if (call->apdus) {
 
1267
                cur = call->apdus;
 
1268
                while (cur->next) {
 
1269
                        cur = cur->next;
 
1270
                }
 
1271
                cur->next = new_event;
 
1272
        } else
 
1273
                call->apdus = new_event;
 
1274
 
 
1275
        return 0;
 
1276
}
 
1277
 
 
1278
extern int pri_call_apdu_queue_cleanup(q931_call *call)
 
1279
{
 
1280
        struct apdu_event *cur_event = NULL, *free_event = NULL;
 
1281
 
 
1282
        if (call && call->apdus) {
 
1283
                cur_event = call->apdus;
 
1284
                while (cur_event) {
 
1285
                        /* TODO: callbacks, some way of giving return res on status of apdu */
 
1286
                        free_event = cur_event;
 
1287
                        cur_event = cur_event->next;
 
1288
                        free(free_event);
 
1289
                }
 
1290
                call->apdus = NULL;
 
1291
        }
 
1292
 
 
1293
        return 0;
 
1294
}
 
1295
 
 
1296
extern int pri_call_add_standard_apdus(struct pri *pri, q931_call *call)
 
1297
{
 
1298
        if (!pri->sendfacility)
 
1299
                return 0;
 
1300
 
 
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);
 
1305
                return 0;
 
1306
        }
 
1307
 
 
1308
        if (pri->localtype == PRI_NETWORK) {
 
1309
                switch (pri->switchtype) {
 
1310
                        case PRI_SWITCH_NI2:
 
1311
                                add_callername_facility_ies(pri, call, 0);
 
1312
                                break;
 
1313
                        default:
 
1314
                                break;
 
1315
                }
 
1316
                return 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);
 
1321
                                break;
 
1322
                        default:
 
1323
                                break;
 
1324
                }
 
1325
                return 0;
 
1326
        }
 
1327
 
 
1328
        return 0;
 
1329
}
 
1330