1960366cfSKarsten Keil /* 2960366cfSKarsten Keil * Audio support data for ISDN4Linux. 3960366cfSKarsten Keil * 4960366cfSKarsten Keil * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu) 5960366cfSKarsten Keil * 6960366cfSKarsten Keil * This software may be used and distributed according to the terms 7960366cfSKarsten Keil * of the GNU General Public License, incorporated herein by reference. 8960366cfSKarsten Keil * 9960366cfSKarsten Keil */ 10960366cfSKarsten Keil 11960366cfSKarsten Keil #define DEBUG_DSP_CTRL 0x0001 12960366cfSKarsten Keil #define DEBUG_DSP_CORE 0x0002 13960366cfSKarsten Keil #define DEBUG_DSP_DTMF 0x0004 14960366cfSKarsten Keil #define DEBUG_DSP_CMX 0x0010 15960366cfSKarsten Keil #define DEBUG_DSP_TONE 0x0020 16960366cfSKarsten Keil #define DEBUG_DSP_BLOWFISH 0x0040 17960366cfSKarsten Keil #define DEBUG_DSP_DELAY 0x0100 18960366cfSKarsten Keil #define DEBUG_DSP_DTMFCOEFF 0x8000 /* heavy output */ 19960366cfSKarsten Keil 20960366cfSKarsten Keil /* options may be: 21960366cfSKarsten Keil * 22960366cfSKarsten Keil * bit 0 = use ulaw instead of alaw 23960366cfSKarsten Keil * bit 1 = enable hfc hardware accelleration for all channels 24960366cfSKarsten Keil * 25960366cfSKarsten Keil */ 26960366cfSKarsten Keil #define DSP_OPT_ULAW (1<<0) 27960366cfSKarsten Keil #define DSP_OPT_NOHARDWARE (1<<1) 28960366cfSKarsten Keil 29960366cfSKarsten Keil #include <linux/timer.h> 30960366cfSKarsten Keil #include <linux/workqueue.h> 31960366cfSKarsten Keil 32960366cfSKarsten Keil #include "dsp_ecdis.h" 33960366cfSKarsten Keil 34960366cfSKarsten Keil extern int dsp_options; 35960366cfSKarsten Keil extern int dsp_debug; 36960366cfSKarsten Keil extern int dsp_poll; 37960366cfSKarsten Keil extern int dsp_tics; 38960366cfSKarsten Keil extern spinlock_t dsp_lock; 39960366cfSKarsten Keil extern struct work_struct dsp_workq; 40960366cfSKarsten Keil extern u32 dsp_poll_diff; /* calculated fix-comma corrected poll value */ 41960366cfSKarsten Keil 42960366cfSKarsten Keil /*************** 43960366cfSKarsten Keil * audio stuff * 44960366cfSKarsten Keil ***************/ 45960366cfSKarsten Keil 46960366cfSKarsten Keil extern s32 dsp_audio_alaw_to_s32[256]; 47960366cfSKarsten Keil extern s32 dsp_audio_ulaw_to_s32[256]; 48960366cfSKarsten Keil extern s32 *dsp_audio_law_to_s32; 49960366cfSKarsten Keil extern u8 dsp_audio_s16_to_law[65536]; 50960366cfSKarsten Keil extern u8 dsp_audio_alaw_to_ulaw[256]; 51960366cfSKarsten Keil extern u8 dsp_audio_mix_law[65536]; 52960366cfSKarsten Keil extern u8 dsp_audio_seven2law[128]; 53960366cfSKarsten Keil extern u8 dsp_audio_law2seven[256]; 54960366cfSKarsten Keil extern void dsp_audio_generate_law_tables(void); 55960366cfSKarsten Keil extern void dsp_audio_generate_s2law_table(void); 56960366cfSKarsten Keil extern void dsp_audio_generate_seven(void); 57960366cfSKarsten Keil extern void dsp_audio_generate_mix_table(void); 58960366cfSKarsten Keil extern void dsp_audio_generate_ulaw_samples(void); 59960366cfSKarsten Keil extern void dsp_audio_generate_volume_changes(void); 60960366cfSKarsten Keil extern u8 dsp_silence; 61960366cfSKarsten Keil 62960366cfSKarsten Keil 63960366cfSKarsten Keil /************* 64960366cfSKarsten Keil * cmx stuff * 65960366cfSKarsten Keil *************/ 66960366cfSKarsten Keil 67960366cfSKarsten Keil #define MAX_POLL 256 /* maximum number of send-chunks */ 68960366cfSKarsten Keil 69960366cfSKarsten Keil #define CMX_BUFF_SIZE 0x8000 /* must be 2**n (0x1000 about 1/2 second) */ 70960366cfSKarsten Keil #define CMX_BUFF_HALF 0x4000 /* CMX_BUFF_SIZE / 2 */ 71960366cfSKarsten Keil #define CMX_BUFF_MASK 0x7fff /* CMX_BUFF_SIZE - 1 */ 72960366cfSKarsten Keil 73960366cfSKarsten Keil /* how many seconds will we check the lowest delay until the jitter buffer 74960366cfSKarsten Keil is reduced by that delay */ 75960366cfSKarsten Keil #define MAX_SECONDS_JITTER_CHECK 5 76960366cfSKarsten Keil 77960366cfSKarsten Keil extern struct timer_list dsp_spl_tl; 78960366cfSKarsten Keil extern u32 dsp_spl_jiffies; 79960366cfSKarsten Keil 80960366cfSKarsten Keil /* the structure of conferences: 81960366cfSKarsten Keil * 82960366cfSKarsten Keil * each conference has a unique number, given by user space. 83960366cfSKarsten Keil * the conferences are linked in a chain. 84960366cfSKarsten Keil * each conference has members linked in a chain. 85960366cfSKarsten Keil * each dsplayer points to a member, each member points to a dsplayer. 86960366cfSKarsten Keil */ 87960366cfSKarsten Keil 88960366cfSKarsten Keil /* all members within a conference (this is linked 1:1 with the dsp) */ 89960366cfSKarsten Keil struct dsp; 90960366cfSKarsten Keil struct dsp_conf_member { 91960366cfSKarsten Keil struct list_head list; 92960366cfSKarsten Keil struct dsp *dsp; 93960366cfSKarsten Keil }; 94960366cfSKarsten Keil 95960366cfSKarsten Keil /* the list of all conferences */ 96960366cfSKarsten Keil struct dsp_conf { 97960366cfSKarsten Keil struct list_head list; 98960366cfSKarsten Keil u32 id; 99960366cfSKarsten Keil /* all cmx stacks with the same ID are 100960366cfSKarsten Keil connected */ 101960366cfSKarsten Keil struct list_head mlist; 102960366cfSKarsten Keil int software; /* conf is processed by software */ 103960366cfSKarsten Keil int hardware; /* conf is processed by hardware */ 104960366cfSKarsten Keil /* note: if both unset, has only one member */ 105960366cfSKarsten Keil }; 106960366cfSKarsten Keil 107960366cfSKarsten Keil 108960366cfSKarsten Keil /************** 109960366cfSKarsten Keil * DTMF stuff * 110960366cfSKarsten Keil **************/ 111960366cfSKarsten Keil 112960366cfSKarsten Keil #define DSP_DTMF_NPOINTS 102 113960366cfSKarsten Keil 114960366cfSKarsten Keil #define ECHOCAN_BUFLEN (4*128) 115960366cfSKarsten Keil 116960366cfSKarsten Keil struct dsp_dtmf { 117960366cfSKarsten Keil int treshold; /* above this is dtmf (square of) */ 118960366cfSKarsten Keil int software; /* dtmf uses software decoding */ 119960366cfSKarsten Keil int hardware; /* dtmf uses hardware decoding */ 120960366cfSKarsten Keil int size; /* number of bytes in buffer */ 121960366cfSKarsten Keil signed short buffer[DSP_DTMF_NPOINTS]; 122960366cfSKarsten Keil /* buffers one full dtmf frame */ 123960366cfSKarsten Keil u8 lastwhat, lastdigit; 124960366cfSKarsten Keil int count; 125960366cfSKarsten Keil u8 digits[16]; /* just the dtmf result */ 126960366cfSKarsten Keil }; 127960366cfSKarsten Keil 128960366cfSKarsten Keil 129960366cfSKarsten Keil /****************** 130960366cfSKarsten Keil * pipeline stuff * 131960366cfSKarsten Keil ******************/ 132960366cfSKarsten Keil struct dsp_pipeline { 133960366cfSKarsten Keil rwlock_t lock; 134960366cfSKarsten Keil struct list_head list; 135960366cfSKarsten Keil int inuse; 136960366cfSKarsten Keil }; 137960366cfSKarsten Keil 138960366cfSKarsten Keil /*************** 139960366cfSKarsten Keil * tones stuff * 140960366cfSKarsten Keil ***************/ 141960366cfSKarsten Keil 142960366cfSKarsten Keil struct dsp_tone { 143960366cfSKarsten Keil int software; /* tones are generated by software */ 144960366cfSKarsten Keil int hardware; /* tones are generated by hardware */ 145960366cfSKarsten Keil int tone; 146960366cfSKarsten Keil void *pattern; 147960366cfSKarsten Keil int count; 148960366cfSKarsten Keil int index; 149960366cfSKarsten Keil struct timer_list tl; 150960366cfSKarsten Keil }; 151960366cfSKarsten Keil 152960366cfSKarsten Keil /***************** 153960366cfSKarsten Keil * general stuff * 154960366cfSKarsten Keil *****************/ 155960366cfSKarsten Keil 156960366cfSKarsten Keil struct dsp { 157960366cfSKarsten Keil struct list_head list; 158960366cfSKarsten Keil struct mISDNchannel ch; 159960366cfSKarsten Keil struct mISDNchannel *up; 160960366cfSKarsten Keil unsigned char name[64]; 161960366cfSKarsten Keil int b_active; 162960366cfSKarsten Keil int echo; /* echo is enabled */ 163960366cfSKarsten Keil int rx_disabled; /* what the user wants */ 164960366cfSKarsten Keil int rx_is_off; /* what the card is */ 165960366cfSKarsten Keil int tx_mix; 166960366cfSKarsten Keil struct dsp_tone tone; 167960366cfSKarsten Keil struct dsp_dtmf dtmf; 168960366cfSKarsten Keil int tx_volume, rx_volume; 169960366cfSKarsten Keil 170960366cfSKarsten Keil /* queue for sending frames */ 171960366cfSKarsten Keil struct work_struct workq; 172960366cfSKarsten Keil struct sk_buff_head sendq; 173960366cfSKarsten Keil int hdlc; /* if mode is hdlc */ 174960366cfSKarsten Keil int data_pending; /* currently an unconfirmed frame */ 175960366cfSKarsten Keil 176960366cfSKarsten Keil /* conference stuff */ 177960366cfSKarsten Keil u32 conf_id; 178960366cfSKarsten Keil struct dsp_conf *conf; 179960366cfSKarsten Keil struct dsp_conf_member 180960366cfSKarsten Keil *member; 181960366cfSKarsten Keil 182960366cfSKarsten Keil /* buffer stuff */ 183960366cfSKarsten Keil int rx_W; /* current write pos for data without timestamp */ 184960366cfSKarsten Keil int rx_R; /* current read pos for transmit clock */ 185960366cfSKarsten Keil int rx_init; /* if set, pointers will be adjusted first */ 186960366cfSKarsten Keil int tx_W; /* current write pos for transmit data */ 187960366cfSKarsten Keil int tx_R; /* current read pos for transmit clock */ 188960366cfSKarsten Keil int rx_delay[MAX_SECONDS_JITTER_CHECK]; 189960366cfSKarsten Keil int tx_delay[MAX_SECONDS_JITTER_CHECK]; 190960366cfSKarsten Keil u8 tx_buff[CMX_BUFF_SIZE]; 191960366cfSKarsten Keil u8 rx_buff[CMX_BUFF_SIZE]; 192960366cfSKarsten Keil int last_tx; /* if set, we transmitted last poll interval */ 193960366cfSKarsten Keil int cmx_delay; /* initial delay of buffers, 194960366cfSKarsten Keil or 0 for dynamic jitter buffer */ 195960366cfSKarsten Keil int tx_dejitter; /* if set, dejitter tx buffer */ 196960366cfSKarsten Keil int tx_data; /* enables tx-data of CMX to upper layer */ 197960366cfSKarsten Keil 198960366cfSKarsten Keil /* hardware stuff */ 199960366cfSKarsten Keil struct dsp_features features; 200960366cfSKarsten Keil int features_rx_off; /* set if rx_off is featured */ 201*8dd2f36fSAndreas Eversberg int features_fill_empty; /* set if fill_empty is featured */ 202960366cfSKarsten Keil int pcm_slot_rx; /* current PCM slot (or -1) */ 203960366cfSKarsten Keil int pcm_bank_rx; 204960366cfSKarsten Keil int pcm_slot_tx; 205960366cfSKarsten Keil int pcm_bank_tx; 206960366cfSKarsten Keil int hfc_conf; /* unique id of current conference (or -1) */ 207960366cfSKarsten Keil 208960366cfSKarsten Keil /* encryption stuff */ 209960366cfSKarsten Keil int bf_enable; 210960366cfSKarsten Keil u32 bf_p[18]; 211960366cfSKarsten Keil u32 bf_s[1024]; 212960366cfSKarsten Keil int bf_crypt_pos; 213960366cfSKarsten Keil u8 bf_data_in[9]; 214960366cfSKarsten Keil u8 bf_crypt_out[9]; 215960366cfSKarsten Keil int bf_decrypt_in_pos; 216960366cfSKarsten Keil int bf_decrypt_out_pos; 217960366cfSKarsten Keil u8 bf_crypt_inring[16]; 218960366cfSKarsten Keil u8 bf_data_out[9]; 219960366cfSKarsten Keil int bf_sync; 220960366cfSKarsten Keil 221960366cfSKarsten Keil struct dsp_pipeline 222960366cfSKarsten Keil pipeline; 223960366cfSKarsten Keil }; 224960366cfSKarsten Keil 225960366cfSKarsten Keil /* functions */ 226960366cfSKarsten Keil 227960366cfSKarsten Keil extern void dsp_change_volume(struct sk_buff *skb, int volume); 228960366cfSKarsten Keil 229960366cfSKarsten Keil extern struct list_head dsp_ilist; 230960366cfSKarsten Keil extern struct list_head conf_ilist; 231960366cfSKarsten Keil extern void dsp_cmx_debug(struct dsp *dsp); 232960366cfSKarsten Keil extern void dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp); 233960366cfSKarsten Keil extern int dsp_cmx_conf(struct dsp *dsp, u32 conf_id); 234960366cfSKarsten Keil extern void dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb); 235960366cfSKarsten Keil extern void dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb); 236960366cfSKarsten Keil extern void dsp_cmx_send(void *arg); 237960366cfSKarsten Keil extern void dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb); 238960366cfSKarsten Keil extern int dsp_cmx_del_conf_member(struct dsp *dsp); 239960366cfSKarsten Keil extern int dsp_cmx_del_conf(struct dsp_conf *conf); 240960366cfSKarsten Keil 241960366cfSKarsten Keil extern void dsp_dtmf_goertzel_init(struct dsp *dsp); 242960366cfSKarsten Keil extern void dsp_dtmf_hardware(struct dsp *dsp); 243960366cfSKarsten Keil extern u8 *dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 *data, int len, 244960366cfSKarsten Keil int fmt); 245960366cfSKarsten Keil 246960366cfSKarsten Keil extern int dsp_tone(struct dsp *dsp, int tone); 247960366cfSKarsten Keil extern void dsp_tone_copy(struct dsp *dsp, u8 *data, int len); 248960366cfSKarsten Keil extern void dsp_tone_timeout(void *arg); 249960366cfSKarsten Keil 250960366cfSKarsten Keil extern void dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len); 251960366cfSKarsten Keil extern void dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len); 252960366cfSKarsten Keil extern int dsp_bf_init(struct dsp *dsp, const u8 *key, unsigned int keylen); 253960366cfSKarsten Keil extern void dsp_bf_cleanup(struct dsp *dsp); 254960366cfSKarsten Keil 255960366cfSKarsten Keil extern int dsp_pipeline_module_init(void); 256960366cfSKarsten Keil extern void dsp_pipeline_module_exit(void); 257960366cfSKarsten Keil extern int dsp_pipeline_init(struct dsp_pipeline *pipeline); 258960366cfSKarsten Keil extern void dsp_pipeline_destroy(struct dsp_pipeline *pipeline); 259960366cfSKarsten Keil extern int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg); 260960366cfSKarsten Keil extern void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data, 261960366cfSKarsten Keil int len); 262960366cfSKarsten Keil extern void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data, 263960366cfSKarsten Keil int len); 264960366cfSKarsten Keil 265