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

« back to all changes in this revision

Viewing changes to pri_facility.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2009-04-02 22:03:13 UTC
  • mfrom: (6.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090402220313-72of1j1ij7h4fw3j
Tags: 1.4.9-2
* Upload to unstable
  - pkg-voip transition discussed on debian-release
* Drop oldstable Conflicts: libpri1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * Written by Matthew Fredrickson <creslin@digium.com>
5
5
 *
6
 
 * Copyright (C) 2004-2005, Digium
 
6
 * Copyright (C) 2004-2005, Digium, Inc.
7
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
 
 *
 
8
 */
 
9
 
 
10
/*
 
11
 * See http://www.asterisk.org for more information about
 
12
 * the Asterisk project. Please do not directly contact
 
13
 * any of the maintainers of this project for assistance;
 
14
 * the project provides a web site, mailing lists and IRC
 
15
 * channels for your use.
 
16
 *
 
17
 * This program is free software, distributed under the terms of
 
18
 * the GNU General Public License Version 2 as published by the
 
19
 * Free Software Foundation. See the LICENSE file included with
 
20
 * this program for more details.
 
21
 *
 
22
 * In addition, when this program is distributed with Asterisk in
 
23
 * any form that would qualify as a 'combined work' or as a
 
24
 * 'derivative work' (but not mere aggregation), you can redistribute
 
25
 * and/or modify the combination under the terms of the license
 
26
 * provided with that copy of Asterisk, instead of the license
 
27
 * terms granted here.
23
28
 */
24
29
 
25
30
#include "compat.h"
167
172
struct addressingdataelements_presentednumberunscreened {
168
173
        char partyaddress[21];
169
174
        char partysubaddress[21];
170
 
        int  npi;
171
 
        int  ton;
172
 
        int  pres;
 
175
        int  npi;       /* Numbering Plan Indicator */
 
176
        int  ton;       /* Type Of Number */
 
177
        int  pres;      /* Presentation */
 
178
};
 
179
 
 
180
struct addressingdataelements_presentednumberscreened {
 
181
        char partyaddress[21];
 
182
        char partysubaddress[21];
 
183
        int  npi;       /* Numbering Plan Indicator */
 
184
        int  ton;       /* Type Of Number */
 
185
        int  pres;      /* Presentation */
 
186
        int  scrind;    /* Screening Indicator */
173
187
};
174
188
 
175
189
#define PRI_CHECKOVERFLOW(size) \
453
467
        return -1;
454
468
}
455
469
 
 
470
static int rose_private_party_number_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
 
471
{
 
472
        int i = 0;
 
473
        struct rose_component *comp = NULL;
 
474
        unsigned char *vdata = data;
 
475
        int ton;
 
476
        int res = 0;
 
477
 
 
478
        if (len < 2)
 
479
        return -1;
 
480
 
 
481
        do {
 
482
                GET_COMPONENT(comp, i, vdata, len);
 
483
                CHECK_COMPONENT(comp, ASN1_ENUMERATED, "Don't know what to do with PrivatePartyNumber ROSE component type 0x%x\n");
 
484
                ASN1_GET_INTEGER(comp, ton);
 
485
                NEXT_COMPONENT(comp, i);
 
486
                ton = typeofnumber_for_q931(pri, ton);
 
487
 
 
488
                res = rose_number_digits_decode(pri, call, &vdata[i], len-i, value);
 
489
                if (res < 0)
 
490
                  return -1;
 
491
                value->ton = ton;
 
492
 
 
493
                return res + 3;
 
494
 
 
495
        } while(0);
 
496
        return -1;
 
497
}
 
498
 
456
499
static int rose_address_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
457
500
{
458
501
        int i = 0;
503
546
                        pri_message(pri, "!! telexPartyNumber isn't handled\n");
504
547
                        return -1;
505
548
                case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_5):   /* [5] priavePartyNumber */
506
 
                        pri_message(pri, "!! privatePartyNumber isn't handled\n");
 
549
                        res = rose_private_party_number_decode(pri, call, comp->data, comp->len, value);
 
550
                        if (res < 0)
 
551
                        return -1;
507
552
                        value->npi = PRI_NPI_PRIVATE;
508
 
                        return -1;
 
553
                        break;
509
554
                case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_8):   /* [8] nationalStandardPartyNumber */
510
555
                        res = rose_number_digits_decode(pri, call, comp->data, comp->len, value);
511
556
                        if (res < 0)
589
634
        struct rose_component *comp = NULL;
590
635
        unsigned char *vdata = sequence->data;
591
636
        int res = 0;
 
637
        memset(&divertingnr, 0, sizeof(divertingnr));
 
638
        memset(&originalcallednr, 0, sizeof(originalcallednr));
592
639
 
593
640
        /* Data checks */
594
641
        if (sequence->type != (ASN1_CONSTRUCTOR | ASN1_SEQUENCE)) { /* Constructed Sequence */
670
717
                                if (pri->debug & PRI_DEBUG_APDU)
671
718
                                        pri_message(pri, "    Received Originally Called Name '%s'\n", origcalledname);
672
719
                                break;
 
720
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_5):
 
721
                                pri_message(pri, "!! Ignoring DivertingLegInformation2 component 0x%X\n", comp->type);
 
722
                                break;
673
723
                        default:
674
724
                                if (comp->type == 0 && comp->len == 0) {
675
725
                                        break; /* Found termination characters */
684
734
                        call->redirectingpres = divertingnr.pres;
685
735
                        call->redirectingreason = diversion_reason;
686
736
                        libpri_copy_string(call->redirectingnum, divertingnr.partyaddress, sizeof(call->redirectingnum));
 
737
                        pri_message(pri, "    Received redirectingnum '%s' (%d)\n", call->redirectingnum, (int)call->redirectingnum[0]);
687
738
                }
688
739
                if (originalcallednr.pres >= 0) {
689
740
                        call->origcalledplan = originalcallednr.npi;
690
741
                        call->origcalledpres = originalcallednr.pres;
691
742
                        libpri_copy_string(call->origcallednum, originalcallednr.partyaddress, sizeof(call->origcallednum));
 
743
                        pri_message(pri, "    Received origcallednum '%s' (%d)\n", call->origcallednum, (int)call->origcallednum[0]);
692
744
                }
693
745
                libpri_copy_string(call->redirectingname, redirectingname, sizeof(call->redirectingname));
694
746
                libpri_copy_string(call->origcalledname, origcalledname, sizeof(call->origcalledname));
1134
1186
}
1135
1187
/* End EECT */
1136
1188
 
 
1189
/* QSIG CF CallRerouting */
 
1190
int qsig_cf_callrerouting(struct pri *pri, q931_call *c, const char* dest, const char* original, const char* reason)
 
