Project

General

Profile

Trunkdev-S0-Adapter » History » Version 3

manawyrm, 08/13/2022 01:26 AM

1 1 manawyrm
h1. Trunkdev-S0-Adapter
2
3
Using osmo-e1d's trunkdev functionality, osmo-e1d can provide OCTOI as a virtual E1 / PRI line to DAHDI on a Linux machine.
4
This can then be used in conjunction with a software PBX to switch between the virtual E1 line going to/from OCTOI and a physical ISDN interface, for example a more common S0 / BRI interface.
5
6
h3. Experimental test setup - Hardware
7
8
Fujitsu Futro S900 thin client with CologneChip HFC-S PCI ISDN card (NT mode capable)
9 3 manawyrm
10
!{width:40%}IMG_4900.JPG!
11
12 1 manawyrm
The HFC-S card needs numerous mods: 
13
- External clock input
14
- 100 ohm termination
15
- NT/TE selection (aka RX/TX flip)
16
17
100 ohm termination could be achieved directly on the card by soldering 100 Ohm resistors to the 0603 footprints next to the RJ45 connector.
18
The card was permanently modded for NT mode by cutting all 4 traces going to the RJ45 line (but after the transformer) and flipping the RX/TX pairs with enameled copper wire. 
19
This (as well as the termination) doesn't need to be done on the card, but it's very convenient. 
20
21
!{width:40%}IMG_3554.JPG!
22
23
This external clock input is terminated with a 50 ohm resistor (actually 51 ohm) in parallel, which is then fed through a 100n AC coupling ceramic capacitor into the CLKIN pin on the chip. It's accessible on one side of the crystal oscillator. 
24
_This mod loads the crystal oscillator so much, that the card will stop working without external clock input attached!_ Detaching the 100n cap from the crystal oscillator will make it start again.
25 2 manawyrm
A high-quality, low phase noise (low jitter), high precision time source with 12.288 MHz (12288000 Hz) is required. The "Mini Precision GPS Reference Clock" from Leo Bodnar has shown to be pretty reliable so far. 
26
27
h3. Experimental test setup - Software
28
29
mISDN kernel modules need to be blacklisted (hfcpci, etc.)
30
https://gitea.osmocom.org/retronetworking/dahdi-linux needs to be installed, *laforge/trunkdev branch* !
31
https://gitea.osmocom.org/retronetworking/dahdi-tools needs to be installed.
32
https://gitea.osmocom.org/retronetworking/osmo-e1d/ needs to be installed, *laforge/trunkdev branch* !
33
asterisk and asterisk-dahdi need to be installed (be careful, the latter will install dahdi via DKMS, you'll need to disable that and/or reinstall dahdi-linux from retronetworking!)
34
35
zaphfc driver needs to be loaded with nt_modes=0 parameter to force NT mode:
36
<pre><code class="bash">
37
modprobe zaphfc nt_modes=0
38
modprobe dahdi-trunkdev
39
</code></pre>
40
41
Then, the trunkdev needs to be created manually (for now):
42
<pre><code class="cpp">
43
#include <stdio.h>
44
#include <string.h>
45
#include <sys/ioctl.h>
46
#include <errno.h>
47
#include <fcntl.h>
48
49
struct dahdi_trunkdev_create {
50
        char name[40];          /* name of the to-be-created span */
51
        //int numchans;
52
        int spanno;             /* Span number (filled in by DAHDI) */
53
};
54
#define DAHDI_CODE              0xDA
55
#define DAHDI_TRUNKDEV_CREATE   _IOWR(DAHDI_CODE, 255, struct dahdi_trunkdev_create)
56
57
static int trunkdev_create(int fd, const char *name)
58
{
59
        struct dahdi_trunkdev_create td_c = { 0 };
60
61
        strncpy(td_c.name, name, sizeof(td_c.name));
62
        td_c.name[sizeof(td_c.name)-1] = 0;
63
64
        return ioctl(fd, DAHDI_TRUNKDEV_CREATE, &td_c);
65
}
66
67
int main()
68
{
69
        int fd = open("/dev/dahdi/trunkdev", O_RDWR);
70
        if (fd < 0) {
71
                return -errno;
72
        }
73
74
        trunkdev_create(fd, "octoi");
75
}
76
</code></pre>
77
78
<pre><code class="shell">
79
gcc trunkdev.c
80
./a.out
81
</code></pre> 
82
(fixme: there has to be a better way to do this!)
83
84
85
osmo-e1d.cfg: 
86
<pre><code class="bash">
87
octoi-client 123.123.123.123 10013
88
 local-bind 0.0.0.0 3333
89
 account username
90
  mode dahdi-trunkdev
91
  dahdi-trunkdev name octoi
92
  dahdi-trunkdev line-number 0
93
e1d
94
 interface 0 dahdi-trunkdev
95
  trunkdev-name octoi
96
  line 0
97
   mode e1oip
98
</code></pre>
99
100
/etc/dahdi/system.conf: 
101
<pre><code class="ini">
102
# Span 1: ZTHFC1 "HFC-S PCI A ISDN card 0 [NT] " (MASTER)
103
span=1,0,0,ccs,ami
104
# termtype: nt
105
bchan=1-2
106
hardhdlc=3
107
108
# Span 2: trunkdev/octoi/0 "Virtual trunk octoi span 0"
109
span=2,1,0,ccs,hdb3,crc4
110
# termtype: te
111
bchan=4-18,20-34
112
dchan=19
113
114
# Global data
115
116
loadzone        = de
117
defaultzone     = de
118
</code></pre>
119
120
/etc/asterisk/chan_dahdi.conf:
121
<pre><code class="r">
122
[trunkgroups]
123
124
[channels]
125
language=de
126
switchtype=euroisdn
127
128
129
echocancel=no
130
echocancelwhenbridged=no
131
132
133
pridialplan=unknown
134
prilocaldialplan=unknown
135
internationalprefix = 00
136
nationalprefix = 0
137
138
overlapdial=yes
139
140
#include dahdi-channels.conf
141
</code></pre>
142
143
/etc/asterisk/dahdi-channels.conf:
144
<pre><code class="r">
145
; Span 1: ZTHFC1 "HFC-S PCI A ISDN card 0 [NT] " (MASTER) AMI/CCS
146
group=0,11
147
context=from-hfc
148
switchtype = euroisdn
149
signalling = bri_net_ptmp
150
channel => 1-2
151
context = default
152
group = 63
153
154
group=0,12
155
context=from-octoi
156
switchtype = euroisdn
157
signalling = pri_cpe
158
channel => 4-18,20-33
159
context = default
160
group = 63
161
</code></pre>
162
163
/etc/asterisk/extensions.lua (remember to change your phone prefix in the CALLERID, otherwise the PortMaster won't like you):
164
Asterisk has a strange data corruption issue when not using "tkTK" flags, which will prohibit bridging (because those flags force DTMF reception). Needs further investigation!
165
<pre><code class="lua">
166
extensions = {
167
	["from-hfc"] = {
168
		["_X."] = function(context, extension)
169
			app.dumpChan()
170
			channel.CALLERID("all"):set(string.format("%s <%s>", "HFC", '0306503' .. 1234))
171
			app.dial("Dahdi/g12/"..extension, 100, "tkTK")
172
		end;
173
	};
174
	["from-octoi"] = {
175
		["_X."] = function(context, extension)
176
			app.dumpChan()
177
			app.dial("Dahdi/g11/"..extension, 100, "tkTK")
178
		end;
179
	};
180
	hangup = {
181
		s = function(context, extension)
182
			app.verbose("WARNING: Unknown call!")
183
			app.hangup()
184
		end;
185
186
	};
187
	default = {
188
		include = {"hangup"};
189
	};
190
191
	public = {
192
		-- ATTENTION: If your Asterisk is connected to the internet and you do
193
		-- not have allowguest=no in sip.conf, everybody out there may use your
194
		-- public context without authentication.  In that case you want to
195
		-- double check which services you offer to the world.
196
		include = {"hangup"};
197
	};
198
}
199
200
hints = {
201
	default = {
202
		["1234"] = "SIP/1234";
203
	};
204
}
205
</code></pre>
206 3 manawyrm
207
h3. Experimental test setup - Results
208
209
Seems to be working well, X.75, PPP over ISDN (2 B-channel bonding/MLPPP) and voice calls all work very well:  
210
!{width:40%}IMG_4904.JPG!
211
More testing (bit error rate, signalling, modem calls, video calls) needs to be done.
Add picture from clipboard (Maximum size: 48.8 MB)