📄 capiutil.c
字号:
/* * $Id: capiutil.c,v 1.13 2000/11/23 20:45:14 kai Exp $ * * CAPI 2.0 convert capi message to capi message struct * * From CAPI 2.0 Development Kit AVM 1995 (msg.c) * Rewritten for Linux 1996 by Carsten Paeth (calle@calle.in-berlin.de) * * $Log: capiutil.c,v $ * Revision 1.13 2000/11/23 20:45:14 kai * fixed module_init/exit stuff * Note: compiled-in kernel doesn't work pre 2.2.18 anymore. * * Revision 1.12 2000/11/01 14:05:02 calle * - use module_init/module_exit from linux/init.h. * - all static struct variables are initialized with "membername:" now. * - avm_cs.c, let it work with newer pcmcia-cs. * * Revision 1.11 2000/03/03 15:50:42 calle * - kernel CAPI: * - Changed parameter "param" in capi_signal from __u32 to void *. * - rewrote notifier handling in kcapi.c * - new notifier NCCI_UP and NCCI_DOWN * - User CAPI: * - /dev/capi20 is now a cloning device. * - middleware extentions prepared. * - capidrv.c * - locking of list operations and module count updates. * * Revision 1.10 1999/08/31 11:19:54 paul * various spelling corrections (new checksums may be needed, Karsten!) * * Revision 1.9 1999/07/09 15:05:46 keil * compat.h is now isdn_compat.h * * Revision 1.8 1999/07/01 15:26:37 calle * complete new version (I love it): * + new hardware independed "capi_driver" interface that will make it easy to: * - support other controllers with CAPI-2.0 (i.e. USB Controller) * - write a CAPI-2.0 for the passive cards * - support serial link CAPI-2.0 boxes. * + wrote "capi_driver" for all supported cards. * + "capi_driver" (supported cards) now have to be configured with * make menuconfig, in the past all supported cards where included * at once. * + new and better informations in /proc/capi/ * + new ioctl to switch trace of capi messages per controller * using "avmcapictrl trace [contr] on|off|...." * + complete testcircle with all supported cards and also the * PCMCIA cards (now patch for pcmcia-cs-3.0.13 needed) done. * * Revision 1.7 1999/07/01 08:23:01 keil * compatibility macros now in <linux/isdn_compat.h> * * Revision 1.6 1997/11/04 06:12:12 calle * capi.c: new read/write in file_ops since 2.1.60 * capidrv.c: prepared isdnlog interface for d2-trace in newer firmware. * capiutil.c: needs config.h (CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON) * compat.h: added #define LinuxVersionCode * * Revision 1.5 1997/10/01 09:21:19 fritz * Removed old compatibility stuff for 2.0.X kernels. * From now on, this code is for 2.1.X ONLY! * Old stuff is still in the separate branch. * * Revision 1.4 1997/08/10 07:43:55 calle * forgot to export symbol capi_info2str for 2.1.x * * Revision 1.3 1997/05/18 09:24:18 calle * added verbose disconnect reason reporting to avmb1. * some fixes in capi20 interface. * changed info messages for B1-PCI * * Revision 1.2 1997/03/05 21:22:13 fritz * Fix: Symbols have to be exported unconditionally. * * Revision 1.1 1997/03/04 21:50:34 calle * Frirst version in isdn4linux * * Revision 2.2 1997/02/12 09:31:39 calle * new version * * Revision 1.1 1997/01/31 10:32:20 calle * Initial revision * */#include <linux/module.h>#include <linux/string.h>#include <linux/ctype.h>#include <linux/stddef.h>#include <linux/kernel.h>#include <linux/mm.h>#include <linux/init.h>#include <asm/segment.h>#include <linux/config.h>#include "capiutil.h"/* from CAPI2.0 DDK AVM Berlin GmbH */#ifndef CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASONchar *capi_info2str(__u16 reason){ return "..";}#elsechar *capi_info2str(__u16 reason){ switch (reason) {/*-- informative values (corresponding message was processed) -----*/ case 0x0001: return "NCPI not supported by current protocol, NCPI ignored"; case 0x0002: return "Flags not supported by current protocol, flags ignored"; case 0x0003: return "Alert already sent by another application";/*-- error information concerning CAPI_REGISTER -----*/ case 0x1001: return "Too many applications"; case 0x1002: return "Logical block size too small, must be at least 128 Bytes"; case 0x1003: return "Buffer exceeds 64 kByte"; case 0x1004: return "Message buffer size too small, must be at least 1024 Bytes"; case 0x1005: return "Max. number of logical connections not supported"; case 0x1006: return "Reserved"; case 0x1007: return "The message could not be accepted because of an internal busy condition"; case 0x1008: return "OS resource error (no memory ?)"; case 0x1009: return "CAPI not installed"; case 0x100A: return "Controller does not support external equipment"; case 0x100B: return "Controller does only support external equipment";/*-- error information concerning message exchange functions -----*/ case 0x1101: return "Illegal application number"; case 0x1102: return "Illegal command or subcommand or message length less than 12 bytes"; case 0x1103: 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"; case 0x1104: return "Queue is empty"; case 0x1105: return "Queue overflow, a message was lost !! This indicates a configuration error. The only recovery from this error is to perform a CAPI_RELEASE"; case 0x1106: return "Unknown notification parameter"; case 0x1107: return "The Message could not be accepted because of an internal busy condition"; case 0x1108: return "OS Resource error (no memory ?)"; case 0x1109: return "CAPI not installed"; case 0x110A: return "Controller does not support external equipment"; case 0x110B: return "Controller does only support external equipment";/*-- error information concerning resource / coding problems -----*/ case 0x2001: return "Message not supported in current state"; case 0x2002: return "Illegal Controller / PLCI / NCCI"; case 0x2003: return "Out of PLCI"; case 0x2004: return "Out of NCCI"; case 0x2005: return "Out of LISTEN"; case 0x2006: return "Out of FAX resources (protocol T.30)"; case 0x2007: return "Illegal message parameter coding";/*-- error information concerning requested services -----*/ case 0x3001: return "B1 protocol not supported"; case 0x3002: return "B2 protocol not supported"; case 0x3003: return "B3 protocol not supported"; case 0x3004: return "B1 protocol parameter not supported"; case 0x3005: return "B2 protocol parameter not supported"; case 0x3006: return "B3 protocol parameter not supported"; case 0x3007: return "B protocol combination not supported"; case 0x3008: return "NCPI not supported"; case 0x3009: return "CIP Value unknown"; case 0x300A: return "Flags not supported (reserved bits)"; case 0x300B: return "Facility not supported"; case 0x300C: return "Data length not supported by current protocol"; case 0x300D: return "Reset procedure not supported by current protocol";/*-- informations about the clearing of a physical connection -----*/ case 0x3301: return "Protocol error layer 1 (broken line or B-channel removed by signalling protocol)"; case 0x3302: return "Protocol error layer 2"; case 0x3303: return "Protocol error layer 3"; case 0x3304: return "Another application got that call";/*-- T.30 specific reasons -----*/ case 0x3311: return "Connecting not successful (remote station is no FAX G3 machine)"; case 0x3312: return "Connecting not successful (training error)"; case 0x3313: return "Disconnected before transfer (remote station does not support transfer mode, e.g. resolution)"; case 0x3314: return "Disconnected during transfer (remote abort)"; case 0x3315: return "Disconnected during transfer (remote procedure error, e.g. unsuccessful repetition of T.30 commands)"; case 0x3316: return "Disconnected during transfer (local tx data underrun)"; case 0x3317: return "Disconnected during transfer (local rx data overflow)"; case 0x3318: return "Disconnected during transfer (local abort)"; case 0x3319: return "Illegal parameter coding (e.g. SFF coding error)";/*-- disconnect causes from the network according to ETS 300 102-1/Q.931 -----*/ case 0x3481: return "Unallocated (unassigned) number"; case 0x3482: return "No route to specified transit network"; case 0x3483: return "No route to destination"; case 0x3486: return "Channel unacceptable"; case 0x3487: return "Call awarded and being delivered in an established channel"; case 0x3490: return "Normal call clearing"; case 0x3491: return "User busy"; case 0x3492: return "No user responding"; case 0x3493: return "No answer from user (user alerted)"; case 0x3495: return "Call rejected"; case 0x3496: return "Number changed"; case 0x349A: return "Non-selected user clearing"; case 0x349B: return "Destination out of order"; case 0x349C: return "Invalid number format"; case 0x349D: return "Facility rejected"; case 0x349E: return "Response to STATUS ENQUIRY"; case 0x349F: return "Normal, unspecified"; case 0x34A2: return "No circuit / channel available"; case 0x34A6: return "Network out of order"; case 0x34A9: return "Temporary failure"; case 0x34AA: return "Switching equipment congestion"; case 0x34AB: return "Access information discarded"; case 0x34AC: return "Requested circuit / channel not available"; case 0x34AF: return "Resources unavailable, unspecified"; case 0x34B1: return "Quality of service unavailable"; case 0x34B2: return "Requested facility not subscribed"; case 0x34B9: return "Bearer capability not authorized"; case 0x34BA: return "Bearer capability not presently available"; case 0x34BF: return "Service or option not available, unspecified"; case 0x34C1: return "Bearer capability not implemented"; case 0x34C2: return "Channel type not implemented"; case 0x34C5: return "Requested facility not implemented"; case 0x34C6: return "Only restricted digital information bearer capability is available"; case 0x34CF: return "Service or option not implemented, unspecified"; case 0x34D1: return "Invalid call reference value"; case 0x34D2: return "Identified channel does not exist"; case 0x34D3: return "A suspended call exists, but this call identity does not"; case 0x34D4: return "Call identity in use"; case 0x34D5: return "No call suspended"; case 0x34D6: return "Call having the requested call identity has been cleared"; case 0x34D8: return "Incompatible destination"; case 0x34DB: return "Invalid transit network selection"; case 0x34DF: return "Invalid message, unspecified"; case 0x34E0: return "Mandatory information element is missing"; case 0x34E1: return "Message type non-existent or not implemented"; case 0x34E2: return "Message not compatible with call state or message type non-existent or not implemented"; case 0x34E3: return "Information element non-existent or not implemented"; case 0x34E4: return "Invalid information element contents"; case 0x34E5: return "Message not compatible with call state"; case 0x34E6: return "Recovery on timer expiry"; case 0x34EF: return "Protocol error, unspecified"; case 0x34FF: return "Interworking, unspecified"; default: return "No additional information"; }}#endiftypedef struct { int typ; size_t off;} _cdef;#define _CBYTE 1#define _CWORD 2#define _CDWORD 3#define _CSTRUCT 4#define _CMSTRUCT 5#define _CEND 6static _cdef cdef[] ={ /*00 */ {_CEND}, /*01 */ {_CEND}, /*02 */ {_CEND}, /*03 */ {_CDWORD, offsetof(_cmsg, adr.adrController)}, /*04 */ {_CMSTRUCT, offsetof(_cmsg, AdditionalInfo)}, /*05 */ {_CSTRUCT, offsetof(_cmsg, B1configuration)}, /*06 */ {_CWORD, offsetof(_cmsg, B1protocol)}, /*07 */ {_CSTRUCT, offsetof(_cmsg, B2configuration)}, /*08 */ {_CWORD, offsetof(_cmsg, B2protocol)}, /*09 */ {_CSTRUCT, offsetof(_cmsg, B3configuration)}, /*0a */ {_CWORD, offsetof(_cmsg, B3protocol)}, /*0b */ {_CSTRUCT, offsetof(_cmsg, BC)}, /*0c */ {_CSTRUCT, offsetof(_cmsg, BChannelinformation)}, /*0d */ {_CMSTRUCT, offsetof(_cmsg, BProtocol)}, /*0e */ {_CSTRUCT, offsetof(_cmsg, CalledPartyNumber)}, /*0f */ {_CSTRUCT, offsetof(_cmsg, CalledPartySubaddress)}, /*10 */ {_CSTRUCT, offsetof(_cmsg, CallingPartyNumber)}, /*11 */ {_CSTRUCT, offsetof(_cmsg, CallingPartySubaddress)}, /*12 */ {_CDWORD, offsetof(_cmsg, CIPmask)}, /*13 */ {_CDWORD, offsetof(_cmsg, CIPmask2)}, /*14 */ {_CWORD, offsetof(_cmsg, CIPValue)}, /*15 */ {_CDWORD, offsetof(_cmsg, Class)}, /*16 */ {_CSTRUCT, offsetof(_cmsg, ConnectedNumber)}, /*17 */ {_CSTRUCT, offsetof(_cmsg, ConnectedSubaddress)}, /*18 */ {_CDWORD, offsetof(_cmsg, Data)}, /*19 */ {_CWORD, offsetof(_cmsg, DataHandle)}, /*1a */ {_CWORD, offsetof(_cmsg, DataLength)}, /*1b */ {_CSTRUCT, offsetof(_cmsg, FacilityConfirmationParameter)}, /*1c */ {_CSTRUCT, offsetof(_cmsg, Facilitydataarray)}, /*1d */ {_CSTRUCT, offsetof(_cmsg, FacilityIndicationParameter)}, /*1e */ {_CSTRUCT, offsetof(_cmsg, FacilityRequestParameter)}, /*1f */ {_CWORD, offsetof(_cmsg, FacilitySelector)}, /*20 */ {_CWORD, offsetof(_cmsg, Flags)}, /*21 */ {_CDWORD, offsetof(_cmsg, Function)}, /*22 */ {_CSTRUCT, offsetof(_cmsg, HLC)}, /*23 */ {_CWORD, offsetof(_cmsg, Info)}, /*24 */ {_CSTRUCT, offsetof(_cmsg, InfoElement)}, /*25 */ {_CDWORD, offsetof(_cmsg, InfoMask)}, /*26 */ {_CWORD, offsetof(_cmsg, InfoNumber)}, /*27 */ {_CSTRUCT, offsetof(_cmsg, Keypadfacility)}, /*28 */ {_CSTRUCT, offsetof(_cmsg, LLC)}, /*29 */ {_CSTRUCT, offsetof(_cmsg, ManuData)}, /*2a */ {_CDWORD, offsetof(_cmsg, ManuID)}, /*2b */ {_CSTRUCT, offsetof(_cmsg, NCPI)}, /*2c */ {_CWORD, offsetof(_cmsg, Reason)}, /*2d */ {_CWORD, offsetof(_cmsg, Reason_B3)}, /*2e */ {_CWORD, offsetof(_cmsg, Reject)}, /*2f */ {_CSTRUCT, offsetof(_cmsg, Useruserdata)}};static unsigned char *cpars[] ={ /*00 */ 0, /*01 ALERT_REQ */ (unsigned char *) "\x03\x04\x0c\x27\x2f\x1c\x01\x01", /*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", /*03 */ 0, /*04 DISCONNECT_REQ */ (unsigned char *) "\x03\x04\x0c\x27\x2f\x1c\x01\x01", /*05 LISTEN_REQ */ (unsigned char *) "\x03\x25\x12\x13\x10\x11\x01", /*06 */ 0, /*07 */ 0, /*08 INFO_REQ */ (unsigned char *) "\x03\x0e\x04\x0c\x27\x2f\x1c\x01\x01", /*09 FACILITY_REQ */ (unsigned char *) "\x03\x1f\x1e\x01", /*0a SELECT_B_PROTOCOL_REQ */ (unsigned char *) "\x03\x0d\x06\x08\x0a\x05\x07\x09\x01\x01", /*0b CONNECT_B3_REQ */ (unsigned char *) "\x03\x2b\x01", /*0c */ 0, /*0d DISCONNECT_B3_REQ */ (unsigned char *) "\x03\x2b\x01", /*0e */ 0, /*0f DATA_B3_REQ */ (unsigned char *) "\x03\x18\x1a\x19\x20\x01", /*10 RESET_B3_REQ */ (unsigned char *) "\x03\x2b\x01", /*11 */ 0, /*12 */ 0, /*13 ALERT_CONF */ (unsigned char *) "\x03\x23\x01", /*14 CONNECT_CONF */ (unsigned char *) "\x03\x23\x01", /*15 */ 0, /*16 DISCONNECT_CONF */ (unsigned char *) "\x03\x23\x01", /*17 LISTEN_CONF */ (unsigned char *) "\x03\x23\x01", /*18 MANUFACTURER_REQ */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01", /*19 */ 0, /*1a INFO_CONF */ (unsigned char *) "\x03\x23\x01", /*1b FACILITY_CONF */ (unsigned char *) "\x03\x23\x1f\x1b\x01", /*1c SELECT_B_PROTOCOL_CONF */ (unsigned char *) "\x03\x23\x01", /*1d CONNECT_B3_CONF */ (unsigned char *) "\x03\x23\x01", /*1e */ 0, /*1f DISCONNECT_B3_CONF */ (unsigned char *) "\x03\x23\x01", /*20 */ 0, /*21 DATA_B3_CONF */ (unsigned char *) "\x03\x19\x23\x01", /*22 RESET_B3_CONF */ (unsigned char *) "\x03\x23\x01", /*23 */ 0, /*24 */ 0, /*25 */ 0, /*26 CONNECT_IND */ (unsigned char *) "\x03\x14\x0e\x10\x0f\x11\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01", /*27 CONNECT_ACTIVE_IND */ (unsigned char *) "\x03\x16\x17\x28\x01", /*28 DISCONNECT_IND */ (unsigned char *) "\x03\x2c\x01", /*29 */ 0, /*2a MANUFACTURER_CONF */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01", /*2b */ 0, /*2c INFO_IND */ (unsigned char *) "\x03\x26\x24\x01", /*2d FACILITY_IND */ (unsigned char *) "\x03\x1f\x1d\x01", /*2e */ 0, /*2f CONNECT_B3_IND */ (unsigned char *) "\x03\x2b\x01", /*30 CONNECT_B3_ACTIVE_IND */ (unsigned char *) "\x03\x2b\x01", /*31 DISCONNECT_B3_IND */ (unsigned char *) "\x03\x2d\x2b\x01", /*32 */ 0, /*33 DATA_B3_IND */ (unsigned char *) "\x03\x18\x1a\x19\x20\x01", /*34 RESET_B3_IND */ (unsigned char *) "\x03\x2b\x01", /*35 CONNECT_B3_T90_ACTIVE_IND */ (unsigned char *) "\x03\x2b\x01", /*36 */ 0, /*37 */ 0, /*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", /*39 CONNECT_ACTIVE_RESP */ (unsigned char *) "\x03\x01", /*3a DISCONNECT_RESP */ (unsigned char *) "\x03\x01", /*3b */ 0, /*3c MANUFACTURER_IND */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01", /*3d */ 0, /*3e INFO_RESP */ (unsigned char *) "\x03\x01", /*3f FACILITY_RESP */ (unsigned char *) "\x03\x1f\x01", /*40 */ 0, /*41 CONNECT_B3_RESP */ (unsigned char *) "\x03\x2e\x2b\x01", /*42 CONNECT_B3_ACTIVE_RESP */ (unsigned char *) "\x03\x01", /*43 DISCONNECT_B3_RESP */ (unsigned char *) "\x03\x01", /*44 */ 0, /*45 DATA_B3_RESP */ (unsigned char *) "\x03\x19\x01", /*46 RESET_B3_RESP */ (unsigned char *) "\x03\x01", /*47 CONNECT_B3_T90_ACTIVE_RESP */ (unsigned char *) "\x03\x01", /*48 */ 0, /*49 */ 0, /*4a */ 0, /*4b */ 0, /*4c */ 0, /*4d */ 0, /*4e MANUFACTURER_RESP */ (unsigned char *) "\x03\x2a\x15\x21\x29\x01",};/*-------------------------------------------------------*/#define byteTLcpy(x,y) *(__u8 *)(x)=*(__u8 *)(y);#define wordTLcpy(x,y) *(__u16 *)(x)=*(__u16 *)(y);#define dwordTLcpy(x,y) memcpy(x,y,4);#define structTLcpy(x,y,l) memcpy (x,y,l)#define structTLcpyovl(x,y,l) memmove (x,y,l)#define byteTRcpy(x,y) *(__u8 *)(y)=*(__u8 *)(x);#define wordTRcpy(x,y) *(__u16 *)(y)=*(__u16 *)(x);#define dwordTRcpy(x,y) memcpy(y,x,4);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -