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
|
? asterisk_ukcid.diff
Index: channels/chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.344.2.7
diff -u -r1.344.2.7 chan_zap.c
--- channels/chan_zap.c 27 Oct 2004 14:41:55 -0000 1.344.2.7
+++ channels/chan_zap.c 4 Nov 2004 21:05:03 -0000
@@ -790,6 +790,14 @@
return 0;
}
+static int zt_get_history(int fd, void *buf, int buf_size)
+{
+ struct zt_history hist;
+ hist.buf=buf;
+ hist.len=buf_size;
+ return ioctl(fd, ZT_GET_HISTORY, &hist);
+}
+
static int alloc_sub(struct zt_pvt *p, int x)
{
ZT_BUFFERINFO bi;
@@ -5114,6 +5122,120 @@
}
}
#endif
+ /* If we're using an X100P in the UK, caller ID needs to be extracted from
+ * the history buffer */
+ if (p->use_callerid && p->cid_start == CID_START_USEHIST) {
+ ast_log(LOG_DEBUG,"Using history buffer to extract UK caller ID\n");
+ cs = callerid_new(cid_signalling);
+ if (cs) {
+ unsigned char cidbuf[16384];
+ res=0;
+
+ res = zt_get_history(p->subs[index].zfd,cidbuf,sizeof(cidbuf));
+ if(res<0) {
+ ast_log(LOG_ERROR,"zt_get_history failed: %s\n", strerror(errno));
+ } else {
+ res=callerid_feed(cs,cidbuf,sizeof(cidbuf),AST_LAW(p));
+ if (res < 0) {
+ ast_log(LOG_WARNING, "CallerID feed failed: %s\n", strerror(errno));
+ }
+ }
+
+ if(res==1) {
+ callerid_get(cs, &name, &number, &flags);
+ if (option_debug)
+ ast_log(LOG_DEBUG, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags);
+ }
+ }
+ if (p->usedistinctiveringdetection == 1) {
+#if 1
+ bump_gains(p);
+#endif
+ len = 0;
+ distMatches = 0;
+ /* Clear the current ring data array so we dont have old data in it. */
+ for (receivedRingT=0; receivedRingT < 3; receivedRingT++) {
+ curRingData[receivedRingT] = 0;
+ }
+ receivedRingT = 0;
+ counter = 0;
+ counter1 = 0;
+ /* Check to see if context is what it should be, if not set to be. */
+ if (strcmp(p->context,p->defcontext) != 0) {
+ strncpy(p->context, p->defcontext, sizeof(p->context)-1);
+ strncpy(chan->context,p->defcontext,sizeof(chan->context)-1);
+ }
+
+ for(;;) {
+ i = ZT_IOMUX_READ | ZT_IOMUX_SIGEVENT;
+ if ((res = ioctl(p->subs[index].zfd, ZT_IOMUX, &i))) {
+ ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
+ callerid_free(cs);
+ ast_hangup(chan);
+ return NULL;
+ }
+ if (i & ZT_IOMUX_SIGEVENT) {
+ res = zt_get_event(p->subs[index].zfd);
+ ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
+ res = 0;
+ /* Let us detect distinctive ring */
+
+ curRingData[receivedRingT] = p->ringt;
+
+ if (p->ringt < ringt_base/2)
+ break;
+ ++receivedRingT; /* Increment the ringT counter so we can match it against
+ values in zapata.conf for distinctive ring */
+ } else if (i & ZT_IOMUX_READ) {
+ res = read(p->subs[index].zfd, buf, sizeof(buf));
+ if (res < 0) {
+ if (errno != ELAST) {
+ ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
+ callerid_free(cs);
+ ast_hangup(chan);
+ return NULL;
+ }
+ break;
+ }
+ if (p->ringt)
+ p->ringt--;
+ if (p->ringt == 1) {
+ res = -1;
+ break;
+ }
+ }
+ }
+ if(option_verbose > 2)
+ /* this only shows up if you have n of the dring patterns filled in */
+ ast_verbose( VERBOSE_PREFIX_3 "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]);
+
+ for (counter=0; counter < 3; counter++) {
+ /* Check to see if the rings we received match any of the ones in zapata.conf for this
+ channel */
+ distMatches = 0;
+ for (counter1=0; counter1 < 3; counter1++) {
+ if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1]+10) && curRingData[counter1] >=
+ (p->drings.ringnum[counter].ring[counter1]-10)) {
+ distMatches++;
+ }
+ }
+ if (distMatches == 3) {
+ /* The ring matches, set the context to whatever is for distinctive ring.. */
+ strncpy(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context)-1);
+ strncpy(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context)-1);
+ if(option_verbose > 2)
+ ast_verbose( VERBOSE_PREFIX_3 "Distinctive Ring matched context %s\n",p->context);
+ break;
+ }
+ }
+ }
+ /* Restore linear mode (if appropriate) for Caller*ID processing */
+ zt_setlinear(p->subs[index].zfd, p->subs[index].linear);
+#if 1
+ restore_gains(p);
+#endif
+ }
+
/* If we want caller id, we're in a prering state due to a polarity reversal
* and we're set to use a polarity reversal to trigger the start of caller id,
* grab the caller id and wait for ringing to start... */
@@ -9178,6 +9300,8 @@
cid_start = CID_START_RING;
else if (!strcasecmp(v->value, "polarity"))
cid_start = CID_START_POLARITY;
+ else if (!strcasecmp(v->value, "usehist"))
+ cid_start = CID_START_USEHIST;
else if (ast_true(v->value))
cid_start = CID_START_RING;
} else if (!strcasecmp(v->name, "threewaycalling")) {
Index: include/asterisk/callerid.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/callerid.h,v
retrieving revision 1.7
diff -u -r1.7 callerid.h
--- include/asterisk/callerid.h 19 Sep 2004 16:17:18 -0000 1.7
+++ include/asterisk/callerid.h 4 Nov 2004 21:05:04 -0000
@@ -30,6 +30,7 @@
#define CID_START_RING 1
#define CID_START_POLARITY 2
+#define CID_START_USEHIST 3
#define AST_LIN2X(a) ((codec == AST_FORMAT_ALAW) ? (AST_LIN2A(a)) : (AST_LIN2MU(a)))
|