-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzaptel.c.echo_debug.patch
262 lines (258 loc) · 8.18 KB
/
zaptel.c.echo_debug.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
--- zaptel.c.orig 2005-12-29 11:24:30.000000000 -0500
+++ zaptel.c 2006-02-01 17:19:35.000000000 -0500
@@ -299,6 +299,7 @@
#include "digits.h"
static int zt_chan_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long data, int unit);
+static void zt_ec_chunk_spike_store(struct zt_chan *ss, unsigned char *rxchunk);
#if defined(CONFIG_ZAPTEL_MMX) || defined(ECHO_CAN_FP)
/* XXX kernel_fpu_begin() is NOT exported properly (in 2.4), so we have to make
@@ -1704,6 +1705,7 @@
unsigned long flags;
struct zt_chan *chan = chans[unit];
int res, amnt, oldbuf, rv,x;
+
/* Make sure count never exceeds 65k, and make sure it's unsigned */
count &= 0xffff;
if (!chan)
@@ -4147,11 +4149,20 @@
tec = chan->ec;
chan->ec = NULL;
/* Attempt hardware native echo can */
- if (chan->span && chan->span->echocan)
+ if (chan->span && chan->span->echocan){
ret = chan->span->echocan(chan, j);
- else
+ }else{
ret = -ENOTTY;
- if (ret) {
+ }
+
+ if(!ret){
+ chan->echo_spike_struct.is_hw_ec_used = 1;
+ }else{
+ chan->echo_spike_struct.is_hw_ec_used = 0;
+ }
+
+ /* the Echo Spike code needs chan->ec to be initialized!! */
+ if (ret || 1) {
/* Use built-in echo can */
if ((j == 32) ||
(j == 64) ||
@@ -4171,6 +4182,8 @@
chan->echostate = ECHO_STATE_IDLE;
chan->echolastupdate = 0;
chan->echotimer = 0;
+ chan->echo_spike_struct.state_bits = ECHO_INITIAL_STATE;
+ chan->echo_spike_struct.sample_len_counter = 0;
echo_can_disable_detector_init(&chan->txecdis);
echo_can_disable_detector_init(&chan->rxecdis);
}
@@ -4328,6 +4341,83 @@
return -EINVAL;
break;
#endif
+
+ case GET_ECHO_SPIKE_SAMPLE:
+ if(chan->echo_spike_struct.sample_buffer){
+ unsigned char *tmp_ptr = (unsigned char*)data;
+
+ chan->echo_spike_struct.return_code = ECHO_OK;
+ chan->echo_spike_struct.spanno = chan->span->spanno;
+ chan->echo_spike_struct.echocancel = chan->echocancel;
+
+ if(chan->xlaw == __zt_mulaw){
+ chan->echo_spike_struct.law = ZT_LAW_MULAW;
+ }else{
+ chan->echo_spike_struct.law = ZT_LAW_ALAW;
+ }
+
+ /* first copy the 'echo_spike_struct_t' structure */
+ copy_to_user(tmp_ptr, &chan->echo_spike_struct, sizeof(echo_spike_struct_t));
+
+ /* second copy the data AFTER the 'echo_spike_struct_t' structure */
+ copy_to_user (&tmp_ptr[sizeof(echo_spike_struct_t)],
+ chan->echo_spike_struct.sample_buffer,
+ ECHO_SPIKE_SAMPLE_LEN);
+
+ /* free the sample buffer */
+ kfree(chan->echo_spike_struct.sample_buffer);
+ /* very important to set to NULL after deallocation!! */
+ chan->echo_spike_struct.sample_buffer = NULL;
+
+ chan->echo_spike_struct.state_bits = ECHO_INITIAL_STATE;
+ chan->echo_spike_struct.sample_len_counter = 0;
+ }else{
+ unsigned char *tmp_ptr = (unsigned char*)data;
+
+ chan->echo_spike_struct.return_code = ECHO_NO_ACTIVE_CALL_OR_EC_OFF;
+ /* copy the 'echo_spike_struct_t' structure */
+ copy_to_user(tmp_ptr, &chan->echo_spike_struct, sizeof(echo_spike_struct_t));
+ }
+ break;
+
+ case SEND_ECHO_SPIKE:
+ copy_from_user(&chan->echo_spike_struct, (void*)data, sizeof(echo_spike_struct_t));
+
+ /* allocate EchoTest buffer. OUSIDE of spin_lock. */
+ chan->echo_spike_struct.sample_buffer = kmalloc(ECHO_SPIKE_SAMPLE_LEN, GFP_KERNEL);
+ if (chan->echo_spike_struct.sample_buffer == NULL) {
+ printk(KERN_INFO "channo: %d: Failed to allocate %d bytes for EchoTest storage!!!\n",
+ chan->channo, ECHO_SPIKE_SAMPLE_LEN);
+ return -ENOMEM;
+ }
+
+ spin_lock_irqsave(&chan->lock, flags);
+ /* send echo spike */
+ if (chan->ec) {
+ chan->echo_spike_struct.return_code = ECHO_OK;
+
+ chan->echo_spike_struct.state_bits = ECHO_INITIAL_STATE;
+ chan->echo_spike_struct.sample_len_counter = 0;
+ /* these two lines will make zaptel to send the spike: */
+ chan->echostate = ECHO_STATE_PRETRAINING;
+ chan->echotimer = 2048; /*Number of silence bytes to transmit before the spike.
+ It makes the line clean from noise, so spike is easy
+ to detect on return.*/
+ }else{
+ printk(KERN_INFO "channo: %d: SEND_ECHO_SPIKE: chan->ec is NULL!!\n",
+ chan->channo);
+
+ chan->echo_spike_struct.return_code = ECHO_NO_ACTIVE_CALL_OR_EC_OFF;
+ }
+ /* Must unlock here, BEFORE copy_to_user() call.
+ Or will get warnings from the kernel. */
+ spin_unlock_irqrestore(&chan->lock, flags);
+
+ /* copy the 'echo_spike_struct_t' structure back to user. so return_code
+ can be accessed. */
+ copy_to_user((void*)data, &chan->echo_spike_struct, sizeof(echo_spike_struct_t));
+ break;
+
default:
return zt_chanandpseudo_ioctl(inode, file, cmd, data, unit);
}
@@ -4343,6 +4433,7 @@
if (chan) {
printk("Huh? Prechan already has private data??\n");
}
+
switch(cmd) {
case ZT_SPECIFY:
get_user(channo,(int *)data);
@@ -4382,10 +4473,26 @@
}
if (unit == 254) {
chan = file->private_data;
- if (chan)
+ if (chan){
return zt_chan_ioctl(inode, file, cmd, data, chan->channo);
- else
- return zt_prechan_ioctl(inode, file, cmd, data, unit);
+ }else{
+ int channo;
+
+ switch(cmd)
+ {
+ case GET_ECHO_SPIKE_SAMPLE:
+ case SEND_ECHO_SPIKE:
+ get_user(channo,(int *)data);
+
+ if (channo < 1 || channo > ZT_MAX_CHANNELS){
+ printk(KERN_INFO "Invalid channel %d!!\n", channo);
+ return -EINVAL;
+ }
+ return zt_chan_ioctl(inode, file, cmd, data, channo);
+ default:
+ return zt_prechan_ioctl(inode, file, cmd, data, unit);
+ }
+ }
}
if (unit == 255) {
chan = file->private_data;
@@ -5416,7 +5523,13 @@
short rxlin, txlin;
int x;
unsigned long flags;
+
spin_lock_irqsave(&ss->lock, flags);
+
+ if(ss->echo_spike_struct.collect_sample_before_ec == 1){
+ zt_ec_chunk_spike_store(ss, rxchunk);
+ }
+
/* Perform echo cancellation on a chunk if necessary */
if (ss->ec) {
#if defined(CONFIG_ZAPTEL_MMX) || defined(ECHO_CAN_FP)
@@ -5436,8 +5549,13 @@
if ((ss->echostate == ECHO_STATE_AWAITINGECHO) && (txlin > 8000)) {
ss->echolastupdate = 0;
ss->echostate = ECHO_STATE_TRAINING;
+
+ if(ss->echo_spike_struct.state_bits == ECHO_INITIAL_STATE){
+ ss->echo_spike_struct.state_bits = ECHO_BUSY_COLLECTING_SAMPLE;
+ ss->echo_spike_struct.sample_len_counter = 0;
+ }
}
- if (ss->echostate == ECHO_STATE_TRAINING) {
+ if (ss->echostate == ECHO_STATE_TRAINING){
if (echo_can_traintap(ss->ec, ss->echolastupdate++, rxlin)) {
#if 0
printk("Finished training (%d taps trained)!\n", ss->echolastupdate);
@@ -5449,16 +5567,20 @@
rxchunk[x] = ZT_LIN2X((int)rxlin, ss);
}
} else {
- for (x=0;x<ZT_CHUNKSIZE;x++) {
- rxlin = ZT_XLAW(rxchunk[x], ss);
- rxlin = echo_can_update(ss->ec, ZT_XLAW(txchunk[x], ss), rxlin);
- rxchunk[x] = ZT_LIN2X((int)rxlin, ss);
+ if(ss->echo_spike_struct.is_hw_ec_used == 0){
+ for (x=0;x<ZT_CHUNKSIZE;x++) {
+ rxlin = ZT_XLAW(rxchunk[x], ss);
+ rxlin = echo_can_update(ss->ec, ZT_XLAW(txchunk[x], ss), rxlin);
+ rxchunk[x] = ZT_LIN2X((int)rxlin, ss);
+ }
}
}
+
#if defined(CONFIG_ZAPTEL_MMX) || defined(ECHO_CAN_FP)
kernel_fpu_end();
#endif
}
+
spin_unlock_irqrestore(&ss->lock, flags);
}
@@ -6591,3 +6713,34 @@
module_init(zt_init);
module_exit(zt_cleanup);
+
+static void zt_ec_chunk_spike_store(struct zt_chan *ss, unsigned char *rxchunk)
+{
+ int x;
+
+ if(ss->echo_spike_struct.state_bits != ECHO_BUSY_COLLECTING_SAMPLE ||
+ ss->echo_spike_struct.sample_buffer == NULL){
+ return;
+ }
+
+ /* check input values */
+ if(ss->echo_spike_struct.sample_len_counter >= ECHO_SPIKE_SAMPLE_LEN){
+ printk(KERN_INFO "chan: %d: Invalid sample_len_counter! (%d)\n",
+ ss->channo, ss->echo_spike_struct.sample_len_counter);
+ return;
+ }
+
+ if(ss->echo_spike_struct.state_bits == ECHO_BUSY_COLLECTING_SAMPLE){
+ for (x = 0; x < ZT_CHUNKSIZE; x++) {
+ ss->echo_spike_struct.sample_buffer[ss->echo_spike_struct.sample_len_counter] =
+ rxchunk[x];
+ ss->echo_spike_struct.sample_len_counter++;
+ if(ss->echo_spike_struct.sample_len_counter >= ECHO_SPIKE_SAMPLE_LEN){
+ /* finished collecting the sample */
+ ss->echo_spike_struct.state_bits = ECHO_FINISHED_COLLECTING_SAMPLE;
+ break;
+ }/*if()*/
+ }/*for()*/
+ }/*if()*/
+}
+