1191
{
 
1192
/*CallRerouting ::= OPERATION
 
1193
    -- Sent from the Served User PINX to the Rerouting PINX
 
1194
    ARGUMENT SEQUENCE
 
1195
    { reroutingReason DiversionReason,
 
1196
    originalReroutingReason [0] IMPLICIT DiversionReason OPTIONAL,
 
1197
    calledAddress Address,
 
1198
    diversionCounter INTEGER (1..15),
 
1199
    pSS1InfoElement PSS1InformationElement,
 
1200
    -- The basic call information elements Bearer capability, High layer compatibility, Low
 
1201
    -- layer compatibity, Progress indicator and Party category can be embedded in the
 
1202
    -- pSS1InfoElement in accordance with 6.5.3.1.5
 
1203
    lastReroutingNr [1] PresentedNumberUnscreened,
 
1204
    subscriptionOption [2] IMPLICIT SubscriptionOption,
 
1205
 
 
1206
    callingPartySubaddress [3] PartySubaddress OPTIONAL,
 
1207
 
 
1208
    callingNumber [4] PresentedNumberScreened,
 
1209
 
 
1210
    callingName [5] Name OPTIONAL,
 
1211
    originalCalledNr [6] PresentedNumberUnscreened OPTIONAL,
 
1212
    redirectingName [7] Name OPTIONAL,
 
1213
    originalCalledName [8] Name OPTIONAL,
 
1214
    extension CHOICE {
 
1215
      [9] IMPLICIT Extension ,
 
1216
      [10] IMPLICIT SEQUENCE OF Extension } OPTIONAL }
 
1217
*/
 
1218
 
 
1219
        int i = 0, j;
 
1220
        int res = 0;
 
1221
        unsigned char buffer[255] = "";
 
1222
        int len = 253;
 
1223
        struct rose_component *comp = NULL, *compstk[10];
 
1224
        int compsp = 0;
 
1225
        static unsigned char op_tag[] = {
 
1226
                0x13,
 
1227
        };
 
1228
 
 
1229
        buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
 
1230
        /* Interpretation component */
 
1231
 
 
1232
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_NFE, buffer, i);
 
1233
        ASN1_PUSH(compstk, compsp, comp);
 
1234
        ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0), buffer, i, 0);
 
1235
        ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i, 0);
 
1236
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1237
 
 
1238
        ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 2);    /* reject - to get feedback from QSIG switch */
 
1239
 
 
1240
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
 
1241
        ASN1_PUSH(compstk, compsp, comp);
 
1242
 
 
1243
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
 
1244
 
 
1245
        res = asn1_string_encode(ASN1_INTEGER, &buffer[i], sizeof(buffer)-i, sizeof(op_tag), op_tag, sizeof(op_tag));
 
1246
        if (res < 0)
 
1247
                return -1;
 
1248
        i += res;
 
1249
 
 
1250
        /* call rerouting argument */
 
1251
        ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE), buffer, i);
 
1252
        ASN1_PUSH(compstk, compsp, comp);
 
1253
 
 
1254
        /* reroutingReason DiversionReason */
 
1255
 
 
1256
        if (reason) {
 
1257
                if (!strcasecmp(reason, "cfu"))
 
1258
                        ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 1); /* cfu */
 
1259
                else if (!strcasecmp(reason, "cfb"))
 
1260
                         ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 2); /* cfb */
 
1261
                else if (!strcasecmp(reason, "cfnr"))
 
1262
                        ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 3); /* cfnr */
 
1263
        } else {
 
1264
                ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 0); /* unknown */
 
1265
        }
 
1266
 
 
1267
 
 
1268
        /* calledAddress Address */
 
1269
        /* explicit sequence tag for Address */
 
1270
        ASN1_ADD_SIMPLE(comp, (ASN1_CONSTRUCTOR | ASN1_SEQUENCE), buffer, i);
 
1271
        ASN1_PUSH(compstk, compsp, comp);
 
1272
        /* implicit choice public party number tag */
 
1273
        ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1), buffer, i);
 
1274
        ASN1_PUSH(compstk, compsp, comp);
 
1275
        /* type of public party number = unknown */
 
1276
        ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 0);
 
1277
        /* NumberDigits of public party number */
 
1278
        j = asn1_string_encode(ASN1_NUMERICSTRING, &buffer[i], len - i, 20, (char*)dest, strlen(dest));
 
1279
        if (j < 0)
 
1280
                return -1;
 
1281
 
 
1282
        i += j;
 
1283
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1284
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1285
 
 
1286
        /* diversionCounter INTEGER (1..15) */
 
1287
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, 1);
 
1288
 
 
1289
        /* pSS1InfoElement */
 
1290
        ASN1_ADD_SIMPLE(comp, (ASN1_APPLICATION | ASN1_TAG_0 ), buffer, i);
 
1291
        ASN1_PUSH(compstk, compsp, comp);
 
1292
        buffer[i++] = (0x04); /*  add BC */
 
1293
        buffer[i++] = (0x03);
 
1294
        buffer[i++] = (0x80);
 
1295
        buffer[i++] = (0x90);
 
1296
        buffer[i++] = (0xa3);
 
1297
        buffer[i++] = (0x95);
 
1298
        buffer[i++] = (0x32);
 
1299
        buffer[i++] = (0x01);
 
1300
        buffer[i++] = (0x81);
 
1301
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1302
 
 
1303
        /* lastReroutingNr [1]*/
 
1304
        /* implicit optional lastReroutingNr tag */
 
1305
        ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1), buffer, i);
 
1306
        ASN1_PUSH(compstk, compsp, comp);
 
1307
 
 
1308
        /* implicit choice presented number unscreened tag */
 
1309
        ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0), buffer, i);
 
1310
        ASN1_PUSH(compstk, compsp, comp);
 
1311
 
 
1312
        /* implicit choice public party number  tag */
 
1313
        ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1), buffer, i);
 
1314
        ASN1_PUSH(compstk, compsp, comp);
 
1315
        /* type of public party number = unknown */
 
1316
        ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 0);
 
1317
        j = asn1_string_encode(ASN1_NUMERICSTRING, &buffer[i], len - i, 20, original?(char*)original:c->callednum, original?strlen(original):strlen(c->callednum));
 
1318
        if (j < 0)
 
1319
                return -1;
 
1320
 
 
1321
        i += j;
 
1322
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1323
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1324
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1325
 
 
1326
        /* subscriptionOption [2]*/
 
1327
        /* implicit optional lastReroutingNr tag */
 
1328
        ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i, 0);     /* noNotification */
 
1329
 
 
1330
        /* callingNumber [4]*/
 
1331
        /* implicit optional callingNumber tag */
 
1332
        ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_4), buffer, i);
 
1333
        ASN1_PUSH(compstk, compsp, comp);
 
1334
 
 
1335
        /* implicit choice presented number screened tag */
 
1336
        ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0), buffer, i);
 
1337
        ASN1_PUSH(compstk, compsp, comp);
 
1338
 
 
1339
        /* implicit choice presentationAllowedAddress tag */
 
1340
        ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1), buffer, i);
 
1341
        ASN1_PUSH(compstk, compsp, comp);
 
1342
        /* type of public party number = subscriber number */
 
1343
        ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 4);
 
1344
        j = asn1_string_encode(ASN1_NUMERICSTRING, &buffer[i], len - i, 20, c->callernum, strlen(c->callernum));
 
1345
        if (j < 0)
 
1346
                return -1;
 
1347
 
 
1348
        i += j;
 
1349
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1350
 
 
1351
        /* Screeening Indicator network provided */
 
1352
        ASN1_ADD_BYTECOMP(comp, ASN1_ENUMERATED, buffer, i, 3);
 
