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