Project

General

Profile

Trunkdev-S0-Adapter » History » Version 2

manawyrm, 08/13/2022 01:22 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
The HFC-S card needs numerous mods: 
10
- External clock input
11
- 100 ohm termination
12
- NT/TE selection (aka RX/TX flip)
13
14
100 ohm termination could be achieved directly on the card by soldering 100 Ohm resistors to the 0603 footprints next to the RJ45 connector.
15
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. 
16
This (as well as the termination) doesn't need to be done on the card, but it's very convenient. 
17
18
!{width:40%}IMG_3554.JPG!
19
20
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. 
21
_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.
22 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. 
23
24
h3. Experimental test setup - Software
25
26
mISDN kernel modules need to be blacklisted (hfcpci, etc.)
27
https://gitea.osmocom.org/retronetworking/dahdi-linux needs to be installed, *laforge/trunkdev branch* !
28
https://gitea.osmocom.org/retronetworking/dahdi-tools needs to be installed.
29
https://gitea.osmocom.org/retronetworking/osmo-e1d/ needs to be installed, *laforge/trunkdev branch* !
30
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!)
31
32
zaphfc driver needs to be loaded with nt_modes=0 parameter to force NT mode:
33
<pre><code class="bash">
34
modprobe zaphfc nt_modes=0
35
modprobe dahdi-trunkdev
36
</code></pre>
37
38
Then, the trunkdev needs to be created manually (for now):
39
<pre><code class="cpp">
40
#include <stdio.h>
41
#include <string.h>
42
#include <sys/ioctl.h>
43
#include <errno.h>
44
#include <fcntl.h>
45
46
struct dahdi_trunkdev_create {
47
        char name[40];          /* name of the to-be-created span */
48
        //int numchans;
49
        int spanno;             /* Span number (filled in by DAHDI) */
50
};
51
#define DAHDI_CODE              0xDA
52
#define DAHDI_TRUNKDEV_CREATE   _IOWR(DAHDI_CODE, 255, struct dahdi_trunkdev_create)
53
54
static int trunkdev_create(int fd, const char *name)
55
{
56
        struct dahdi_trunkdev_create td_c = { 0 };
57
58
        strncpy(td_c.name, name, sizeof(td_c.name));
59
        td_c.name[sizeof(td_c.name)-1] = 0;
60
61
        return ioctl(fd, DAHDI_TRUNKDEV_CREATE, &td_c);
62
}
63
64
int main()
65
{
66
        int fd = open("/dev/dahdi/trunkdev", O_RDWR);
67
        if (fd < 0) {
68
                return -errno;
69
        }
70
71
        trunkdev_create(fd, "octoi");
72
}
73
</code></pre>
74
75
<pre><code class="shell">
76
gcc trunkdev.c
77
./a.out
78
</code></pre> 
79
(fixme: there has to be a better way to do this!)
80
81
82
osmo-e1d.cfg: 
83
<pre><code class="bash">
84
octoi-client 123.123.123.123 10013
85
 local-bind 0.0.0.0 3333
86
 account username
87
  mode dahdi-trunkdev
88
  dahdi-trunkdev name octoi
89
  dahdi-trunkdev line-number 0
90
e1d
91
 interface 0 dahdi-trunkdev
92
  trunkdev-name octoi
93
  line 0
94
   mode e1oip
95
</code></pre>
96
97
/etc/dahdi/system.conf: 
98
<pre><code class="ini">
99
# Span 1: ZTHFC1 "HFC-S PCI A ISDN card 0 [NT] " (MASTER)
100
span=1,0,0,ccs,ami
101
# termtype: nt
102
bchan=1-2
103
hardhdlc=3
104
105
# Span 2: trunkdev/octoi/0 "Virtual trunk octoi span 0"
106
span=2,1,0,ccs,hdb3,crc4
107
# termtype: te
108
bchan=4-18,20-34
109
dchan=19
110
111
# Global data
112
113
loadzone        = de
114
defaultzone     = de
115
</code></pre>
116
117
/etc/asterisk/chan_dahdi.conf:
118
<pre><code class="r">
119
[trunkgroups]
120
121
[channels]
122
language=de
123
switchtype=euroisdn
124
125
126
echocancel=no
127
echocancelwhenbridged=no
128
129
130
pridialplan=unknown
131
prilocaldialplan=unknown
132
internationalprefix = 00
133
nationalprefix = 0
134
135
overlapdial=yes
136
137
#include dahdi-channels.conf
138
</code></pre>
139
140
/etc/asterisk/dahdi-channels.conf:
141
<pre><code class="r">
142
; Span 1: ZTHFC1 "HFC-S PCI A ISDN card 0 [NT] " (MASTER) AMI/CCS
143
group=0,11
144
context=from-hfc
145
switchtype = euroisdn
146
signalling = bri_net_ptmp
147
channel => 1-2
148
context = default
149
group = 63
150
151
group=0,12
152
context=from-octoi
153
switchtype = euroisdn
154
signalling = pri_cpe
155
channel => 4-18,20-33
156
context = default
157
group = 63
158
</code></pre>
159
160
/etc/asterisk/extensions.lua (remember to change your phone prefix in the CALLERID, otherwise the PortMaster won't like you):
161
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!
162
<pre><code class="lua">
163
extensions = {
164
	["from-hfc"] = {
165
		["_X."] = function(context, extension)
166
			app.dumpChan()
167
			channel.CALLERID("all"):set(string.format("%s <%s>", "HFC", '0306503' .. 1234))
168
			app.dial("Dahdi/g12/"..extension, 100, "tkTK")
169
		end;
170
	};
171
	["from-octoi"] = {
172
		["_X."] = function(context, extension)
173
			app.dumpChan()
174
			app.dial("Dahdi/g11/"..extension, 100, "tkTK")
175
		end;
176
	};
177
	hangup = {
178
		s = function(context, extension)
179
			app.verbose("WARNING: Unknown call!")
180
			app.hangup()
181
		end;
182
183
	};
184
	default = {
185
		include = {"hangup"};
186
	};
187
188
	public = {
189
		-- ATTENTION: If your Asterisk is connected to the internet and you do
190
		-- not have allowguest=no in sip.conf, everybody out there may use your
191
		-- public context without authentication.  In that case you want to
192
		-- double check which services you offer to the world.
193
		include = {"hangup"};
194
	};
195
}
196
197
hints = {
198
	default = {
199
		["1234"] = "SIP/1234";
200
	};
201
}
202
</code></pre>
Add picture from clipboard (Maximum size: 48.8 MB)