1353
 
 
1354
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1355
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1356
 
 
1357
        /**/
 
1358
 
 
1359
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1360
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1361
 
 
1362
        res = pri_call_apdu_queue(c, Q931_FACILITY, buffer, i, NULL, NULL);
 
1363
        if (res) {
 
1364
                pri_message(pri, "Could not queue ADPU in facility message\n");
 
1365
                return -1;
 
1366
        }
 
1367
 
 
1368
        /* Remember that if we queue a facility IE for a facility message we
 
1369
         * have to explicitly send the facility message ourselves */
 
1370
 
 
1371
        res = q931_facility(c->pri, c);
 
1372
        if (res) {
 
1373
                pri_message(pri, "Could not schedule facility message for call %d\n", c->cr);
 
1374
                return -1;
 
1375
        }
 
1376
 
 
1377
        return 0;
 
1378
}
 
1379
/* End QSIG CC-CallRerouting */
 
1380
 
 
1381
static int anfpr_pathreplacement_respond(struct pri *pri, q931_call *call, q931_ie *ie)
 
1382
{
 
1383
        int res;
 
1384
        
 
1385
        res = pri_call_apdu_queue_cleanup(call->bridged_call);
 
1386
        if (res) {
 
1387
                pri_message(pri, "Could not Clear queue ADPU\n");
 
1388
                return -1;
 
1389
        }
 
1390
        
 
1391
        /* Send message */
 
1392
        res = pri_call_apdu_queue(call->bridged_call, Q931_FACILITY, ie->data, ie->len, NULL, NULL);
 
1393
        if (res) {
 
1394
                pri_message(pri, "Could not queue ADPU in facility message\n");
 
1395
                return -1;
 
1396
        }
 
1397
        
 
1398
        /* Remember that if we queue a facility IE for a facility message we
 
1399
         * have to explicitly send the facility message ourselves */
 
1400
        
 
1401
        res = q931_facility(call->bridged_call->pri, call->bridged_call);
 
1402
        if (res) {
 
1403
                pri_message(pri, "Could not schedule facility message for call %d\n", call->bridged_call->cr);
 
1404
                return -1;
 
1405
        }
 
1406
 
 
1407
        return 0;
 
1408
}
 
1409
/* AFN-PR */
 
1410
int anfpr_initiate_transfer(struct pri *pri, q931_call *c1, q931_call *c2)
 
1411
{
 
1412
        /* Did all the tests to see if we're on the same PRI and
 
1413
         * are on a compatible switchtype */
 
1414
        /* TODO */
 
1415
        int i = 0;
 
1416
        int res = 0;
 
1417
        unsigned char buffer[255] = "";
 
1418
        unsigned short call_reference = c2->cr;
 
1419
        struct rose_component *comp = NULL, *compstk[10];
 
1420
        unsigned char buffer2[255] = "";
 
1421
        int compsp = 0;
 
1422
        static unsigned char op_tag[] = {
 
1423
                0x0C,
 
1424
        };
 
1425
        
 
1426
        /* Channel 1 */
 
1427
        buffer[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
 
1428
        /* Interpretation component */
 
1429
        
 
1430
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_NFE, buffer, i);
 
1431
        ASN1_PUSH(compstk, compsp, comp);
 
1432
        ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0), buffer, i, 0);
 
1433
        ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i, 0);
 
1434
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1435
        
 
1436
        ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer, i, 2);    /* reject - to get feedback from QSIG switch */
 
1437
        
 
1438
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer, i);
 
1439
        ASN1_PUSH(compstk, compsp, comp);
 
1440
        
 
1441
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer, i, get_invokeid(pri));
 
1442
        
 
1443
        res = asn1_string_encode(ASN1_INTEGER, &buffer[i], sizeof(buffer)-i, sizeof(op_tag), op_tag, sizeof(op_tag));
 
1444
        if (res < 0)
 
1445
                return -1;
 
1446
        i += res;
 
1447
        
 
1448
        ASN1_ADD_SIMPLE(comp, (ASN1_SEQUENCE | ASN1_CONSTRUCTOR), buffer, i);
 
1449
        ASN1_PUSH(compstk, compsp, comp);
 
1450
        buffer[i++] = (0x0a);
 
1451
        buffer[i++] = (0x01);
 
1452
        buffer[i++] = (0x00);
 
1453
        buffer[i++] = (0x81);
 
1454
        buffer[i++] = (0x00);
 
1455
        buffer[i++] = (0x0a);
 
1456
        buffer[i++] = (0x01);
 
1457
        buffer[i++] = (0x01);
 
1458
        ASN1_ADD_WORDCOMP(comp, ASN1_INTEGER, buffer, i, call_reference);
 
1459
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1460
        ASN1_FIXUP(compstk, compsp, buffer, i);
 
1461
        
 
1462
        res = pri_call_apdu_queue(c1, Q931_FACILITY, buffer, i, NULL, NULL);
 
1463
        if (res) {
 
1464
                pri_message(pri, "Could not queue ADPU in facility message\n");
 
1465
                return -1;
 
1466
        }
 
1467
        
 
1468
        /* Remember that if we queue a facility IE for a facility message we
 
1469
         * have to explicitly send the facility message ourselves */
 
1470
        
 
1471
        res = q931_facility(c1->pri, c1);
 
1472
        if (res) {
 
1473
                pri_message(pri, "Could not schedule facility message for call %d\n", c1->cr);
 
1474
                return -1;
 
1475
        }
 
1476
        
 
1477
        /* Channel 2 */
 
1478
        i = 0;
 
1479
        res = 0;
 
1480
        compsp = 0;
 
1481
        
 
1482
        buffer2[i++] = (ASN1_CONTEXT_SPECIFIC | Q932_PROTOCOL_EXTENSIONS);
 
1483
        /* Interpretation component */
 
1484
        
 
1485
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_NFE, buffer2, i);
 
1486
        ASN1_PUSH(compstk, compsp, comp);
 
1487
        ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_0), buffer2, i, 0);
 
1488
        ASN1_ADD_BYTECOMP(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer2, i, 0);
 
1489
        ASN1_FIXUP(compstk, compsp, buffer2, i);
 
1490
        
 
1491
        ASN1_ADD_BYTECOMP(comp, COMP_TYPE_INTERPRETATION, buffer2, i, 2);  /* reject */
 
1492
        
 
1493
        ASN1_ADD_SIMPLE(comp, COMP_TYPE_INVOKE, buffer2, i);
 
1494
        ASN1_PUSH(compstk, compsp, comp);
 
1495
        
 
1496
        ASN1_ADD_BYTECOMP(comp, ASN1_INTEGER, buffer2, i, get_invokeid(pri));
 
1497
        
 
1498
        res = asn1_string_encode(ASN1_INTEGER, &buffer2[i], sizeof(buffer2)-i, sizeof(op_tag), op_tag, sizeof(op_tag));
 
1499
        if (res < 0)
 
1500
                return -1;
 
1501
        i += res;
 
1502
        
 
1503
        ASN1_ADD_SIMPLE(comp, (ASN1_SEQUENCE | ASN1_CONSTRUCTOR), buffer2, i);
 
