summaryrefslogtreecommitdiff
path: root/zaptel.h
diff options
context:
space:
mode:
authormarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2001-12-08 19:28:09 +0000
committermarkster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2001-12-08 19:28:09 +0000
commit353dc767b015ba95744ae97eaa2abe771bfb719e (patch)
tree6a5a72b7dcdceb6010ed5261e8358efc765cffd0 /zaptel.h
parent295b744618e906719d1ef077dc31d9ff975fe21c (diff)
Version 0.1.4 from FTP
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@37 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'zaptel.h')
-rwxr-xr-xzaptel.h147
1 files changed, 137 insertions, 10 deletions
diff --git a/zaptel.h b/zaptel.h
index 7649645..c71fb5e 100755
--- a/zaptel.h
+++ b/zaptel.h
@@ -49,10 +49,15 @@
#define ZT_CONFIG_TXLEVEL 7 /* bits 0-2 are tx level */
/* Line configuration */
+/* These apply to T1 */
#define ZT_CONFIG_D4 (1 << 4)
#define ZT_CONFIG_ESF (1 << 5)
#define ZT_CONFIG_AMI (1 << 6)
#define ZT_CONFIG_B8ZS (1 << 7)
+/* These apply to E1 */
+#define ZT_CONFIG_CCS (1 << 8) /* CCS (ISDN) instead of CAS (Robbed Bit) */
+#define ZT_CONFIG_HDB3 (1 << 9) /* HDB3 instead of AMI (line coding) */
+#define ZT_CONFIG_CRC4 (1 << 10) /* CRC4 framing */
#define ZT_CONFIG_NOTOPEN (1 << 16)
@@ -79,8 +84,10 @@
#define ZT_SIG_HDLCNET ((1 << 10) | ZT_SIG_HDLCFCS) /* HDLC Network */
#define ZT_SIG_SLAVE (1 << 11) /* Slave to another channel */
-#define ZT_ABIT 0x8
-#define ZT_BBIT 0x4
+#define ZT_ABIT 8
+#define ZT_BBIT 4
+#define ZT_CBIT 2
+#define ZT_DBIT 1
#define ZT_MAJOR 196
@@ -112,6 +119,11 @@ int chanpos; /* Channel number in span */
int sigtype; /* read-only */
int sigcap; /* read-only */
int rxisoffhook; /* read-only */
+int rxbits; /* read-only */
+int txbits; /* read-only */
+int txhooksig; /* read-only */
+int rxhooksig; /* read-only */
+int curlaw; /* read-only -- one of ZT_LAW_MULAW or ZT_LAW_ALAW */
char name[40]; /* Name of channel */
int prewinktime;
int preflashtime;
@@ -134,6 +146,7 @@ int rxlevel; /* current RX level */
int bpvcount; /* current BPV count */
int syncsrc; /* span # of current sync source, or 0 for free run */
int numchans; /* number of configured channels on this span */
+int totalchans; /* total number of channels on the span */
int totalspans; /* total number of zaptel spans in entire system */
} ZT_SPANINFO;
@@ -171,6 +184,7 @@ struct zt_chanconfig
int chan; /* Channel we're applying this to (0 to use name) */
char name[40]; /* Name of channel to use */
int sigtype; /* Signal type */
+int deflaw; /* Default law (ZT_LAW_DEFAULT, ZT_LAW_MULAW, or ZT_LAW_ALAW */
int master; /* Master channel if sigtype is ZT_SLAVE */
} ZT_CHANCONFIG;
@@ -198,6 +212,10 @@ int reserved[4]; /* Reserved for future expansion -- always set to 0 */
#define ZT_DIAL_OP_REPLACE 2
#define ZT_DIAL_OP_CANCEL 3
+#define ZT_LAW_DEFAULT 0 /* Default law for span */
+#define ZT_LAW_MULAW 1 /* Mu-law */
+#define ZT_LAW_ALAW 2 /* A-law */
+
typedef struct zt_dialoperation
{
int op;
@@ -401,7 +419,19 @@ char dialstr[ZT_MAX_DTMF_BUF];
* Specify a channel on /dev/zap/chan -- must be done before any other ioctl's and is only
* valid on /dev/zap/chan
*/
-#define ZT_SPECIFY _IOW (ZT_CODE, 38, int)
+#define ZT_SPECIFY _IOW (ZT_CODE, 38, int)
+
+/*
+ * Temporarily set the law on a channel to
+ * ZT_LAW_DEFAULT, ZT_LAW_ALAW, or ZT_LAW_MULAW. Is reset on close.
+ */
+#define ZT_SETLAW _IOW (ZT_CODE, 39, int)
+
+/*
+ * Temporarily set the channel to operate in linear mode when non-zero
+ * or default law if 0
+ */
+#define ZT_SETLINEAR _IOW (ZT_CODE, 40, int)
/*
* Startup or Shutdown a span
@@ -430,7 +460,6 @@ char dialstr[ZT_MAX_DTMF_BUF];
struct zt_tone_def_header {
int count; /* How many samples follow */
- int size; /* Total size of the *data* of our samples (data only!) */
int zone; /* Which zone we are loading */
int ringcadence[ZT_MAX_CADENCE]; /* Ring cadence in ms (0=on, 1=off, ends with 0 value) */
char name[40]; /* Informational name of zone */
@@ -438,12 +467,38 @@ struct zt_tone_def_header {
};
struct zt_tone_def { /* Structure for zone programming */
- int size; /* The size of the data we have */
int tone; /* See ZT_TONE_* */
int next; /* What the next position in the cadence is
(They're numbered by the order the appear here) */
int samples; /* How many samples to play for this cadence */
- unsigned char data[0]; /* The actual samples */
+ /* Now come the constants we need to make tones */
+ int shift; /* How much to scale down the volume (2 is nice) */
+
+ /*
+ Calculate the next 6 factors using the following equations:
+ l = <level in dbm>, f1 = <freq1>, f2 = <freq2>
+ gain = pow(10.0, (l - 3.14) / 20.0) * 65536.0 / 2.0;
+
+ // Frequency factor 1
+ fac_1 = 2.0 * cos(2.0 * M_PI * (f1/8000.0)) * 32768.0;
+ // Last previous two samples
+ init_v2_1 = sin(-4.0 * M_PI * (f1/8000.0)) * gain;
+ init_v3_1 = sin(-2.0 * M_PI * (f1/8000.0)) * gain;
+
+ // Frequency factor 2
+ fac_2 = 2.0 * cos(2.0 * M_PI * (f2/8000.0)) * 32768.0;
+ // Last previous two samples
+ init_v2_2 = sin(-4.0 * M_PI * (f2/8000.0)) * gain;
+ init_v3_2 = sin(-2.0 * M_PI * (f2/8000.0)) * gain;
+ */
+ int fac1;
+ int init_v2_1;
+ int init_v3_1;
+ int fac2;
+ int init_v2_2;
+ int init_v3_2;
+
+
};
#ifdef __KERNEL__
@@ -617,6 +672,15 @@ struct zt_tone_def { /* Structure for zone programming */
struct zt_span;
struct zt_chan;
+struct zt_tone_state {
+ int v1_1;
+ int v2_1;
+ int v3_1;
+ int v1_2;
+ int v2_2;
+ int v3_2;
+};
+
struct zt_chan {
#ifdef CONFIG_ZAPATA_NET
/* Must be first */
@@ -689,6 +753,7 @@ struct zt_chan {
int tonezone; /* Tone zone for this channel */
struct zt_tone *curtone; /* Current tone we're playing (if any) */
int tonep; /* Current position in tone */
+ struct zt_tone_state ts; /* Tone state */
/* Digit string dialing stuff */
int digitmode; /* What kind of tones are we sending? */
@@ -741,10 +806,17 @@ struct zt_chan {
int gotgs;
int txstate;
int rxsig;
+ int txsig;
int rxsigstate;
+
/* non-RBS rx state */
int rxhooksig;
+ int txhooksig;
int kewlonhook;
+
+ int deflaw; /* 1 = mulaw, 2=alaw, 0=undefined */
+ short *xlaw;
+ unsigned char *lin2x;
};
/* defines for transmit signalling */
@@ -767,7 +839,7 @@ typedef enum {
/* Span flags */
#define ZT_FLAG_REGISTERED (1 << 0)
#define ZT_FLAG_RUNNING (1 << 1)
-#define ZT_FLAG_RBS (1 << 12) /* Span uses RBS signalling */
+#define ZT_FLAG_RBS (1 << 12) /* Span uses RBS signalling */
/* Channel flags */
#define ZT_FLAG_DTMFDECODE (1 << 2) /* Channel supports native DTMF decode */
@@ -781,13 +853,16 @@ typedef enum {
#define ZT_FLAG_AUDIO (1 << 9) /* Audio mode channel */
#define ZT_FLAG_OPEN (1 << 10) /* Channel is open */
-#define ZT_FLAG_FCS (1 << 11) /* Calculate FCS */
+#define ZT_FLAG_FCS (1 << 11) /* Calculate FCS */
+/* Reserve 12 for uniqueness with span flags */
+#define ZT_FLAG_LINEAR (1 << 13) /* Talk to user space in linear */
struct zt_span {
spinlock_t lock;
void *pvt; /* Private stuff */
char name[20]; /* Span name */
char desc[80]; /* Span description */
+ int deflaw; /* Default law (ZT_MULAW or ZT_ALAW) */
int alarms; /* Pending alarms on span */
int flags;
int irq; /* IRQ for this span's hardware */
@@ -891,8 +966,60 @@ extern void zt_qevent(struct zt_chan *chan, int event);
/* Notify a change possible change in alarm status */
extern void zt_alarm_notify(struct zt_span *span);
-extern short zt_mulaw[256];
-extern u_char zt_lin2mu[65536];
+/* Initialize a tone state */
+extern void zt_init_tone_state(struct zt_tone_state *ts, struct zt_tone *zt);
+
+/* Get a given DTMF or MF tone struct, suitable for zt_tone_nextsample.
+ Set 'mf' to 0 for DTMF or 1 for MFv1 */
+extern struct zt_tone *zt_dtmf_tone(char digit, int mf);
+
+/* Don't use these directly -- they're not guaranteed to
+ be there. */
+extern short __zt_mulaw[256];
+extern u_char __zt_lin2mu[16384];
+
+/* Used privately by zaptel. Avoid touching directly */
+struct zt_tone {
+ int fac1;
+ int init_v2_1;
+ int init_v3_1;
+
+ int fac2;
+ int init_v2_2;
+ int init_v3_2;
+
+ int tonesamples; /* How long to play this tone before
+ going to the next (in samples) */
+ struct zt_tone *next; /* Next tone in this sequence */
+};
+
+static inline short zt_tone_nextsample(struct zt_tone_state *ts, struct zt_tone *zt)
+{
+ /* follow the curves, return the sum */
+
+ ts->v1_1 = ts->v2_1;
+ ts->v2_1 = ts->v3_1;
+ ts->v3_1 = (zt->fac1 * ts->v2_1 >> 15) - ts->v1_1;
+
+ ts->v1_2 = ts->v2_2;
+ ts->v2_2 = ts->v3_2;
+ ts->v3_2 = (zt->fac2 * ts->v2_2 >> 15) - ts->v1_2;
+
+ /* Return top 16 bits */
+ return ts->v3_1 + ts->v3_2;
+}
+
+/* These are the right functions to use. */
+
+#define ZT_LIN2MU(a) (__zt_lin2mu[((unsigned short)(a)) >> 2])
+#define ZT_MULAW(a) (__zt_mulaw[(a)])
+
+#define ZT_LIN2A(a) (__zt_lin2a[((unsigned short)(a)) >> 2])
+#define ZT_ALAW(a) (__zt_alaw[(a)])
+
+/* Manipulate as appropriate for x-law */
+#define ZT_LIN2X(a,c) ((c)->lin2x[((unsigned short)(a)) >> 2])
+#define ZT_XLAW(a,c) (c->xlaw[(a)])
#endif