aboutsummaryrefslogtreecommitdiff
path: root/misc/dahdi/files/patch-bchan
blob: 4aa35a8b8163c4ed8d271f4040356dc099920006 (plain) (blame)
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
# Translate the D channels to a standard channel data.
# The HFC chipset provides us the D channel as data, but
# Zaptel expects it as a standard channel with 1000 samples
# per second.

Index: freebsd/include/dahdi/dahdi_config.h
===================================================================
--- freebsd/include/dahdi/dahdi_config.h	(revision 8781)
+++ freebsd/include/dahdi/dahdi_config.h	(working copy)
@@ -180,7 +180,13 @@
  */
 /* #define	OPTIMIZE_CHANMUTE */
 
+/*
+ * Uncomment the following for BRI D channels
+ *
+ */
+#define CONFIG_DAHDI_BRI_DCHANS
 
+
 /*
  * Pass DAHDI_AUDIOMODE to channel driver as well
  */
Index: freebsd/include/dahdi/kernel.h
===================================================================
--- freebsd/include/dahdi/kernel.h	(revision 8781)
+++ freebsd/include/dahdi/kernel.h	(working copy)
@@ -426,6 +426,13 @@
 	int statcount;
 	int lastnumbufs;
 #endif
+#ifdef CONFIG_DAHDI_BRI_DCHANS
+	int bytes2receive;
+	int maxbytes2transmit; /* size of the tx buffer in the card driver */
+	int bytes2transmit;
+	int eofrx;
+	int eoftx;
+#endif
 	spinlock_t lock;
 	char name[40];
 	/* Specified by DAHDI */
@@ -738,6 +745,9 @@
 	DAHDI_FLAGBIT_LOOPED	= 18,	/*!< Loopback the receive data from the channel to the transmit */
 	DAHDI_FLAGBIT_MTP2	= 19,	/*!< Repeats last message in buffer and also discards repeating messages sent to us */
 	DAHDI_FLAGBIT_HDLC56	= 20,	/*!< Sets the given channel (if in HDLC mode) to use 56K HDLC instead of 64K  */
