blob: fc1733a088459e2ae27479ca75f6e343ac4b3a0b [file] [log] [blame]
Karsten Keil960366c2008-07-27 01:56:38 +02001/*
2 * Audio support data for ISDN4Linux.
3 *
4 * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu)
5 *
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
8 *
9 */
10
11#define DEBUG_DSP_CTRL 0x0001
12#define DEBUG_DSP_CORE 0x0002
13#define DEBUG_DSP_DTMF 0x0004
14#define DEBUG_DSP_CMX 0x0010
15#define DEBUG_DSP_TONE 0x0020
16#define DEBUG_DSP_BLOWFISH 0x0040
17#define DEBUG_DSP_DELAY 0x0100
Andreas Eversberg190f71d2008-08-03 10:36:53 +020018#define DEBUG_DSP_CLOCK 0x0200
Karsten Keil960366c2008-07-27 01:56:38 +020019#define DEBUG_DSP_DTMFCOEFF 0x8000 /* heavy output */
20
21/* options may be:
22 *
23 * bit 0 = use ulaw instead of alaw
Lucas De Marchi25985ed2011-03-30 22:57:33 -030024 * bit 1 = enable hfc hardware acceleration for all channels
Karsten Keil960366c2008-07-27 01:56:38 +020025 *
26 */
Joe Perches475be4d2012-02-19 19:52:38 -080027#define DSP_OPT_ULAW (1 << 0)
28#define DSP_OPT_NOHARDWARE (1 << 1)
Karsten Keil960366c2008-07-27 01:56:38 +020029
30#include <linux/timer.h>
31#include <linux/workqueue.h>
32
33#include "dsp_ecdis.h"
34
35extern int dsp_options;
36extern int dsp_debug;
37extern int dsp_poll;
38extern int dsp_tics;
39extern spinlock_t dsp_lock;
40extern struct work_struct dsp_workq;
41extern u32 dsp_poll_diff; /* calculated fix-comma corrected poll value */
42
43/***************
44 * audio stuff *
45 ***************/
46
47extern s32 dsp_audio_alaw_to_s32[256];
48extern s32 dsp_audio_ulaw_to_s32[256];
49extern s32 *dsp_audio_law_to_s32;
50extern u8 dsp_audio_s16_to_law[65536];
51extern u8 dsp_audio_alaw_to_ulaw[256];
52extern u8 dsp_audio_mix_law[65536];
53extern u8 dsp_audio_seven2law[128];
54extern u8 dsp_audio_law2seven[256];
55extern void dsp_audio_generate_law_tables(void);
56extern void dsp_audio_generate_s2law_table(void);
57extern void dsp_audio_generate_seven(void);
58extern void dsp_audio_generate_mix_table(void);
59extern void dsp_audio_generate_ulaw_samples(void);
60extern void dsp_audio_generate_volume_changes(void);
61extern u8 dsp_silence;
62
63
64/*************
65 * cmx stuff *
66 *************/
67
68#define MAX_POLL 256 /* maximum number of send-chunks */
69
70#define CMX_BUFF_SIZE 0x8000 /* must be 2**n (0x1000 about 1/2 second) */
71#define CMX_BUFF_HALF 0x4000 /* CMX_BUFF_SIZE / 2 */
72#define CMX_BUFF_MASK 0x7fff /* CMX_BUFF_SIZE - 1 */
73
74/* how many seconds will we check the lowest delay until the jitter buffer
75 is reduced by that delay */
76#define MAX_SECONDS_JITTER_CHECK 5
77
78extern struct timer_list dsp_spl_tl;
Karsten Keil9cf6ace2012-04-25 20:54:48 +000079
80/* the datatype need to match jiffies datatype */
81extern unsigned long dsp_spl_jiffies;
Karsten Keil960366c2008-07-27 01:56:38 +020082
83/* the structure of conferences:
84 *
85 * each conference has a unique number, given by user space.
86 * the conferences are linked in a chain.
87 * each conference has members linked in a chain.
88 * each dsplayer points to a member, each member points to a dsplayer.
89 */
90
91/* all members within a conference (this is linked 1:1 with the dsp) */
92struct dsp;
93struct dsp_conf_member {
94 struct list_head list;
95 struct dsp *dsp;
96};
97
98/* the list of all conferences */
99struct dsp_conf {
100 struct list_head list;
101 u32 id;
Joe Perches475be4d2012-02-19 19:52:38 -0800102 /* all cmx stacks with the same ID are
103 connected */
Karsten Keil960366c2008-07-27 01:56:38 +0200104 struct list_head mlist;
105 int software; /* conf is processed by software */
106 int hardware; /* conf is processed by hardware */
Joe Perches475be4d2012-02-19 19:52:38 -0800107 /* note: if both unset, has only one member */
Karsten Keil960366c2008-07-27 01:56:38 +0200108};
109
110
111/**************
112 * DTMF stuff *
113 **************/
114
115#define DSP_DTMF_NPOINTS 102
116
Andreas Eversberga5355c22009-05-22 11:04:45 +0000117#define ECHOCAN_BUFF_SIZE 0x400 /* must be 2**n */
118#define ECHOCAN_BUFF_MASK 0x3ff /* -1 */
Karsten Keil960366c2008-07-27 01:56:38 +0200119
120struct dsp_dtmf {
Andreas Eversbergb0579d72009-05-22 11:04:58 +0000121 int enable; /* dtmf is enabled */
Karsten Keil960366c2008-07-27 01:56:38 +0200122 int treshold; /* above this is dtmf (square of) */
123 int software; /* dtmf uses software decoding */
124 int hardware; /* dtmf uses hardware decoding */
125 int size; /* number of bytes in buffer */
126 signed short buffer[DSP_DTMF_NPOINTS];
Joe Perches475be4d2012-02-19 19:52:38 -0800127 /* buffers one full dtmf frame */
Karsten Keil960366c2008-07-27 01:56:38 +0200128 u8 lastwhat, lastdigit;
129 int count;
Andreas Eversbergb5df5a52009-05-22 11:04:48 +0000130 u8 digits[16]; /* dtmf result */
Karsten Keil960366c2008-07-27 01:56:38 +0200131};
132
133
134/******************
135 * pipeline stuff *
136 ******************/
137struct dsp_pipeline {
138 rwlock_t lock;
139 struct list_head list;
140 int inuse;
141};
142
143/***************
144 * tones stuff *
145 ***************/
146
147struct dsp_tone {
148 int software; /* tones are generated by software */
149 int hardware; /* tones are generated by hardware */
150 int tone;
151 void *pattern;
152 int count;
153 int index;
154 struct timer_list tl;
155};
156
Andreas Eversbergbc138ec2009-05-22 11:04:49 +0000157/***************
158 * echo stuff *
159 ***************/
160
161struct dsp_echo {
162 int software; /* echo is generated by software */
163 int hardware; /* echo is generated by hardware */
164};
165
Karsten Keil960366c2008-07-27 01:56:38 +0200166/*****************
167 * general stuff *
168 *****************/
169
170struct dsp {
171 struct list_head list;
172 struct mISDNchannel ch;
173 struct mISDNchannel *up;
174 unsigned char name[64];
175 int b_active;
Andreas Eversbergbc138ec2009-05-22 11:04:49 +0000176 struct dsp_echo echo;
Karsten Keil960366c2008-07-27 01:56:38 +0200177 int rx_disabled; /* what the user wants */
178 int rx_is_off; /* what the card is */
179 int tx_mix;
180 struct dsp_tone tone;
181 struct dsp_dtmf dtmf;
182 int tx_volume, rx_volume;
183
184 /* queue for sending frames */
185 struct work_struct workq;
186 struct sk_buff_head sendq;
187 int hdlc; /* if mode is hdlc */
188 int data_pending; /* currently an unconfirmed frame */
189
190 /* conference stuff */
191 u32 conf_id;
192 struct dsp_conf *conf;
193 struct dsp_conf_member
Joe Perches475be4d2012-02-19 19:52:38 -0800194 *member;
Karsten Keil960366c2008-07-27 01:56:38 +0200195
196 /* buffer stuff */
197 int rx_W; /* current write pos for data without timestamp */
198 int rx_R; /* current read pos for transmit clock */
199 int rx_init; /* if set, pointers will be adjusted first */
200 int tx_W; /* current write pos for transmit data */
201 int tx_R; /* current read pos for transmit clock */
202 int rx_delay[MAX_SECONDS_JITTER_CHECK];
203 int tx_delay[MAX_SECONDS_JITTER_CHECK];
204 u8 tx_buff[CMX_BUFF_SIZE];
205 u8 rx_buff[CMX_BUFF_SIZE];
206 int last_tx; /* if set, we transmitted last poll interval */
207 int cmx_delay; /* initial delay of buffers,
Joe Perches475be4d2012-02-19 19:52:38 -0800208 or 0 for dynamic jitter buffer */
Karsten Keil960366c2008-07-27 01:56:38 +0200209 int tx_dejitter; /* if set, dejitter tx buffer */
210 int tx_data; /* enables tx-data of CMX to upper layer */
211
212 /* hardware stuff */
213 struct dsp_features features;
214 int features_rx_off; /* set if rx_off is featured */
Andreas Eversberg8dd2f362008-08-02 22:51:52 +0200215 int features_fill_empty; /* set if fill_empty is featured */
Karsten Keil960366c2008-07-27 01:56:38 +0200216 int pcm_slot_rx; /* current PCM slot (or -1) */
217 int pcm_bank_rx;
218 int pcm_slot_tx;
219 int pcm_bank_tx;
220 int hfc_conf; /* unique id of current conference (or -1) */
221
222 /* encryption stuff */
223 int bf_enable;
224 u32 bf_p[18];
225 u32 bf_s[1024];
226 int bf_crypt_pos;
227 u8 bf_data_in[9];
228 u8 bf_crypt_out[9];
229 int bf_decrypt_in_pos;
230 int bf_decrypt_out_pos;
231 u8 bf_crypt_inring[16];
232 u8 bf_data_out[9];
233 int bf_sync;
234
235 struct dsp_pipeline
Joe Perches475be4d2012-02-19 19:52:38 -0800236 pipeline;
Karsten Keil960366c2008-07-27 01:56:38 +0200237};
238
239/* functions */
240
241extern void dsp_change_volume(struct sk_buff *skb, int volume);
242
243extern struct list_head dsp_ilist;
244extern struct list_head conf_ilist;
245extern void dsp_cmx_debug(struct dsp *dsp);
246extern void dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp);
247extern int dsp_cmx_conf(struct dsp *dsp, u32 conf_id);
248extern void dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb);
249extern void dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb);
250extern void dsp_cmx_send(void *arg);
251extern void dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb);
252extern int dsp_cmx_del_conf_member(struct dsp *dsp);
253extern int dsp_cmx_del_conf(struct dsp_conf *conf);
254
255extern void dsp_dtmf_goertzel_init(struct dsp *dsp);
256extern void dsp_dtmf_hardware(struct dsp *dsp);
257extern u8 *dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 *data, int len,
Joe Perches475be4d2012-02-19 19:52:38 -0800258 int fmt);
Karsten Keil960366c2008-07-27 01:56:38 +0200259
260extern int dsp_tone(struct dsp *dsp, int tone);
261extern void dsp_tone_copy(struct dsp *dsp, u8 *data, int len);
262extern void dsp_tone_timeout(void *arg);
263
264extern void dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len);
265extern void dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len);
266extern int dsp_bf_init(struct dsp *dsp, const u8 *key, unsigned int keylen);
267extern void dsp_bf_cleanup(struct dsp *dsp);
268
269extern int dsp_pipeline_module_init(void);
270extern void dsp_pipeline_module_exit(void);
271extern int dsp_pipeline_init(struct dsp_pipeline *pipeline);
272extern void dsp_pipeline_destroy(struct dsp_pipeline *pipeline);
273extern int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg);
274extern void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data,
Joe Perches475be4d2012-02-19 19:52:38 -0800275 int len);
Karsten Keil960366c2008-07-27 01:56:38 +0200276extern void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data,
Joe Perches475be4d2012-02-19 19:52:38 -0800277 int len, unsigned int txlen);