1504
        ASN1_PUSH(compstk, compsp, comp);
 
1505
        buffer2[i++] = (0x0a);
 
1506
        buffer2[i++] = (0x01);
 
1507
        buffer2[i++] = (0x01);
 
1508
        buffer2[i++] = (0x81);
 
1509
        buffer2[i++] = (0x00);
 
1510
        buffer2[i++] = (0x0a);
 
1511
        buffer2[i++] = (0x01);
 
1512
        buffer2[i++] = (0x01);
 
1513
        ASN1_ADD_WORDCOMP(comp, ASN1_INTEGER, buffer2, i, call_reference);
 
1514
        ASN1_FIXUP(compstk, compsp, buffer2, i);
 
1515
        ASN1_FIXUP(compstk, compsp, buffer2, i);
 
1516
        
 
1517
        
 
1518
        res = pri_call_apdu_queue(c2, Q931_FACILITY, buffer2, i, NULL, NULL);
 
1519
        if (res) {
 
1520
                pri_message(pri, "Could not queue ADPU in facility message\n");
 
1521
                return -1;
 
1522
        }
 
1523
        
 
1524
        /* Remember that if we queue a facility IE for a facility message we
 
1525
         * have to explicitly send the facility message ourselves */
 
1526
        
 
1527
        res = q931_facility(c2->pri, c2);
 
1528
        if (res) {
 
1529
                pri_message(pri, "Could not schedule facility message for call %d\n", c1->cr);
 
1530
                return -1;
 
1531
        }
 
1532
        
 
1533
        return 0;
 
1534
}
 
1535
/* End AFN-PR */
 
1536
 
1137
1537
/* AOC */
1138
1538
static int aoc_aoce_charging_request_decode(struct pri *pri, q931_call *call, unsigned char *data, int len) 
1139
1539
{
1340
1740
}
1341
1741
/* End AOC */
1342
1742
 
1343
 
int rose_reject_decode(struct pri *pri, q931_call *call, unsigned char *data, int len)
 
1743
static int rose_calling_name_decode(struct pri *pri, q931_call *call, struct rose_component *choice, int len)
 
1744
{
 
1745
        int i = 0;
 
1746
        struct rose_component *comp = NULL;
 
1747
        unsigned char *vdata = choice->data;
 
1748
        int characterSet = 1;
 
1749
        switch (choice->type) {
 
1750
                case ROSE_NAME_PRESENTATION_ALLOWED_SIMPLE:
 
1751
                        memcpy(call->callername, choice->data, choice->len);
 
1752
                        call->callername[choice->len] = 0;
 
1753
                        if (pri->debug & PRI_DEBUG_APDU)
 
1754
                                pri_message(pri, "    Received simple calling name '%s'\n", call->callername);
 
1755
                        return 0;
 
1756
 
 
1757
                case ROSE_NAME_PRESENTATION_ALLOWED_EXTENDED:
 
1758
                        do {
 
1759
                                GET_COMPONENT(comp, i, vdata, len);
 
1760
                                CHECK_COMPONENT(comp, ASN1_OCTETSTRING, "Don't know what to do if nameData is of type 0x%x\n");
 
1761
                                memcpy(call->callername, comp->data, comp->len);
 
1762
                                call->callername[comp->len] = 0;
 
1763
                                NEXT_COMPONENT(comp, i);
 
1764
 
 
1765
                                GET_COMPONENT(comp, i, vdata, len);
 
1766
                                CHECK_COMPONENT(comp, ASN1_INTEGER, "Don't know what to do if CharacterSet is of type 0x%x\n");
 
1767
                                ASN1_GET_INTEGER(comp, characterSet);
 
1768
                        }
 
1769
                        while (0);
 
1770
 
 
1771
                        if (pri->debug & PRI_DEBUG_APDU)
 
1772
                                pri_message(pri, "    Received extended calling name '%s', characterset %d\n", call->callername, characterSet);
 
1773
                        return 0;
 
1774
                case ROSE_NAME_PRESENTATION_RESTRICTED_SIMPLE:
 
1775
                case ROSE_NAME_PRESENTATION_RESTRICTED_EXTENDED:
 
1776
                case ROSE_NAME_PRESENTATION_RESTRICTED_NULL:
 
1777
                case ROSE_NAME_NOT_AVAIL:
 
1778
                default:
 
1779
                        if (pri->debug & PRI_DEBUG_APDU)
 
1780
                                pri_message(pri, "Do not handle argument of type 0x%X\n", choice->type);
 
1781
                        return -1;
 
1782
        }
 
1783
}
 
1784
/* ===== Call Transfer Supplementary Service (ECMA-178) ===== */
 
1785
 
 
1786
static int rose_party_number_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberunscreened *value)
 
1787
{
 
1788
        int i = 0;
 
1789
        int size = 0;
 
1790
        struct rose_component *comp = NULL;
 
1791
        unsigned char *vdata = data;
 
1792
 
 
1793
 
 
1794
        do {
 
1795
                GET_COMPONENT(comp, i, vdata, len);
 
1796
 
 
1797
                switch(comp->type) {
 
1798
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0):   /* [0] IMPLICIT NumberDigits -- default: unknownPartyNumber */
 
1799
                                if (pri->debug & PRI_DEBUG_APDU)
 
1800
                                        pri_message(pri, "     PartyNumber: UnknownPartyNumber len=%d\n", len);
 
1801
                                size = rose_number_digits_decode(pri, call, comp->data, comp->len, value);
 
1802
                                if (size < 0)
 
1803
                                        return -1;
 
1804
                                value->npi = PRI_NPI_UNKNOWN;
 
1805
                                value->ton = PRI_TON_UNKNOWN;
 
1806
                                break;
 
1807
 
 
1808
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_1):   /* [1] IMPLICIT PublicPartyNumber */
 
1809
                                if (pri->debug & PRI_DEBUG_APDU)
 
1810
                                        pri_message(pri, "     PartyNumber: PublicPartyNumber len=%d\n", len);
 
1811
                                size = rose_public_party_number_decode(pri, call, comp->data, comp->len, value);
 
1812
                                if (size < 0)
 
1813
                                        return -1;
 
1814
                                value->npi = PRI_NPI_E163_E164;
 
1815
                                break;
 
1816
 
 
1817
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_3):   /* [3] IMPLICIT NumberDigits -- not used: dataPartyNumber */
 
1818
                                pri_message(pri, "!! PartyNumber: dataPartyNumber is reserved!\n");
 
1819
                                size = rose_number_digits_decode(pri, call, comp->data, comp->len, value);
 
1820
                                if (size < 0)
 
1821
                                        return -1;
 
1822
                                value->npi = PRI_NPI_X121 /* ??? */;
 
1823
                                value->ton = PRI_TON_UNKNOWN /* ??? */;
 
1824
                                break;
 
1825
 
 
1826
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_4):   /* [4] IMPLICIT NumberDigits -- not used: telexPartyNumber */
 
1827
                                pri_message(pri, "!! PartyNumber: telexPartyNumber is reserved!\n");
 
1828
                                size = rose_number_digits_decode(pri, call, comp->data, comp->len, value);
 
1829
                                if (size < 0)
 
