OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [before_ORP/] [uclinux/] [uClinux-2.0.x/] [drivers/] [isdn/] [avmb1/] [capiutil.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 * $Id: capiutil.c,v 1.1.1.1 2001-09-10 07:44:18 simons Exp $
3
 *
4
 * CAPI 2.0 convert capi message to capi message struct
5
 *
6
 * From CAPI 2.0 Development Kit AVM 1995 (msg.c)
7
 * Rewritten for Linux 1996 by Carsten Paeth (calle@calle.in-berlin.de)
8
 *
9
 * $Log: not supported by cvs2svn $
10
 * Revision 1.1.1.1  2001/07/02 17:58:32  simons
11
 * Initial revision
12
 *
13
 * Revision 1.3.2.1  1998/08/03 15:52:21  paul
14
 * various changes from 2.0.3[45] kernel sources, as suggested by
15
 * Oliver.Lauer@coburg.baynet.de
16
 *
17
 * Revision 1.3  1997/05/18 09:24:18  calle
18
 * added verbose disconnect reason reporting to avmb1.
19
 * some fixes in capi20 interface.
20
 * changed info messages for B1-PCI
21
 *
22
 * Revision 1.2  1997/03/05 21:22:13  fritz
23
 * Fix: Symbols have to be exported unconditionally.
24
 *
25
 * Revision 1.1  1997/03/04 21:50:34  calle
26
 * Frirst version in isdn4linux
27
 *
28
 * Revision 2.2  1997/02/12 09:31:39  calle
29
 * new version
30
 *
31
 * Revision 1.1  1997/01/31 10:32:20  calle
32
 * Initial revision
33
 *
34
 */
35
#include <linux/config.h> /* CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON */
36
#include <linux/module.h>
37
#include <linux/string.h>
38
#include <linux/ctype.h>
39
#include <linux/stddef.h>
40
#include <linux/kernel.h>
41
#include <linux/mm.h>
42
#include <asm/segment.h>
43
 
44
#include "compat.h"
45
#include "capiutil.h"
46
 
47
/* from CAPI2.0 DDK AVM Berlin GmbH */
48
 
49
#ifndef CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON
50
char *capi_info2str(__u16 reason)
51
{
52
    return "..";
53
}
54
#else
55
char *capi_info2str(__u16 reason)
56
{
57
    switch (reason) {
58
 
59
/*-- informative values (corresponding message was processed) -----*/
60
        case 0x0001:
61
           return "NCPI not supported by current protocol, NCPI ignored";
62
        case 0x0002:
63
           return "Flags not supported by current protocol, flags ignored";
64
        case 0x0003:
65
           return "Alert already sent by another application";
66
 
67
/*-- error information concerning CAPI_REGISTER -----*/
68
        case 0x1001:
69
           return "Too many applications";
70
        case 0x1002:
71
           return "Logical block size to small, must be at least 128 Bytes";
72
        case 0x1003:
73
           return "Buffer exceeds 64 kByte";
74
        case 0x1004:
75
           return "Message buffer size too small, must be at least 1024 Bytes";
76
        case 0x1005:
77
           return "Max. number of logical connections not supported";
78
        case 0x1006:
79
           return "Reserved";
80
        case 0x1007:
81
           return "The message could not be accepted because of an internal busy condition";
82
        case 0x1008:
83
           return "OS resource error (no memory ?)";
84
        case 0x1009:
85
           return "CAPI not installed";
86
        case 0x100A:
87
           return "Controller does not support external equipment";
88
        case 0x100B:
89
           return "Controller does only support external equipment";
90
 
91
/*-- error information concerning message exchange functions -----*/
92
        case 0x1101:
93
           return "Illegal application number";
94
        case 0x1102:
95
           return "Illegal command or subcommand or message length less than 12 bytes";
96
        case 0x1103:
97
           return "The message could not be accepted because of a queue full condition !! The error code does not imply that CAPI cannot receive messages directed to another controller, PLCI or NCCI";
98
        case 0x1104:
99
           return "Queue is empty";
100
        case 0x1105:
101
           return "Queue overflow, a message was lost !! This indicates a configuration error. The only recovery from this error is to perform a CAPI_RELEASE";
102
        case 0x1106:
103
           return "Unknown notification parameter";
104
        case 0x1107:
105
           return "The Message could not be accepted because of an internal busy condition";
106
        case 0x1108:
107
           return "OS Resource error (no memory ?)";
108
        case 0x1109:
109
           return "CAPI not installed";
110
        case 0x110A:
111
           return "Controller does not support external equipment";
112
        case 0x110B:
113
           return "Controller does only support external equipment";
114
 
115
/*-- error information concerning resource / coding problems -----*/
116
        case 0x2001:
117
           return "Message not supported in current state";
118
        case 0x2002:
119
           return "Illegal Controller / PLCI / NCCI";
120
        case 0x2003:
121
           return "Out of PLCI";
122
        case 0x2004:
123
           return "Out of NCCI";
124
        case 0x2005:
125
           return "Out of LISTEN";
126
        case 0x2006:
127
           return "Out of FAX resources (protocol T.30)";
128
        case 0x2007:
129
           return "Illegal message parameter coding";
130
 
131
/*-- error information concerning requested services  -----*/
132
        case 0x3001:
133
           return "B1 protocol not supported";
134
        case 0x3002:
135
           return "B2 protocol not supported";
136
        case 0x3003:
137
           return "B3 protocol not supported";
138
        case 0x3004:
139
           return "B1 protocol parameter not supported";
140
        case 0x3005:
141
           return "B2 protocol parameter not supported";
142
        case 0x3006:
143
           return "B3 protocol parameter not supported";
144
        case 0x3007:
145
           return "B protocol combination not supported";
146
        case 0x3008:
147
           return "NCPI not supported";
148
        case 0x3009:
149
           return "CIP Value unknown";
150
        case 0x300A:
151
           return "Flags not supported (reserved bits)";
152
        case 0x300B:
153
           return "Facility not supported";
154
        case 0x300C:
155
           return "Data length not supported by current protocol";
156
        case 0x300D:
157
           return "Reset procedure not supported by current protocol";
158
 
159
/*-- informations about the clearing of a physical connection -----*/
160
        case 0x3301:
161
           return "Protocol error layer 1 (broken line or B-channel removed by signalling protocol)";
162
        case 0x3302:
163
           return "Protocol error layer 2";
164
        case 0x3303:
165
           return "Protocol error layer 3";
166
        case 0x3304:
167
           return "Another application got that call";
168
/*-- T.30 specific reasons -----*/
169
        case 0x3311:
170
           return "Connecting not successful (remote station is no FAX G3 machine)";
171
        case 0x3312:
172
           return "Connecting not successful (training error)";
173
        case 0x3313:
174
           return "Disconnected before transfer (remote station does not support transfer mode, e.g. resolution)";
175
        case 0x3314:
176
           return "Disconnected during transfer (remote abort)";
177
        case 0x3315:
178
           return "Disconnected during transfer (remote procedure error, e.g. unsuccessful repetition of T.30 commands)";
179
        case 0x3316:
180
           return "Disconnected during transfer (local tx data underrun)";
181
        case 0x3317:
182
           return "Disconnected during transfer (local rx data overflow)";
183
        case 0x3318:
184
           return "Disconnected during transfer (local abort)";
185
        case 0x3319:
186
           return "Illegal parameter coding (e.g. SFF coding error)";
187
 
188
/*-- disconnect causes from the network according to ETS 300 102-1/Q.931 -----*/
189
        case 0x3481: return "Unallocated (unassigned) number";
190
        case 0x3482: return "No route to specified transit network";
191
        case 0x3483: return "No route to destination";
192
        case 0x3486: return "Channel unacceptable";
193
        case 0x3487:
194
           return "Call awarded and being delivered in an established channel";
195
        case 0x3490: return "Normal call clearing";
196
        case 0x3491: return "User busy";
197
        case 0x3492: return "No user responding";
198
        case 0x3493: return "No answer from user (user alerted)";
199
        case 0x3495: return "Call rejected";
200
        case 0x3496: return "Number changed";
201
        case 0x349A: return "Non-selected user clearing";
202
        case 0x349B: return "Destination out of order";
203
        case 0x349C: return "Invalid number format";
204
        case 0x349D: return "Facility rejected";
205
        case 0x349E: return "Response to STATUS ENQUIRY";
206
        case 0x349F: return "Normal, unspecified";
207
        case 0x34A2: return "No circuit / channel available";
208
        case 0x34A6: return "Network out of order";
209
        case 0x34A9: return "Temporary failure";
210
        case 0x34AA: return "Switching equipment congestion";
211
        case 0x34AB: return "Access information discarded";
212
        case 0x34AC: return "Requested circuit / channel not available";
213
        case 0x34AF: return "Resources unavailable, unspecified";
214
        case 0x34B1: return "Quality of service unavailable";
215
        case 0x34B2: return "Requested facility not subscribed";
216
        case 0x34B9: return "Bearer capability not authorized";
217
        case 0x34BA: return "Bearer capability not presently available";
218
        case 0x34BF: return "Service or option not available, unspecified";
219
        case 0x34C1: return "Bearer capability not implemented";
220
        case 0x34C2: return "Channel type not implemented";
221
        case 0x34C5: return "Requested facility not implemented";
222
        case 0x34C6: return "Only restricted digital information bearer capability is available";
223
        case 0x34CF: return "Service or option not implemented, unspecified";
224
        case 0x34D1: return "Invalid call reference value";
225
        case 0x34D2: return "Identified channel does not exist";
226
        case 0x34D3: return "A suspended call exists, but this call identity does not";
227
        case 0x34D4: return "Call identity in use";
228
        case 0x34D5: return "No call suspended";
229
        case 0x34D6: return "Call having the requested call identity has been cleared";
230
        case 0x34D8: return "Incompatible destination";
231
        case 0x34DB: return "Invalid transit network selection";
232
        case 0x34DF: return "Invalid message, unspecified";
233
        case 0x34E0: return "Mandatory information element is missing";
234
        case 0x34E1: return "Message type non-existent or not implemented";
235
        case 0x34E2: return "Message not compatible with call state or message type non-existent or not implemented";
236
        case 0x34E3: return "Information element non-existent or not implemented";
237
        case 0x34E4: return "Invalid information element contents";
238
        case 0x34E5: return "Message not compatible with call state";
239
        case 0x34E6: return "Recovery on timer expiry";
240
        case 0x34EF: return "Protocol error, unspecified";
241
        case 0x34FF: return "Interworking, unspecified";
242
 
243
        default: return "No additional information";
244
    }
245
}
246
#endif
247
 
248
typedef struct {
249
        int typ;
250
        size_t off;
251
} _cdef;
252
 
253
#define _CBYTE         1
254
#define _CWORD         2
255
#define _CDWORD        3
256
#define _CSTRUCT       4
257
#define _CMSTRUCT      5
258
#define _CEND          6
259
 
260
static _cdef cdef[] =
261
{
262
    /*00 */
263
 {_CEND},
264
    /*01 */
265
 {_CEND},
266
    /*02 */
267
 {_CEND},
268
    /*03 */
269
 {_CDWORD, offsetof(_cmsg, adr.adrController)},
270
    /*04 */
271
 {_CMSTRUCT, offsetof(_cmsg, AdditionalInfo)},
272
    /*05 */
273
 {_CSTRUCT, offsetof(_cmsg, B1configuration)},
274
    /*06 */
275
 {_CWORD, offsetof(_cmsg, B1protocol)},
276
    /*07 */
277
 {_CSTRUCT, offsetof(_cmsg, B2configuration)},
278
    /*08 */
279
 {_CWORD, offsetof(_cmsg, B2protocol)},
280
    /*09 */
281
 {_CSTRUCT, offsetof(_cmsg, B3configuration)},
282
    /*0a */
283
 {_CWORD, offsetof(_cmsg, B3protocol)},
284
    /*0b */
285
 {_CSTRUCT, offsetof(_cmsg, BC)},
286
    /*0c */
287
 {_CSTRUCT, offsetof(_cmsg, BChannelinformation)},
288
    /*0d */
289
 {_CMSTRUCT, offsetof(_cmsg, BProtocol)},
290
    /*0e */
291
 {_CSTRUCT, offsetof(_cmsg, CalledPartyNumber)},
292
    /*0f */
293
 {_CSTRUCT, offsetof(_cmsg, CalledPartySubaddress)},
294
    /*10 */
295
 {_CSTRUCT, offsetof(_cmsg, CallingPartyNumber)},
296
    /*11 */
297
 {_CSTRUCT, offsetof(_cmsg, CallingPartySubaddress)},
298
    /*12 */
299
 {_CDWORD, offsetof(_cmsg, CIPmask)},
300
    /*13 */
301
 {_CDWORD, offsetof(_cmsg, CIPmask2)},
302
    /*14 */
303
 {_CWORD, offsetof(_cmsg, CIPValue)},
304
    /*15 */
305
 {_CDWORD, offsetof(_cmsg, Class)},
306
    /*16 */
307
 {_CSTRUCT, offsetof(_cmsg, ConnectedNumber)},
308
    /*17 */
309
 {_CSTRUCT, offsetof(_cmsg, ConnectedSubaddress)},
310
    /*18 */
311
 {_CDWORD, offsetof(_cmsg, Data)},
312
    /*19 */
313
 {_CWORD, offsetof(_cmsg, DataHandle)},
314
    /*1a */
315
 {_CWORD, offsetof(_cmsg, DataLength)},
316
    /*1b */
317
 {_CSTRUCT, offsetof(_cmsg, FacilityConfirmationParameter)},
318
    /*1c */
319
 {_CSTRUCT, offsetof(_cmsg, Facilitydataarray)},
320
    /*1d */
321
 {_CSTRUCT, offsetof(_cmsg, FacilityIndicationParameter)},
322
    /*1e */
323
 {_CSTRUCT, offsetof(_cmsg, FacilityRequestParameter)},
324
    /*1f */
325
 {_CWORD, offsetof(_cmsg, FacilitySelector)},
326
    /*20 */
327
 {_CWORD, offsetof(_cmsg, Flags)},
328
    /*21 */
329
 {_CDWORD, offsetof(_cmsg, Function)},
330
    /*22 */
331
 {_CSTRUCT, offsetof(_cmsg, HLC)},
332
    /*23 */
333
 {_CWORD, offsetof(_cmsg, Info)},
334
    /*24 */
335
 {_CSTRUCT, offsetof(_cmsg, InfoElement)},
336
    /*25 */
337
 {_CDWORD, offsetof(_cmsg, InfoMask)},
338
    /*26 */
339
 {_CWORD, offsetof(_cmsg, InfoNumber)},
340
    /*27 */
341
 {_CSTRUCT, offsetof(_cmsg, Keypadfacility)},
342
    /*28 */
343
 {_CSTRUCT, offsetof(_cmsg, LLC)},
344
    /*29 */
345
 {_CSTRUCT, offsetof(_cmsg, ManuData)},
346
    /*2a */
347
 {_CDWORD, offsetof(_cmsg, ManuID)},
348
    /*2b */
349
 {_CSTRUCT, offsetof(_cmsg, NCPI)},
350
    /*2c */
351
 {_CWORD, offsetof(_cmsg, Reason)},
352
    /*2d */
353
 {_CWORD, offsetof(_cmsg, Reason_B3)},
354
    /*2e */
355
 {_CWORD, offsetof(_cmsg, Reject)},
356
    /*2f */
357
 {_CSTRUCT, offsetof(_cmsg, Useruserdata)}
358
};
359
 
360
static unsigned char *cpars[] =
361
{
362
    /*00 */ 0,
363
    /*01 ALERT_REQ */ (unsigned char *) "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
364
    /*02 CONNECT_REQ */ (unsigned char *) "\x03\x14\x0e\x10\x0f\x11\x0d\x06\x08\x0a\x05\x07\x09\x01\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
365
    /*03 */ 0,
366
    /*04 DISCONNECT_REQ */ (unsigned char *) "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
367
    /*05 LISTEN_REQ */ (unsigned char *) "\x03\x25\x12\x13\x10\x11\x01",
368
    /*06 */ 0,
369
    /*07 */ 0,
370
    /*08 INFO_REQ */ (unsigned char *) "\x03\x0e\x04\x0c\x27\x2f\x1c\x01\x01",
371
    /*09 FACILITY_REQ */ (unsigned char *) "\x03\x1f\x1e\x01",
372
    /*0a SELECT_B_PROTOCOL_REQ */ (unsigned char *) "\x03\x0d\x06\x08\x0a\x05\x07\x09\x01\x01",
373
    /*0b CONNECT_B3_REQ */ (unsigned char *) "\x03\x2b\x01",
374
    /*0c */ 0,
375
    /*0d DISCONNECT_B3_REQ */ (unsigned char *) "\x03\x2b\x01",
376
    /*0e */ 0,
377
    /*0f DATA_B3_REQ */ (unsigned char *) "\x03\x18\x1a\x19\x20\x01",
378
    /*10 RESET_B3_REQ */ (unsigned char *) "\x03\x2b\x01",
379
    /*11 */ 0,
380
    /*12 */ 0,
381
    /*13 ALERT_CONF */ (unsigned char *) "\x03\x23\x01",
382
    /*14 CONNECT_CONF */ (unsigned char *) "\x03\x23\x01",
383
    /*15 */ 0,
384
    /*16 DISCONNECT_CONF */ (unsigned char *) "\x03\x23\x01",
385
    /*17 LISTEN_CONF */ (unsigned char *) "\x03\x23\x01",
386
    /*18 MANUFACTURER_REQ */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
387
    /*19 */ 0,
388
    /*1a INFO_CONF */ (unsigned char *) "\x03\x23\x01",
389
    /*1b FACILITY_CONF */ (unsigned char *) "\x03\x23\x1f\x1b\x01",
390
    /*1c SELECT_B_PROTOCOL_CONF */ (unsigned char *) "\x03\x23\x01",
391
    /*1d CONNECT_B3_CONF */ (unsigned char *) "\x03\x23\x01",
392
    /*1e */ 0,
393
    /*1f DISCONNECT_B3_CONF */ (unsigned char *) "\x03\x23\x01",
394
    /*20 */ 0,
395
    /*21 DATA_B3_CONF */ (unsigned char *) "\x03\x19\x23\x01",
396
    /*22 RESET_B3_CONF */ (unsigned char *) "\x03\x23\x01",
397
    /*23 */ 0,
398
    /*24 */ 0,
399
    /*25 */ 0,
400
    /*26 CONNECT_IND */ (unsigned char *) "\x03\x14\x0e\x10\x0f\x11\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
401
    /*27 CONNECT_ACTIVE_IND */ (unsigned char *) "\x03\x16\x17\x28\x01",
402
    /*28 DISCONNECT_IND */ (unsigned char *) "\x03\x2c\x01",
403
    /*29 */ 0,
404
    /*2a MANUFACTURER_CONF */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
405
    /*2b */ 0,
406
    /*2c INFO_IND */ (unsigned char *) "\x03\x26\x24\x01",
407
    /*2d FACILITY_IND */ (unsigned char *) "\x03\x1f\x1d\x01",
408
    /*2e */ 0,
409
    /*2f CONNECT_B3_IND */ (unsigned char *) "\x03\x2b\x01",
410
    /*30 CONNECT_B3_ACTIVE_IND */ (unsigned char *) "\x03\x2b\x01",
411
    /*31 DISCONNECT_B3_IND */ (unsigned char *) "\x03\x2d\x2b\x01",
412
    /*32 */ 0,
413
    /*33 DATA_B3_IND */ (unsigned char *) "\x03\x18\x1a\x19\x20\x01",
414
    /*34 RESET_B3_IND */ (unsigned char *) "\x03\x2b\x01",
415
    /*35 CONNECT_B3_T90_ACTIVE_IND */ (unsigned char *) "\x03\x2b\x01",
416
    /*36 */ 0,
417
    /*37 */ 0,
418
    /*38 CONNECT_RESP */ (unsigned char *) "\x03\x2e\x0d\x06\x08\x0a\x05\x07\x09\x01\x16\x17\x28\x04\x0c\x27\x2f\x1c\x01\x01",
419
    /*39 CONNECT_ACTIVE_RESP */ (unsigned char *) "\x03\x01",
420
    /*3a DISCONNECT_RESP */ (unsigned char *) "\x03\x01",
421
    /*3b */ 0,
422
    /*3c MANUFACTURER_IND */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
423
    /*3d */ 0,
424
    /*3e INFO_RESP */ (unsigned char *) "\x03\x01",
425
    /*3f FACILITY_RESP */ (unsigned char *) "\x03\x1f\x01",
426
    /*40 */ 0,
427
    /*41 CONNECT_B3_RESP */ (unsigned char *) "\x03\x2e\x2b\x01",
428
    /*42 CONNECT_B3_ACTIVE_RESP */ (unsigned char *) "\x03\x01",
429
    /*43 DISCONNECT_B3_RESP */ (unsigned char *) "\x03\x01",
430
    /*44 */ 0,
431
    /*45 DATA_B3_RESP */ (unsigned char *) "\x03\x19\x01",
432
    /*46 RESET_B3_RESP */ (unsigned char *) "\x03\x01",
433
    /*47 CONNECT_B3_T90_ACTIVE_RESP */ (unsigned char *) "\x03\x01",
434
    /*48 */ 0,
435
    /*49 */ 0,
436
    /*4a */ 0,
437
    /*4b */ 0,
438
    /*4c */ 0,
439
    /*4d */ 0,
440
    /*4e MANUFACTURER_RESP */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",
441
};
442
 
443
/*-------------------------------------------------------*/
444
 
445
#define byteTLcpy(x,y)        *(__u8 *)(x)=*(__u8 *)(y);
446
#define wordTLcpy(x,y)        *(__u16 *)(x)=*(__u16 *)(y);
447
#define dwordTLcpy(x,y)       memcpy(x,y,4);
448
#define structTLcpy(x,y,l)    memcpy (x,y,l)
449
#define structTLcpyovl(x,y,l) memmove (x,y,l)
450
 
451
#define byteTRcpy(x,y)        *(__u8 *)(y)=*(__u8 *)(x);
452
#define wordTRcpy(x,y)        *(__u16 *)(y)=*(__u16 *)(x);
453
#define dwordTRcpy(x,y)       memcpy(y,x,4);
454
#define structTRcpy(x,y,l)    memcpy (y,x,l)
455
#define structTRcpyovl(x,y,l) memmove (y,x,l)
456
 
457
/*-------------------------------------------------------*/
458
static unsigned command_2_index(unsigned c, unsigned sc)
459
{
460
        if (c & 0x80)
461
                c = 0x9 + (c & 0x0f);
462
        else if (c <= 0x0f);
463
        else if (c == 0x41)
464
                c = 0x9 + 0x1;
465
        else if (c == 0xff)
466
                c = 0x00;
467
        return (sc & 3) * (0x9 + 0x9) + c;
468
}
469
 
470
/*-------------------------------------------------------*/
471
#define TYP (cdef[cmsg->par[cmsg->p]].typ)
472
#define OFF (((__u8 *)cmsg)+cdef[cmsg->par[cmsg->p]].off)
473
 
474
static void jumpcstruct(_cmsg * cmsg)
475
{
476
        unsigned layer;
477
        for (cmsg->p++, layer = 1; layer;) {
478
                /* $$$$$ assert (cmsg->p); */
479
                cmsg->p++;
480
                switch (TYP) {
481
                case _CMSTRUCT:
482
                        layer++;
483
                        break;
484
                case _CEND:
485
                        layer--;
486
                        break;
487
                }
488
        }
489
}
490
/*-------------------------------------------------------*/
491
static void pars_2_message(_cmsg * cmsg)
492
{
493
 
494
        for (; TYP != _CEND; cmsg->p++) {
495
                switch (TYP) {
496
                case _CBYTE:
497
                        byteTLcpy(cmsg->m + cmsg->l, OFF);
498
                        cmsg->l++;
499
                        break;
500
                case _CWORD:
501
                        wordTLcpy(cmsg->m + cmsg->l, OFF);
502
                        cmsg->l += 2;
503
                        break;
504
                case _CDWORD:
505
                        dwordTLcpy(cmsg->m + cmsg->l, OFF);
506
                        cmsg->l += 4;
507
                        break;
508
                case _CSTRUCT:
509
                        if (*(__u8 **) OFF == 0) {
510
                                *(cmsg->m + cmsg->l) = '\0';
511
                                cmsg->l++;
512
                        } else if (**(_cstruct *) OFF != 0xff) {
513
                                structTLcpy(cmsg->m + cmsg->l, *(_cstruct *) OFF, 1 + **(_cstruct *) OFF);
514
                                cmsg->l += 1 + **(_cstruct *) OFF;
515
                        } else {
516
                                _cstruct s = *(_cstruct *) OFF;
517
                                structTLcpy(cmsg->m + cmsg->l, s, 3 + *(__u16 *) (s + 1));
518
                                cmsg->l += 3 + *(__u16 *) (s + 1);
519
                        }
520
                        break;
521
                case _CMSTRUCT:
522
/*----- Metastruktur 0 -----*/
523
                        if (*(_cmstruct *) OFF == CAPI_DEFAULT) {
524
                                *(cmsg->m + cmsg->l) = '\0';
525
                                cmsg->l++;
526
                                jumpcstruct(cmsg);
527
                        }
528
/*----- Metastruktur wird composed -----*/
529
                        else {
530
                                unsigned _l = cmsg->l;
531
                                unsigned _ls;
532
                                cmsg->l++;
533
                                cmsg->p++;
534
                                pars_2_message(cmsg);
535
                                _ls = cmsg->l - _l - 1;
536
                                if (_ls < 255)
537
                                        (cmsg->m + _l)[0] = (__u8) _ls;
538
                                else {
539
                                        structTLcpyovl(cmsg->m + _l + 3, cmsg->m + _l + 1, _ls);
540
                                        (cmsg->m + _l)[0] = 0xff;
541
                                        wordTLcpy(cmsg->m + _l + 1, &_ls);
542
                                }
543
                        }
544
                        break;
545
                }
546
        }
547
}
548
 
549
/*-------------------------------------------------------*/
550
unsigned capi_cmsg2message(_cmsg * cmsg, __u8 * msg)
551
{
552
        cmsg->m = msg;
553
        cmsg->l = 8;
554
        cmsg->p = 0;
555
        cmsg->par = cpars[command_2_index(cmsg->Command, cmsg->Subcommand)];
556
 
557
        pars_2_message(cmsg);
558
 
559
        wordTLcpy(msg + 0, &cmsg->l);
560
        byteTLcpy(cmsg->m + 4, &cmsg->Command);
561
        byteTLcpy(cmsg->m + 5, &cmsg->Subcommand);
562
        wordTLcpy(cmsg->m + 2, &cmsg->ApplId);
563
        wordTLcpy(cmsg->m + 6, &cmsg->Messagenumber);
564
 
565
        return 0;
566
}
567
 
568
/*-------------------------------------------------------*/
569
static void message_2_pars(_cmsg * cmsg)
570
{
571
        for (; TYP != _CEND; cmsg->p++) {
572
 
573
                switch (TYP) {
574
                case _CBYTE:
575
                        byteTRcpy(cmsg->m + cmsg->l, OFF);
576
                        cmsg->l++;
577
                        break;
578
                case _CWORD:
579
                        wordTRcpy(cmsg->m + cmsg->l, OFF);
580
                        cmsg->l += 2;
581
                        break;
582
                case _CDWORD:
583
                        dwordTRcpy(cmsg->m + cmsg->l, OFF);
584
                        cmsg->l += 4;
585
                        break;
586
                case _CSTRUCT:
587
                        *(__u8 **) OFF = cmsg->m + cmsg->l;
588
 
589
                        if (cmsg->m[cmsg->l] != 0xff)
590
                                cmsg->l += 1 + cmsg->m[cmsg->l];
591
                        else
592
                                cmsg->l += 3 + *(__u16 *) (cmsg->m + cmsg->l + 1);
593
                        break;
594
                case _CMSTRUCT:
595
/*----- Metastruktur 0 -----*/
596
                        if (cmsg->m[cmsg->l] == '\0') {
597
                                *(_cmstruct *) OFF = CAPI_DEFAULT;
598
                                cmsg->l++;
599
                                jumpcstruct(cmsg);
600
                        } else {
601
                                unsigned _l = cmsg->l;
602
                                *(_cmstruct *) OFF = CAPI_COMPOSE;
603
                                cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1;
604
                                cmsg->p++;
605
                                message_2_pars(cmsg);
606
                        }
607
                        break;
608
                }
609
        }
610
}
611
 
612
/*-------------------------------------------------------*/
613
unsigned capi_message2cmsg(_cmsg * cmsg, __u8 * msg)
614
{
615
        memset(cmsg, 0, sizeof(_cmsg));
616
        cmsg->m = msg;
617
        cmsg->l = 8;
618
        cmsg->p = 0;
619
        byteTRcpy(cmsg->m + 4, &cmsg->Command);
620
        byteTRcpy(cmsg->m + 5, &cmsg->Subcommand);
621
        cmsg->par = cpars[command_2_index(cmsg->Command, cmsg->Subcommand)];
622
 
623
        message_2_pars(cmsg);
624
 
625
        wordTRcpy(msg + 0, &cmsg->l);
626
        wordTRcpy(cmsg->m + 2, &cmsg->ApplId);
627
        wordTRcpy(cmsg->m + 6, &cmsg->Messagenumber);
628
 
629
        return 0;
630
}
631
 
632
/*-------------------------------------------------------*/
633
unsigned capi_cmsg_header(_cmsg * cmsg, __u16 _ApplId,
634
                          __u8 _Command, __u8 _Subcommand,
635
                          __u16 _Messagenumber, __u32 _Controller)
636
{
637
        memset(cmsg, 0, sizeof(_cmsg));
638
        cmsg->ApplId = _ApplId;
639
        cmsg->Command = _Command;
640
        cmsg->Subcommand = _Subcommand;
641
        cmsg->Messagenumber = _Messagenumber;
642
        cmsg->adr.adrController = _Controller;
643
        return 0;
644
}
645
 
646
/*-------------------------------------------------------*/
647
 
648
static char *mnames[] =
649
{
650
        0,
651
        "ALERT_REQ",
652
        "CONNECT_REQ",
653
        0,
654
        "DISCONNECT_REQ",
655
        "LISTEN_REQ",
656
        0,
657
        0,
658
        "INFO_REQ",
659
        "FACILITY_REQ",
660
        "SELECT_B_PROTOCOL_REQ",
661
        "CONNECT_B3_REQ",
662
        0,
663
        "DISCONNECT_B3_REQ",
664
        0,
665
        "DATA_B3_REQ",
666
        "RESET_B3_REQ",
667
        0,
668
        0,
669
        "ALERT_CONF",
670
        "CONNECT_CONF",
671
        0,
672
        "DISCONNECT_CONF",
673
        "LISTEN_CONF",
674
        "MANUFACTURER_REQ",
675
        0,
676
        "INFO_CONF",
677
        "FACILITY_CONF",
678
        "SELECT_B_PROTOCOL_CONF",
679
        "CONNECT_B3_CONF",
680
        0,
681
        "DISCONNECT_B3_CONF",
682
        0,
683
        "DATA_B3_CONF",
684
        "RESET_B3_CONF",
685
        0,
686
        0,
687
        0,
688
        "CONNECT_IND",
689
        "CONNECT_ACTIVE_IND",
690
        "DISCONNECT_IND",
691
        0,
692
        "MANUFACTURER_CONF",
693
        0,
694
        "INFO_IND",
695
        "FACILITY_IND",
696
        0,
697
        "CONNECT_B3_IND",
698
        "CONNECT_B3_ACTIVE_IND",
699
        "DISCONNECT_B3_IND",
700
        0,
701
        "DATA_B3_IND",
702
        "RESET_B3_IND",
703
        "CONNECT_B3_T90_ACTIVE_IND",
704
        0,
705
        0,
706
        "CONNECT_RESP",
707
        "CONNECT_ACTIVE_RESP",
708
        "DISCONNECT_RESP",
709
        0,
710
        "MANUFACTURER_IND",
711
        0,
712
        "INFO_RESP",
713
        "FACILITY_RESP",
714
        0,
715
        "CONNECT_B3_RESP",
716
        "CONNECT_B3_ACTIVE_RESP",
717
        "DISCONNECT_B3_RESP",
718
        0,
719
        "DATA_B3_RESP",
720
        "RESET_B3_RESP",
721
        "CONNECT_B3_T90_ACTIVE_RESP",
722
        0,
723
        0,
724
        0,
725
        0,
726
        0,
727
        0,
728
        "MANUFACTURER_RESP"
729
};
730
 
731
char *capi_cmd2str(__u8 cmd, __u8 subcmd)
732
{
733
        return mnames[command_2_index(cmd, subcmd)];
734
}
735
 
736
 
737
/*-------------------------------------------------------*/
738
/*-------------------------------------------------------*/
739
 
740
static char *pnames[] =
741
{
742
    /*00 */ 0,
743
    /*01 */ 0,
744
    /*02 */ 0,
745
    /*03 */ "Controller/PLCI/NCCI",
746
    /*04 */ "AdditionalInfo",
747
    /*05 */ "B1configuration",
748
    /*06 */ "B1protocol",
749
    /*07 */ "B2configuration",
750
    /*08 */ "B2protocol",
751
    /*09 */ "B3configuration",
752
    /*0a */ "B3protocol",
753
    /*0b */ "BC",
754
    /*0c */ "BChannelinformation",
755
    /*0d */ "BProtocol",
756
    /*0e */ "CalledPartyNumber",
757
    /*0f */ "CalledPartySubaddress",
758
    /*10 */ "CallingPartyNumber",
759
    /*11 */ "CallingPartySubaddress",
760
    /*12 */ "CIPmask",
761
    /*13 */ "CIPmask2",
762
    /*14 */ "CIPValue",
763
    /*15 */ "Class",
764
    /*16 */ "ConnectedNumber",
765
    /*17 */ "ConnectedSubaddress",
766
    /*18 */ "Data",
767
    /*19 */ "DataHandle",
768
    /*1a */ "DataLength",
769
    /*1b */ "FacilityConfirmationParameter",
770
    /*1c */ "Facilitydataarray",
771
    /*1d */ "FacilityIndicationParameter",
772
    /*1e */ "FacilityRequestParameter",
773
    /*1f */ "FacilitySelector",
774
    /*20 */ "Flags",
775
    /*21 */ "Function",
776
    /*22 */ "HLC",
777
    /*23 */ "Info",
778
    /*24 */ "InfoElement",
779
    /*25 */ "InfoMask",
780
    /*26 */ "InfoNumber",
781
    /*27 */ "Keypadfacility",
782
    /*28 */ "LLC",
783
    /*29 */ "ManuData",
784
    /*2a */ "ManuID",
785
    /*2b */ "NCPI",
786
    /*2c */ "Reason",
787
    /*2d */ "Reason_B3",
788
    /*2e */ "Reject",
789
    /*2f */ "Useruserdata"
790
};
791
 
792
 
793
static char buf[8192];
794
static char *p = 0;
795
 
796
#include <stdarg.h>
797
 
798
/*-------------------------------------------------------*/
799
static void bufprint(char *fmt,...)
800
{
801
        va_list f;
802
        va_start(f, fmt);
803
        vsprintf(p, fmt, f);
804
        va_end(f);
805
        p += strlen(p);
806
}
807
 
808
static void printstructlen(__u8 * m, unsigned len)
809
{
810
        unsigned hex = 0;
811
        for (; len; len--, m++)
812
                if (isalnum(*m) || *m == ' ') {
813
                        if (hex)
814
                                bufprint(">");
815
                        bufprint("%c", *m);
816
                        hex = 0;
817
                } else {
818
                        if (!hex)
819
                                bufprint("<%02x", *m);
820
                        else
821
                                bufprint(" %02x", *m);
822
                        hex = 1;
823
                }
824
        if (hex)
825
                bufprint(">");
826
}
827
 
828
static void printstruct(__u8 * m)
829
{
830
        unsigned len;
831
        if (m[0] != 0xff) {
832
                len = m[0];
833
                m += 1;
834
        } else {
835
                len = ((__u16 *) (m + 1))[0];
836
                m += 3;
837
        }
838
        printstructlen(m, len);
839
}
840
 
841
/*-------------------------------------------------------*/
842
#define NAME (pnames[cmsg->par[cmsg->p]])
843
 
844
static void protocol_message_2_pars(_cmsg * cmsg, int level)
845
{
846
        for (; TYP != _CEND; cmsg->p++) {
847
                int slen = 29 + 3 - level;
848
                int i;
849
 
850
                bufprint("  ");
851
                for (i = 0; i < level - 1; i++)
852
                        bufprint(" ");
853
 
854
                switch (TYP) {
855
                case _CBYTE:
856
                        bufprint("%-*s = 0x%x\n", slen, NAME, *(__u8 *) (cmsg->m + cmsg->l));
857
                        cmsg->l++;
858
                        break;
859
                case _CWORD:
860
                        bufprint("%-*s = 0x%x\n", slen, NAME, *(__u16 *) (cmsg->m + cmsg->l));
861
                        cmsg->l += 2;
862
                        break;
863
                case _CDWORD:
864
                        if (strcmp(NAME, "Data") == 0) {
865
                                bufprint("%-*s = ", slen, NAME);
866
                                printstructlen((__u8 *) * (__u32 *) (cmsg->m + cmsg->l),
867
                                               *(__u16 *) (cmsg->m + cmsg->l + sizeof(__u32)));
868
                                bufprint("\n");
869
                        } else
870
                                bufprint("%-*s = 0x%lx\n", slen, NAME, *(__u32 *) (cmsg->m + cmsg->l));
871
                        cmsg->l += 4;
872
                        break;
873
                case _CSTRUCT:
874
                        bufprint("%-*s = ", slen, NAME);
875
                        if (cmsg->m[cmsg->l] == '\0')
876
                                bufprint("default");
877
                        else
878
                                printstruct(cmsg->m + cmsg->l);
879
                        bufprint("\n");
880
                        if (cmsg->m[cmsg->l] != 0xff)
881
                                cmsg->l += 1 + cmsg->m[cmsg->l];
882
                        else
883
                                cmsg->l += 3 + *(__u16 *) (cmsg->m + cmsg->l + 1);
884
 
885
                        break;
886
 
887
                case _CMSTRUCT:
888
/*----- Metastruktur 0 -----*/
889
                        if (cmsg->m[cmsg->l] == '\0') {
890
                                bufprint("%-*s = default\n", slen, NAME);
891
                                cmsg->l++;
892
                                jumpcstruct(cmsg);
893
                        } else {
894
                                char *name = NAME;
895
                                unsigned _l = cmsg->l;
896
                                bufprint("%-*s\n", slen, name);
897
                                cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1;
898
                                cmsg->p++;
899
                                protocol_message_2_pars(cmsg, level + 1);
900
                        }
901
                        break;
902
                }
903
        }
904
}
905
/*-------------------------------------------------------*/
906
char *capi_message2str(__u8 * msg)
907
{
908
 
909
        _cmsg cmsg;
910
        p = buf;
911
        p[0] = 0;
912
 
913
        cmsg.m = msg;
914
        cmsg.l = 8;
915
        cmsg.p = 0;
916
        byteTRcpy(cmsg.m + 4, &cmsg.Command);
917
        byteTRcpy(cmsg.m + 5, &cmsg.Subcommand);
918
        cmsg.par = cpars[command_2_index(cmsg.Command, cmsg.Subcommand)];
919
 
920
        bufprint("%-26s ID=%03d #0x%04x LEN=%04d\n",
921
                 mnames[command_2_index(cmsg.Command, cmsg.Subcommand)],
922
                 ((unsigned short *) msg)[1],
923
                 ((unsigned short *) msg)[3],
924
                 ((unsigned short *) msg)[0]);
925
 
926
        protocol_message_2_pars(&cmsg, 1);
927
        return buf;
928
}
929
 
930
char *capi_cmsg2str(_cmsg * cmsg)
931
{
932
        p = buf;
933
        p[0] = 0;
934
        cmsg->l = 8;
935
        cmsg->p = 0;
936
        bufprint("%s ID=%03d #0x%04x LEN=%04d\n",
937
                 mnames[command_2_index(cmsg->Command, cmsg->Subcommand)],
938
                 ((__u16 *) cmsg->m)[1],
939
                 ((__u16 *) cmsg->m)[3],
940
                 ((__u16 *) cmsg->m)[0]);
941
        protocol_message_2_pars(cmsg, 1);
942
        return buf;
943
}
944
 
945
 
946
#ifdef HAS_NEW_SYMTAB
947
EXPORT_SYMBOL(capi_cmsg2message);
948
EXPORT_SYMBOL(capi_message2cmsg);
949
EXPORT_SYMBOL(capi_cmsg_header);
950
EXPORT_SYMBOL(capi_cmd2str);
951
EXPORT_SYMBOL(capi_cmsg2str);
952
EXPORT_SYMBOL(capi_message2str);
953
#else
954
static struct symbol_table capifunc_syms =
955
{
956
#include <linux/symtab_begin.h>
957
        X(capi_cmsg2message),
958
        X(capi_message2cmsg),
959
        X(capi_cmsg_header),
960
        X(capi_cmd2str),
961
        X(capi_cmsg2str),
962
        X(capi_message2str),
963
        X(capi_info2str),
964
#include <linux/symtab_end.h>
965
};
966
#endif
967
 
968
#ifdef MODULE
969
 
970
int init_module(void)
971
{
972
#ifndef HAS_NEW_SYMTAB
973
        register_symtab(&capifunc_syms);
974
#endif
975
        return 0;
976
}
977
 
978
void cleanup_module(void)
979
{
980
}
981
 
982
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.