+#if defined(CONFIG_DAHDI_BRI_DCHANS)
+	DAHDI_FLAGBIT_BRIDCHAN   = 21,	/*!< hardhdlc-like handling of the D channel */
+#endif
 };
 
 struct dahdi_count {
@@ -788,6 +798,7 @@
 #define DAHDI_FLAG_LOOPED	DAHDI_FLAG(LOOPED)
 #define DAHDI_FLAG_MTP2		DAHDI_FLAG(MTP2)
 #define DAHDI_FLAG_HDLC56	DAHDI_FLAG(HDLC56)
+#define DAHDI_FLAG_BRIDCHAN	DAHDI_FLAG(BRIDCHAN)
 
 struct dahdi_span {
 	spinlock_t lock;
Index: freebsd/drivers/dahdi/dahdi-base.c
===================================================================
--- freebsd/drivers/dahdi/dahdi-base.c	(revision 8860)
+++ freebsd/drivers/dahdi/dahdi-base.c	(working copy)
@@ -6884,11 +6881,40 @@
 					*(txb++) = fasthdlc_tx_run_nocheck(&ms->txhdlc);
 				}
 				bytes -= left;
+#ifdef CONFIG_DAHDI_BRI_DCHANS
+			} else if (test_bit(DAHDI_FLAGBIT_BRIDCHAN, &ms->flags)) {
+			    /*
+			     * Let's get this right, we want to transmit complete frames only.
+			     * The card driver will do the dirty HDLC work for us.
+			     * txb (transmit buffer) is supposed to be big enough to store one frame
+			     * we will make this as big as the D fifo (1KB or 2KB)
+			     */
+
+			    /* there are 'left' bytes in the user buffer left to transmit */
+			    left = ms->writen[ms->outwritebuf] - ms->writeidx[ms->outwritebuf] - 2;
+			    if (left > ms->maxbytes2transmit) {
+				memcpy(txb, buf + ms->writeidx[ms->outwritebuf], ms->maxbytes2transmit);
+				ms->writeidx[ms->outwritebuf] += ms->maxbytes2transmit;
+				txb += ms->maxbytes2transmit;
+				ms->bytes2transmit = ms->maxbytes2transmit;
+				ms->eoftx = 0;
+			    } else {
+				memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
+				ms->writeidx[ms->outwritebuf] += left + 2;
+				txb += left + 2;
+				ms->bytes2transmit = left;
+				ms->eoftx = 1;
+			    }
+			    bytes = 0;
+#endif
 			} else {
 				memcpy(txb, buf + ms->writeidx[ms->outwritebuf], left);
 				ms->writeidx[ms->outwritebuf]+=left;
 				txb += left;
 				bytes -= left;
+#if defined(CONFIG_DAHDI_BRI_DCHANS)
+				ms->bytes2transmit=DAHDI_CHUNKSIZE;
+#endif
 			}
 			/* Check buffer status */
 			if (ms->writeidx[ms->outwritebuf] >= ms->writen[ms->outwritebuf]) {
@@ -6947,6 +6973,17 @@
 				/* Transmit a flag if this is an HDLC channel */
 				if (ms->flags & DAHDI_FLAG_HDLC)
 					fasthdlc_tx_frame_nocheck(&ms->txhdlc);
+#if defined(CONFIG_DAHDI_BRI_DCHANS)
+				if (test_bit(DAHDI_FLAGBIT_BRIDCHAN, &ms->flags)) {
+			//	    if (ms->bytes2transmit > 0) {
+					// txb += 2;
+					// ms->bytes2transmit -= 2;
+					bytes=0;
+					ms->eoftx = 1;
+//					printk(KERN_CRIT "zaptel EOF(%d) bytes2transmit %d\n",ms->eoftx,ms->bytes2transmit);
+			//	    }
+				}
+#endif
 #ifdef CONFIG_DAHDI_NET
 				if (ms->flags & DAHDI_FLAG_NETDEV)
 					netif_wake_queue(ztchan_to_dev(ms));
@@ -7007,6 +7044,12 @@
 				memset(txb, 0xFF, bytes);
 			}
 			bytes = 0;
+#if defined(CONFIG_DAHDI_BRI_DCHANS)
+		} else if (test_bit(DAHDI_FLAGBIT_BRIDCHAN, &ms->flags)) {
+		    ms->bytes2transmit = 0;
+		    ms->eoftx = 0;
+		    bytes = 0;
+#endif
 		} else {
 			memset(txb, DAHDI_LIN2X(0, ms), bytes);	/* Lastly we use silence on telephony channels */
 			bytes = 0;
@@ -7905,6 +7948,14 @@
 	int left, x;
 
 
+#if defined(CONFIG_DAHDI_BRI_DCHANS)
+	if (test_bit(DAHDI_FLAGBIT_BRIDCHAN, &ms->flags)) {
+	    bytes = ms->bytes2receive;
+	    if (bytes < 1) return;
+//	    printk(KERN_CRIT "bytes2receive %d\n",ms->bytes2receive);
+	}
+#endif
+
 	while(bytes) {
 #if defined(CONFIG_DAHDI_NET)  || defined(CONFIG_DAHDI_PPP)
 		skb = NULL;
@@ -7962,6 +8013,19 @@
 						}
 					}
 				}
+#ifdef CONFIG_DAHDI_BRI_DCHANS
+			} else if (test_bit(DAHDI_FLAGBIT_BRIDCHAN, &ms->flags)) {
+			    memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);
+			    rxb += left;
+			    ms->readidx[ms->inreadbuf] += left;
+			    bytes -= left;
+			    if (ms->eofrx == 1) {
+				eof=1;
+			    }
+//			    printk(KERN_CRIT "receiving %d bytes\n",ms->bytes2receive);
+			    ms->bytes2receive = 0;
+			    ms->eofrx = 0;
+#endif
 			} else {
 				/* Not HDLC */
 				memcpy(buf + ms->readidx[ms->inreadbuf], rxb, left);