summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdigits.h55
-rwxr-xr-xzaptel.h147
2 files changed, 141 insertions, 61 deletions
diff --git a/digits.h b/digits.h
index 227f4b7..61e657c 100755
--- a/digits.h
+++ b/digits.h
@@ -20,69 +20,22 @@
#ifndef _DIGITS_H
#define _DIGITS_H
-#include "tones.h"
-
#define DEFAULT_DTMF_LENGTH 100 * 8
#define DEFAULT_MFV1_LENGTH 60 * 8
#define PAUSE_LENGTH 500 * 8
-static unsigned char silence[40] =
-{ 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
- 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
- 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
- 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
- 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f };
-
/* At the end of silence, the tone stops */
static struct zt_tone dtmf_silence =
- { silence, sizeof(silence), DEFAULT_DTMF_LENGTH, NULL };
+ { 0, 0, 0, 0, 0, 0, DEFAULT_DTMF_LENGTH, NULL };
/* At the end of silence, the tone stops */
static struct zt_tone mfv1_silence =
- { silence, sizeof(silence), DEFAULT_MFV1_LENGTH, NULL };
+ { 0, 0, 0, 0, 0, 0, DEFAULT_MFV1_LENGTH, NULL };
/* A pause in the dialing */
static struct zt_tone tone_pause =
- { silence, sizeof(silence), PAUSE_LENGTH, NULL };
-
-static struct zt_tone dtmf_tones[16] =
-{
- { dtmf_0, sizeof(dtmf_0), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_1, sizeof(dtmf_1), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_2, sizeof(dtmf_2), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_3, sizeof(dtmf_3), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_4, sizeof(dtmf_4), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_5, sizeof(dtmf_5), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_6, sizeof(dtmf_6), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_7, sizeof(dtmf_7), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_8, sizeof(dtmf_8), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_9, sizeof(dtmf_9), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_s, sizeof(dtmf_s), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_p, sizeof(dtmf_p), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_A, sizeof(dtmf_A), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_B, sizeof(dtmf_B), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_C, sizeof(dtmf_C), DEFAULT_DTMF_LENGTH, &dtmf_silence },
- { dtmf_D, sizeof(dtmf_D), DEFAULT_DTMF_LENGTH, &dtmf_silence },
-};
-
-static struct zt_tone mfv1_tones[15] =
-{
- { mfv1_0, sizeof(mfv1_0), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_1, sizeof(mfv1_1), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_2, sizeof(mfv1_2), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_3, sizeof(mfv1_3), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_4, sizeof(mfv1_4), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_5, sizeof(mfv1_5), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_6, sizeof(mfv1_6), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_7, sizeof(mfv1_7), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_8, sizeof(mfv1_8), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_9, sizeof(mfv1_9), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_s, sizeof(mfv1_s), DEFAULT_MFV1_LENGTH * 5 / 3, &mfv1_silence },
- { mfv1_p, sizeof(mfv1_p), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_A, sizeof(mfv1_A), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_B, sizeof(mfv1_B), DEFAULT_MFV1_LENGTH, &mfv1_silence },
- { mfv1_C, sizeof(mfv1_C), DEFAULT_MFV1_LENGTH, &mfv1_silence },
-};
+ { 0, 0, 0, 0, 0, 0, PAUSE_LENGTH, NULL };
+#include "tones.h"
#endif
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