1830
                                        return -1;
 
1831
                                value->npi = PRI_NPI_F69 /* ??? */;
 
1832
                                value->ton = PRI_TON_UNKNOWN /* ??? */;
 
1833
                                break;
 
1834
 
 
1835
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_5):   /* [5] IMPLICIT PrivatePartyNumber */
 
1836
                                if (pri->debug & PRI_DEBUG_APDU)
 
1837
                                        pri_message(pri, "     PartyNumber: PrivatePartyNumber len=%d\n", len);
 
1838
                                size = rose_private_party_number_decode(pri, call, comp->data, comp->len, value);
 
1839
                                if (size < 0)
 
1840
                                        return -1;
 
1841
                                value->npi = PRI_NPI_PRIVATE;
 
1842
                                break;
 
1843
 
 
1844
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_8):   /* [8] IMPLICIT NumberDigits -- not used: nationalStandatdPartyNumber */
 
1845
                                pri_message(pri, "!! PartyNumber: nationalStandardPartyNumber is reserved!\n");
 
1846
                                size = rose_number_digits_decode(pri, call, comp->data, comp->len, value);
 
1847
                                if (size < 0)
 
1848
                                        return -1;
 
1849
                                value->npi = PRI_NPI_NATIONAL;
 
1850
                                value->ton = PRI_TON_NATIONAL;
 
1851
                                break;
 
1852
 
 
1853
                        default:
 
1854
                                pri_message(pri, "Invalid PartyNumber component 0x%X\n", comp->type);
 
1855
                                return -1;
 
1856
                }
 
1857
                ASN1_FIXUP_LEN(comp, size);
 
1858
                if (pri->debug & PRI_DEBUG_APDU)
 
1859
                        pri_message(pri, "     PartyNumber: '%s' size=%d len=%d\n", value->partyaddress, size, len);
 
1860
                return size;
 
1861
        }
 
1862
        while (0);
 
1863
 
 
1864
        return -1;
 
1865
}
 
1866
 
 
1867
 
 
1868
static int rose_number_screened_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberscreened *value)
 
1869
{
 
1870
        int i = 0;
 
1871
        int size = 0;
 
1872
        struct rose_component *comp = NULL;
 
1873
        unsigned char *vdata = data;
 
1874
 
 
1875
        int scrind = -1;
 
1876
 
 
1877
        do {
 
1878
                /* Party Number */
 
1879
                GET_COMPONENT(comp, i, vdata, len);
 
1880
                size = rose_party_number_decode(pri, call, (u_int8_t *)comp, comp->len + 2, (struct addressingdataelements_presentednumberunscreened*) value);
 
1881
                if (size < 0)
 
1882
                        return -1;
 
1883
                comp->len = size;
 
1884
                NEXT_COMPONENT(comp, i);
 
1885
 
 
1886
                /* Screening Indicator */
 
1887
                GET_COMPONENT(comp, i, vdata, len);
 
1888
                CHECK_COMPONENT(comp, ASN1_ENUMERATED, "Don't know what to do with NumberScreened ROSE component type 0x%x\n");
 
1889
                ASN1_GET_INTEGER(comp, scrind);
 
1890
                // Todo: scrind = screeningindicator_for_q931(pri, scrind);
 
1891
                NEXT_COMPONENT(comp, i);
 
1892
 
 
1893
                value->scrind = scrind;
 
1894
 
 
1895
                if (pri->debug & PRI_DEBUG_APDU)
 
1896
                        pri_message(pri, "     NumberScreened: '%s' ScreeningIndicator=%d  i=%d  len=%d\n", value->partyaddress, scrind, i, len);
 
1897
 
 
1898
                return i-2;  // We do not have a sequence header here.
 
1899
        }
 
1900
        while (0);
 
1901
 
 
1902
        return -1;
 
1903
}
 
1904
 
 
1905
 
 
1906
static int rose_presented_number_screened_decode(struct pri *pri, q931_call *call, unsigned char *data, int len, struct addressingdataelements_presentednumberscreened *value)
 
1907
{
 
1908
        int i = 0;
 
1909
        int size = 0;
 
1910
        struct rose_component *comp = NULL;
 
1911
        unsigned char *vdata = data;
 
1912
 
 
1913
        /* Fill in default values */
 
1914
        value->ton = PRI_TON_UNKNOWN;
 
1915
        value->npi = PRI_NPI_UNKNOWN;
 
1916
        value->pres = -1; /* Data is not available */
 
1917
 
 
1918
        do {
 
1919
                GET_COMPONENT(comp, i, vdata, len);
 
1920
 
 
1921
                switch(comp->type) {
 
1922
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0):   /* [0] IMPLICIT presentationAllowedNumber */
 
1923
                                if (pri->debug & PRI_DEBUG_APDU)
 
1924
                                        pri_message(pri, "     PresentedNumberScreened: presentationAllowedNumber comp->len=%d\n", comp->len);
 
1925
                                value->pres = PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
 
1926
                                size = rose_number_screened_decode(pri, call, comp->data, comp->len, value);
 
1927
                                if (size < 0)
 
1928
                                        return -1;
 
1929
                                ASN1_FIXUP_LEN(comp, size);
 
1930
                                return size + 2;
 
1931
 
 
1932
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1):    /* [1] IMPLICIT presentationRestricted */
 
1933
                                if (pri->debug & PRI_DEBUG_APDU)
 
1934
                                        pri_message(pri, "     PresentedNumberScreened: presentationRestricted comp->len=%d\n", comp->len);
 
1935
                                if (comp->len != 0) { /* must be NULL */
 
1936
                                        pri_error(pri, "!! Invalid PresentationRestricted component received (len != 0)\n");
 
1937
                                        return -1;
 
1938
                                }
 
1939
                                value->pres = PRES_PROHIB_USER_NUMBER_PASSED_SCREEN;
 
1940
                                return 2;
 
1941
 
 
1942
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2):    /* [2] IMPLICIT numberNotAvailableDueToInterworking */
 
1943
                                if (pri->debug & PRI_DEBUG_APDU)
 
1944
                                        pri_message(pri, "     PresentedNumberScreened: NumberNotAvailableDueToInterworking comp->len=%d\n", comp->len);
 
1945
                                if (comp->len != 0) { /* must be NULL */
 
1946
                                        pri_error(pri, "!! Invalid NumberNotAvailableDueToInterworking component received (len != 0)\n");
 
1947
                                        return -1;
 
1948
                                }
 
1949
                                value->pres = PRES_NUMBER_NOT_AVAILABLE;
 
1950
                                if (pri->debug & PRI_DEBUG_APDU)
 
1951
                                        pri_message(pri, "     PresentedNumberScreened: numberNotAvailableDueToInterworking Type=0x%X  i=%d len=%d size=%d\n", comp->type, i, len);
 
1952
                                return 2;
 
1953
 
 
1954
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_3):    /* [3] IMPLICIT presentationRestrictedNumber */
 
1955
                                if (pri->debug & PRI_DEBUG_APDU)
 
1956
                                        pri_message(pri, "     PresentedNumberScreened: presentationRestrictedNumber comp->len=%d\n", comp->len);
 
