Trunkdev-S0-Adapter » History » Revision 4

Revision 3 (manawyrm, 08/13/2022 01:26 AM) → Revision 4/7 (manawyrm, 08/13/2022 10:41 AM)

h1. Trunkdev-S0-Adapter 

 Using osmo-e1d's trunkdev functionality, osmo-e1d can provide OCTOI as a virtual E1 / PRI line to DAHDI on a Linux machine. 
 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. 

 h3. Experimental test setup - Hardware 

 Fujitsu Futro S900 thin client with CologneChip HFC-S PCI ISDN card (NT mode capable) 


 The HFC-S card needs numerous mods:  
 - External clock input 
 - 100 ohm termination 
 - NT/TE selection (aka RX/TX flip) 

 100 ohm termination could be achieved directly on the card by soldering 100 Ohm resistors to the 0603 footprints next to the RJ45 connector. 
 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.  
 This (as well as the termination) doesn't need to be done on the card, but it's very convenient.  


 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.  
 _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. 
 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.  

 h3. Experimental test setup - Software 

 mISDN kernel modules need to be blacklisted (hfcpci, etc.) needs to be installed, *laforge/trunkdev branch* ! needs to be installed. needs to be installed, *laforge/trunkdev branch* ! 
 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!) 

 zaphfc driver needs to be loaded with nt_modes=0 parameter to force NT mode: 
 <pre><code class="bash"> 
 modprobe zaphfc nt_modes=0 
 modprobe dahdi-trunkdev 

 Then, the trunkdev needs to be created manually (for now): 
 <pre><code class="cpp"> 
 #include <stdio.h> 
 #include <string.h> 
 #include <sys/ioctl.h> 
 #include <errno.h> 
 #include <fcntl.h> 

 struct dahdi_trunkdev_create { 
         char name[40];            /* name of the to-be-created span */ 
         //int numchans; 
         int spanno;               /* Span number (filled in by DAHDI) */ 
 #define DAHDI_CODE                0xDA 
 #define DAHDI_TRUNKDEV_CREATE     _IOWR(DAHDI_CODE, 255, struct dahdi_trunkdev_create) 

 static int trunkdev_create(int fd, const char *name) 
         struct dahdi_trunkdev_create td_c = { 0 }; 

         strncpy(, name, sizeof(; [sizeof(] = 0; 

         return ioctl(fd, DAHDI_TRUNKDEV_CREATE, &td_c); 

 int main() 
         int fd = open("/dev/dahdi/trunkdev", O_RDWR); 
         if (fd < 0) { 
                 return -errno; 

         trunkdev_create(fd, "octoi"); 

 <pre><code class="shell"> 
 dahdi_trunkdev create octoi gcc trunkdev.c 

 (fixme: there has to be a better way to do this!) 

 <pre><code class="bash"> 
 octoi-client 10013 
  local-bind 3333 
  account username 
   mode dahdi-trunkdev 
   dahdi-trunkdev name octoi 
   dahdi-trunkdev line-number 0 
  interface 0 dahdi-trunkdev 
   trunkdev-name octoi 
   line 0 
    mode e1oip 

 <pre><code class="ini"> 
 # Span 1: ZTHFC1 "HFC-S PCI A ISDN card 0 [NT] " (MASTER) 
 # termtype: nt 

 # Span 2: trunkdev/octoi/0 "Virtual trunk octoi span 0" 
 # termtype: te 

 # Global data 

 loadzone          = de 
 defaultzone       = de 

 <pre><code class="r"> 



 internationalprefix = 00 
 nationalprefix = 0 


 #include dahdi-channels.conf 

 <pre><code class="r"> 
 ; Span 1: ZTHFC1 "HFC-S PCI A ISDN card 0 [NT] " (MASTER) AMI/CCS 
 switchtype = euroisdn 
 signalling = bri_net_ptmp 
 channel => 1-2 
 context = default 
 group = 63 

 switchtype = euroisdn 
 signalling = pri_cpe 
 channel => 4-18,20-33 
 context = default 
 group = 63 

 /etc/asterisk/extensions.lua (remember to change your phone prefix in the CALLERID, otherwise the PortMaster won't like you): 
 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! 
 <pre><code class="lua"> 
 extensions = { 
	 ["from-hfc"] = { 
		 ["_X."] = function(context, extension) 
			 channel.CALLERID("all"):set(string.format("%s <%s>", "HFC", '0306503' .. 1234)) 
			 app.dial("Dahdi/g12/"..extension, 100, "tkTK") 
	 ["from-octoi"] = { 
		 ["_X."] = function(context, extension) 
			 app.dial("Dahdi/g11/"..extension, 100, "tkTK") 
	 hangup = { 
		 s = function(context, extension) 
			 app.verbose("WARNING: Unknown call!") 

	 default = { 
		 include = {"hangup"}; 

	 public = { 
		 -- ATTENTION: If your Asterisk is connected to the internet and you do 
		 -- not have allowguest=no in sip.conf, everybody out there may use your 
		 -- public context without authentication.    In that case you want to 
		 -- double check which services you offer to the world. 
		 include = {"hangup"}; 

 hints = { 
	 default = { 
		 ["1234"] = "SIP/1234"; 

 h3. Experimental test setup - Results 

 Seems to be working well, X.75, PPP over ISDN (2 B-channel bonding/MLPPP) and voice calls all work very well:   
 More testing (bit error rate, signalling, modem calls, video calls) needs to be done. 
Add picture from clipboard (Maximum size: 48.8 MB)