^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Kernel CAPI 2.0 Module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 1999 by Carsten Paeth <calle@calle.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2002 by Kai Germaschewski <kai@germaschewski.name>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This software may be used and distributed according to the terms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * of the GNU General Public License, incorporated herein by reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/isdn/capilli.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #ifdef KCAPI_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define DBG(format, arg...) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) printk(KERN_DEBUG "%s: " format "\n" , __func__ , ## arg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define DBG(format, arg...) /* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) CAPI_CTR_DETACHED = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) CAPI_CTR_DETECTED = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) CAPI_CTR_LOADING = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) CAPI_CTR_RUNNING = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) extern struct capi_ctr *capi_controller[CAPI_MAXCONTR];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) extern struct mutex capi_controller_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) extern struct capi20_appl *capi_applications[CAPI_MAXAPPL];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) void kcapi_proc_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) void kcapi_proc_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct capi20_appl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u16 applid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) capi_register_params rparam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void (*recv_message)(struct capi20_appl *ap, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) void *private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* internal to kernelcapi.o */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) unsigned long nrecvctlpkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned long nrecvdatapkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) unsigned long nsentctlpkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) unsigned long nsentdatapkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct mutex recv_mtx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct sk_buff_head recv_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct work_struct recv_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int release_in_progress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u16 capi20_isinstalled(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) u16 capi20_register(struct capi20_appl *ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) u16 capi20_release(struct capi20_appl *ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u16 capi20_put_message(struct capi20_appl *ap, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) u16 capi20_get_manufacturer(u32 contr, u8 buf[CAPI_MANUFACTURER_LEN]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u16 capi20_get_version(u32 contr, struct capi_version *verp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u16 capi20_get_serial(u32 contr, u8 serial[CAPI_SERIAL_LEN]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u16 capi20_get_profile(u32 contr, struct capi_profile *profp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int capi20_manufacturer(unsigned long cmd, void __user *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define CAPICTR_UP 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define CAPICTR_DOWN 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int kcapi_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) void kcapi_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /*----- basic-type definitions -----*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) typedef __u8 *_cstruct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) typedef enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) CAPI_COMPOSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) CAPI_DEFAULT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) } _cmstruct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) The _cmsg structure contains all possible CAPI 2.0 parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) All parameters are stored here first. The function CAPI_CMSG_2_MESSAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) assembles the parameter and builds CAPI2.0 conform messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) CAPI_MESSAGE_2_CMSG disassembles CAPI 2.0 messages and stores the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) parameter in the _cmsg structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* Header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) __u16 ApplId;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) __u8 Command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) __u8 Subcommand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) __u16 Messagenumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* Parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) __u32 adrController;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) __u32 adrPLCI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) __u32 adrNCCI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) } adr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) _cmstruct AdditionalInfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) _cstruct B1configuration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) __u16 B1protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) _cstruct B2configuration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) __u16 B2protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) _cstruct B3configuration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) __u16 B3protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) _cstruct BC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) _cstruct BChannelinformation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) _cmstruct BProtocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) _cstruct CalledPartyNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) _cstruct CalledPartySubaddress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) _cstruct CallingPartyNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) _cstruct CallingPartySubaddress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) __u32 CIPmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) __u32 CIPmask2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) __u16 CIPValue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) __u32 Class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) _cstruct ConnectedNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) _cstruct ConnectedSubaddress;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) __u32 Data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) __u16 DataHandle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) __u16 DataLength;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) _cstruct FacilityConfirmationParameter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) _cstruct Facilitydataarray;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) _cstruct FacilityIndicationParameter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) _cstruct FacilityRequestParameter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) __u16 FacilitySelector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) __u16 Flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) __u32 Function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) _cstruct HLC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) __u16 Info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) _cstruct InfoElement;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) __u32 InfoMask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) __u16 InfoNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) _cstruct Keypadfacility;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) _cstruct LLC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) _cstruct ManuData;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) __u32 ManuID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) _cstruct NCPI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) __u16 Reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) __u16 Reason_B3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) __u16 Reject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) _cstruct Useruserdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* intern */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) unsigned l, p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) unsigned char *par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) __u8 *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /* buffer to construct message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) __u8 buf[180];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) } _cmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /*-----------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * Debugging / Tracing functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) char *capi_cmd2str(__u8 cmd, __u8 subcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) u_char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) u_char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) size_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) } _cdebbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #define CDEBUG_SIZE 1024
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #define CDEBUG_GSIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) void cdebbuf_free(_cdebbuf *cdb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int cdebug_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) void cdebug_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) _cdebbuf *capi_message2str(__u8 *msg);