1957
                                value->pres = PRES_PROHIB_USER_NUMBER_PASSED_SCREEN;
 
1958
                                size = rose_number_screened_decode(pri, call, comp->data, comp->len, value);
 
1959
                                if (size < 0)
 
1960
                                        return -1;
 
1961
                                ASN1_FIXUP_LEN(comp, size);
 
1962
                                return size + 2;
 
1963
 
 
1964
                        default:
 
1965
                                pri_message(pri, "Invalid PresentedNumberScreened component 0x%X\n", comp->type);
 
1966
                }
 
1967
                return -1;
 
1968
        }
 
1969
        while (0);
 
1970
 
 
1971
        return -1;
 
1972
}
 
1973
 
 
1974
 
 
1975
static int rose_call_transfer_complete_decode(struct pri *pri, q931_call *call, struct rose_component *sequence, int len)
 
1976
{
 
1977
        int i = 0;
 
1978
        struct rose_component *comp = NULL;
 
1979
        unsigned char *vdata = sequence->data;
 
1980
        int res = 0;
 
1981
 
 
1982
        int end_designation = 0;
 
1983
        struct addressingdataelements_presentednumberscreened redirection_number;
 
1984
        char redirection_name[50] = "";
 
1985
        int call_status = 0;
 
1986
        redirection_number.partyaddress[0] = 0;
 
1987
        redirection_number.partysubaddress[0] = 0;
 
1988
        call->callername[0] = 0;
 
1989
        call->callernum[0] = 0;
 
1990
 
 
1991
 
 
1992
        /* Data checks */
 
1993
        if (sequence->type != (ASN1_CONSTRUCTOR | ASN1_SEQUENCE)) { /* Constructed Sequence */
 
1994
                pri_message(pri, "Invalid callTransferComplete argument. (Not a sequence)\n");
 
1995
                return -1;
 
1996
        }
 
1997
 
 
1998
        if (sequence->len == ASN1_LEN_INDEF) {
 
1999
                len -= 4; /* For the 2 extra characters at the end
 
2000
                                           * and two characters of header */
 
2001
        } else
 
2002
                len -= 2;
 
2003
 
 
2004
        if (pri->debug & PRI_DEBUG_APDU)
 
2005
                pri_message(pri, "     CT-Complete: len=%d\n", len);
 
2006
 
 
2007
        do {
 
2008
                /* End Designation */
 
2009
                GET_COMPONENT(comp, i, vdata, len);
 
2010
                CHECK_COMPONENT(comp, ASN1_ENUMERATED, "Invalid endDesignation type 0x%X of ROSE callTransferComplete component received\n");
 
2011
                ASN1_GET_INTEGER(comp, end_designation);
 
2012
                NEXT_COMPONENT(comp, i);
 
2013
                if (pri->debug & PRI_DEBUG_APDU)
 
2014
                        pri_message(pri, "     CT-Complete: Received endDesignation=%d\n", end_designation);
 
2015
 
 
2016
 
 
2017
                /* Redirection Number */
 
2018
                GET_COMPONENT(comp, i, vdata, len);
 
2019
                res = rose_presented_number_screened_decode(pri, call, (u_int8_t *)comp, comp->len + 2, &redirection_number);
 
2020
                if (res < 0)
 
2021
                        return -1;
 
2022
                comp->len = res;
 
2023
                if (res > 2) {
 
2024
                        if (pri->debug & PRI_DEBUG_APDU)
 
2025
                                pri_message(pri, "     CT-Complete: Received redirectionNumber=%s\n", redirection_number.partyaddress);
 
2026
                        strncpy(call->callernum, redirection_number.partyaddress, 20);
 
2027
                        call->callernum[20] = 0;
 
2028
                }
 
2029
                NEXT_COMPONENT(comp, i);
 
2030
 
 
2031
 
 
2032
#if 0 /* This one is optional. How do we check if it is there? */
 
2033
                /* Basic Call Info Elements */
 
2034
                GET_COMPONENT(comp, i, vdata, len);
 
2035
                NEXT_COMPONENT(comp, i);
 
2036
#endif
 
2037
 
 
2038
 
 
2039
                /* Redirection Name */
 
2040
                GET_COMPONENT(comp, i, vdata, len);
 
2041
                res = asn1_name_decode((u_int8_t *)comp, comp->len + 2, redirection_name, sizeof(redirection_name));
 
2042
                if (res < 0)
 
2043
                        return -1;
 
2044
                memcpy(call->callername, comp->data, comp->len);
 
2045
                call->callername[comp->len] = 0;
 
2046
                ASN1_FIXUP_LEN(comp, res);
 
2047
                comp->len = res;
 
2048
                NEXT_COMPONENT(comp, i);
 
2049
                if (pri->debug & PRI_DEBUG_APDU)
 
2050
                        pri_message(pri, "     CT-Complete: Received redirectionName '%s'\n", redirection_name);
 
2051
 
 
2052
 
 
2053
                /* Call Status */
 
2054
                GET_COMPONENT(comp, i, vdata, len);
 
2055
                CHECK_COMPONENT(comp, ASN1_ENUMERATED, "Invalid callStatus type 0x%X of ROSE callTransferComplete component received\n");
 
2056
                ASN1_GET_INTEGER(comp, call_status);
 
2057
                NEXT_COMPONENT(comp, i);
 
2058
                if (pri->debug & PRI_DEBUG_APDU)
 
2059
                        pri_message(pri, "     CT-Complete: Received callStatus=%d\n", call_status);
 
2060
 
 
2061
 
 
2062
                /* Argument Extension */
 
2063
#if 0 /* Not supported */
 
2064
                GET_COMPONENT(comp, i, vdata, len);
 
2065
                switch (comp->type) {
 
2066
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_9):   /* [9] IMPLICIT Extension */
 
2067
                                res = rose_extension_decode(pri, call, comp->data, comp->len, &redirection_number);
 
2068
                                if (res < 0)
 
2069
                                        return -1;
 
2070
                                ASN1_FIXUP_LEN(comp, res);
 
2071
                                comp->len = res;
 
2072
 
 
2073
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_10):    /* [10] IMPLICIT SEQUENCE OF Extension */
 
2074
                                res = rose_sequence_of_extension_decode(pri, call, comp->data, comp->len, &redirection_number);
 
2075
                                if (res < 0)
 
2076
                                        return -1;
 
2077
                                ASN1_FIXUP_LEN(comp, res);
 
2078
                                comp->len = res;
 
2079
 
 
2080
                        default:
 
2081
                        pri_message(pri, "     CT-Complete: !! Unknown argumentExtension received 0x%X\n", comp->type);
 
2082
                        return -1;
 
2083
                }
 
2084
#else
 
2085
                GET_COMPONENT(comp, i, vdata, len);
 
2086
                ASN1_FIXUP_LEN(comp, res);
 
2087
                NEXT_COMPONENT(comp, i);
 
2088
#endif
 
2089
 
 
2090
                if(i < len)
 
2091
                        pri_message(pri, "     CT-Complete: !! not all information is handled !! i=%d / len=%d\n", i, len);
 
2092
 
 
2093
                return 0;
 
2094
        }
 
2095
        while (0);
 
2096
 
 
2097
        return -1;
 
2098
}
 
2099
 
 
2100
 
 
2101
static int rose_call_transfer_update_decode(struct pri *pri, q931_call *call, struct rose_component *sequence, int len)
 
2102
{
 
2103
        int i = 0;
 
2104
        struct rose_component *comp = NULL;
 
2105
        unsigned char *vdata = sequence->data;
 
2106
        int res = 0;
 
2107
 
 
2108
        struct addressingdataelements_presentednumberscreened redirection_number;
 
2109
        redirection_number.partyaddress[0] = 0;
 
2110
        redirection_number.partysubaddress[0] = 0;
 
2111
        char redirection_name[50] = "";
 
2112
        call->callername[0] = 0;
 
2113
        call->callernum[0] = 0;
 
2114
 
 
2115
 
 
2116
        /* Data checks */
 
2117
        if (sequence->type != (ASN1_CONSTRUCTOR | ASN1_SEQUENCE)) { /* Constructed Sequence */
 
2118
                pri_message(pri, "Invalid callTransferComplete argument. (Not a sequence)\n");
 
2119
                return -1;
 
2120
        }
 
2121
 
 
2122
        if (sequence->len == ASN1_LEN_INDEF) {
 
2123
                len -= 4; /* For the 2 extra characters at the end
 
2124
                                           * and two characters of header */
 
2125
        } else
 
2126
                len -= 2;
 
2127
 
 
2128
        if (pri->debug & PRI_DEBUG_APDU)
 
2129
                pri_message(pri, "     CT-Complete: len=%d\n", len);
 
2130
 
 
2131
        do {
 
2132
                /* Redirection Number */
 
2133
                GET_COMPONENT(comp, i, vdata, len);
 
2134
                res = rose_presented_number_screened_decode(pri, call, (u_int8_t *)comp, comp->len + 2, &redirection_number);
 
2135
                if (res < 0)
 
2136
                        return -1;
 
2137
                comp->len = res;
 
2138
                if (res > 2) {
 
2139
                        if (pri->debug & PRI_DEBUG_APDU)
 
2140
                                pri_message(pri, "     CT-Complete: Received redirectionNumber=%s\n", redirection_number.partyaddress);
 
2141
                        strncpy(call->callernum, redirection_number.partyaddress, 20);
 
2142
                        call->callernum[20] = 0;
 
2143
                }
 
2144
                NEXT_COMPONENT(comp, i);
 
2145
 
 
2146
                /* Redirection Name */
 
2147
                GET_COMPONENT(comp, i, vdata, len);
 
2148
                res = asn1_name_decode((u_int8_t *)comp, comp->len + 2, redirection_name, sizeof(redirection_name));
 
2149
                if (res < 0)
 
2150
                        return -1;
 
2151
                memcpy(call->callername, comp->data, comp->len);
 
2152
                call->callername[comp->len] = 0;
 
2153
                ASN1_FIXUP_LEN(comp, res);
 
2154
                comp->len = res;
 
2155
                NEXT_COMPONENT(comp, i);
 
2156
                if (pri->debug & PRI_DEBUG_APDU)
 
2157
                        pri_message(pri, "     CT-Complete: Received redirectionName '%s'\n", redirection_name);
 
2158
 
 
2159
 
 
2160
#if 0 /* This one is optional. How do we check if it is there? */
 
2161
                /* Basic Call Info Elements */
 
2162
                GET_COMPONENT(comp, i, vdata, len);
 
2163
                NEXT_COMPONENT(comp, i);
 
2164
#endif
 
2165
 
 
2166
 
 
2167
                /* Argument Extension */
 
2168
#if 0 /* Not supported */
 
2169
                GET_COMPONENT(comp, i, vdata, len);
 
2170
                switch (comp->type) {
 
2171
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_9):   /* [9] IMPLICIT Extension */
 
2172
                                res = rose_extension_decode(pri, call, comp->data, comp->len, &redirection_number);
 
2173
                                if (res < 0)
 
2174
                                        return -1;
 
2175
                                ASN1_FIXUP_LEN(comp, res);
 
2176
                                comp->len = res;
 
2177
 
 
2178
                        case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_10):    /* [10] IMPLICIT SEQUENCE OF Extension */
 
2179
                                res = rose_sequence_of_extension_decode(pri, call, comp->data, comp->len, &redirection_number);
 
2180
                                if (res < 0)
 
2181
                                        return -1;
 
2182
                                ASN1_FIXUP_LEN(comp, res);
 
2183
                                comp->len = res;
 
2184
 
 
2185
                        default:
 
2186
                                pri_message(pri, "     CT-Complete: !! Unknown argumentExtension received 0x%X\n", comp->type);
 
2187
                                return -1;
 
2188
                }
 
2189
#else
 
2190
                GET_COMPONENT(comp, i, vdata, len);
 
2191
                ASN1_FIXUP_LEN(comp, res);
 
2192
                NEXT_COMPONENT(comp, i);
 
2193
#endif
 
2194
 
 
2195
                if(i < len)
 
2196
                        pri_message(pri, "     CT-Complete: !! not all information is handled !! i=%d / len=%d\n", i, len);
 
2197
 
 
2198
                return 0;
 
2199
        }
 
2200
        while (0);
 
2201
 
 
2202
        return -1;
 
2203
}
 
2204
 
 
2205
 
 
2206
/* ===== End Call Transfer Supplementary Service (ECMA-178) ===== */
 
2207
 
 
2208
 
 
2209
 
 
2210
int rose_reject_decode(struct pri *pri, q931_call *call, q931_ie *ie, unsigned char *data, int len)
1344
2211
{
1345
2212
        int i = 0;
1346
2213
        int problemtag = -1;
1408
2275
        
1409
2276
        return -1;
1410
2277
}
1411
 
int rose_return_error_decode(struct pri *pri, q931_call *call, unsigned char *data, int len)
 
2278
int rose_return_error_decode(struct pri *pri, q931_call *call, q931_ie *ie, unsigned char *data, int len)
1412
2279
{
1413
2280
        int i = 0;
1414
2281
        int errorvalue = -1;
1472
2339
        return -1;
1473
2340
}
1474
2341
 
1475
 
int rose_return_result_decode(struct pri *pri, q931_call *call, unsigned char *data, int len)
 
2342
int rose_return_result_decode(struct pri *pri, q931_call *call, q931_ie *ie, unsigned char *data, int len)
1476
2343
{
1477
2344
        int i = 0;
1478
2345
        int operationidvalue = -1;
1524
2391
                                pri_message(pri, "Could not parse invoke of type 0x%x!\n", invokeidvalue);
1525
2392
                                return -1;
1526
2393
                        }
 
2394
                } else if (pri->switchtype == PRI_SWITCH_QSIG) {
 
2395
                        switch (invokeidvalue) {
 
2396
                        case 0x13:
 
2397
                                if (pri->debug & PRI_DEBUG_APDU) pri_message(pri, "Successfully completed QSIG CF callRerouting!\n");
 
2398
                                return 0;
 
2399
                        }
1527
2400
                } else {
1528
2401
                        pri_message(pri, "Unable to handle return result on switchtype %d!\n", pri->switchtype);
1529
2402
                        return -1;
1534
2407
        return -1;
1535
2408
}
1536
2409
 
1537
 
int rose_invoke_decode(struct pri *pri, q931_call *call, unsigned char *data, int len)
 
2410
int rose_invoke_decode(struct pri *pri, q931_call *call, q931_ie *ie, unsigned char *data, int len)
1538
2411
{
1539
2412
        int i = 0;
 
2413
        int res = 0;
1540
2414
        int operation_tag;
1541
2415
        unsigned char *vdata = data;
1542
2416
        struct rose_component *comp = NULL, *invokeid = NULL, *operationid = NULL;
1574
2448
                case SS_CNID_CALLINGNAME:
1575
2449
                        if (pri->debug & PRI_DEBUG_APDU)
1576
2450
                                pri_message(pri, "  Handle Name display operation\n");
1577
 
                        switch (comp->type) {
1578
 
                                case ROSE_NAME_PRESENTATION_ALLOWED_SIMPLE:
1579
 
                                        memcpy(call->callername, comp->data, comp->len);
1580
 
                                        call->callername[comp->len] = 0;
1581
 
                                        if (pri->debug & PRI_DEBUG_APDU)
1582
 
                                                pri_message(pri, "    Received caller name '%s'\n", call->callername);
1583
 
                                        return 0;
1584
 
                                default:
1585
 
                                        if (pri->debug & PRI_DEBUG_APDU)
1586
 
                                                pri_message(pri, "Do not handle argument of type 0x%X\n", comp->type);
1587
 
                                        return -1;
1588
 
                        }
1589
 
                        break;
 
2451
                        return rose_calling_name_decode(pri, call, comp, len-i);
 
2452
                case ROSE_CALL_TRANSFER_IDENTIFY:
 
2453
                        if (pri->debug & PRI_DEBUG_APDU)
 
2454
                                pri_message(pri, "ROSE %i:   CallTransferIdentify - not handled!\n", operation_tag);
 
2455
                        dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 
2456
                        return -1;
 
2457
                case ROSE_CALL_TRANSFER_ABANDON:
 
2458
                        if (pri->debug & PRI_DEBUG_APDU)
 
2459
                                pri_message(pri, "ROSE %i:   CallTransferAbandon - not handled!\n", operation_tag);
 
2460
                        dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 
2461
                        return -1;
 
2462
                case ROSE_CALL_TRANSFER_INITIATE:
 
2463
                        if (pri->debug & PRI_DEBUG_APDU)
 
2464
                                pri_message(pri, "ROSE %i:   CallTransferInitiate - not handled!\n", operation_tag);
 
2465
                        dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 
2466
                        return -1;
 
2467
                case ROSE_CALL_TRANSFER_SETUP:
 
2468
                        if (pri->debug & PRI_DEBUG_APDU)
 
2469
                                pri_message(pri, "ROSE %i:   CallTransferSetup - not handled!\n", operation_tag);
 
2470
                        dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 
2471
                        return -1;
 
2472
                case ROSE_CALL_TRANSFER_ACTIVE:
 
2473
                        if (pri->debug & PRI_DEBUG_APDU)
 
2474
                                pri_message(pri, "ROSE %i:   CallTransferActive - not handled!\n", operation_tag);
 
2475
                        dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 
2476
                        return -1;
 
2477
                case ROSE_CALL_TRANSFER_COMPLETE:
 
2478
                        if (pri->debug & PRI_DEBUG_APDU)
 
2479
                        {
 
2480
                                pri_message(pri, "ROSE %i:   Handle CallTransferComplete\n", operation_tag);
 
2481
                                dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 
2482
                        }
 
2483
                        return rose_call_transfer_complete_decode(pri, call, comp, len-i);
 
2484
                case ROSE_CALL_TRANSFER_UPDATE:
 
2485
                        if (pri->debug & PRI_DEBUG_APDU)
 
2486
                        {
 
2487
                                pri_message(pri, "ROSE %i:    Handle CallTransferUpdate\n", operation_tag);
 
2488
                                dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 
2489
                        }
 
2490
                        return rose_call_transfer_update_decode(pri, call, comp, len-i);
 
2491
                case ROSE_SUBADDRESS_TRANSFER:
 
2492
                        if (pri->debug & PRI_DEBUG_APDU)
 
2493
                                pri_message(pri, "ROSE %i:   SubaddressTransfer - not handled!\n", operation_tag);
 
2494
                        dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 
2495
                        return -1;
1590
2496
                case ROSE_DIVERTING_LEG_INFORMATION2:
1591
 
                        if (pri->debug & PRI_DEBUG_APDU)
1592
 
                                pri_message(pri, "  Handle DivertingLegInformation2\n");
 
2497
                        if (pri->debug & PRI_DEBUG_APDU) {
 
2498
                                pri_message(pri, "ROSE %i:   Handle CallingName\n", operation_tag);
 
2499
                                dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 
2500
                        }
1593
2501
                        return rose_diverting_leg_information2_decode(pri, call, comp, len-i);
1594
2502
                case ROSE_AOC_NO_CHARGING_INFO_AVAILABLE:
1595
2503
                        if (pri->debug & PRI_DEBUG_APDU) {
1641
2549
                                dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
1642
2550
                        }
1643
2551
                        return -1;
 
2552
                case SS_ANFPR_PATHREPLACEMENT:
 
2553
                        /* Clear Queue */
 
2554
                        res = pri_call_apdu_queue_cleanup(call->bridged_call);
 
2555
                        if (res) {
 
2556
                                pri_message(pri, "Could not Clear queue ADPU\n");
 
2557
                                return -1;
 
2558
                        }
 
2559
                        anfpr_pathreplacement_respond(pri, call, ie);
 
2560
                        break;
1644
2561
                default:
1645
2562
                        if (pri->debug & PRI_DEBUG_APDU) {
1646
2563
                                pri_message(pri, "!! Unable to handle ROSE operation %d", operation_tag);
1661
2578
        if (!call || !messagetype || !apdu || (apdu_len < 1) || (apdu_len > 255))
1662
2579
                return -1;
1663
2580
 
1664
 
        new_event = malloc(sizeof(struct apdu_event));
1665
 
 
1666
 
        if (new_event) {
1667
 
                memset(new_event, 0, sizeof(struct apdu_event));
1668
 
                new_event->message = messagetype;
1669
 
                new_event->callback = function;
1670
 
                new_event->data = data;
1671
 
                memcpy(new_event->apdu, apdu, apdu_len);
1672
 
                new_event->apdu_len = apdu_len;
1673
 
        } else {
 
2581
        if (!(new_event = calloc(1, sizeof(*new_event)))) {
1674
2582
                pri_error(call->pri, "!! Malloc failed!\n");
1675
2583
                return -1;
1676
2584
        }
 
2585
 
 
2586
        new_event->message = messagetype;
 
2587
        new_event->callback = function;
 
2588
        new_event->data = data;
 
2589
        memcpy(new_event->apdu, apdu, apdu_len);
 
2590
        new_event->apdu_len = apdu_len;
1677
2591
        
1678
2592
        if (call->apdus) {
1679
2593
                cur = call->apdus;