Project

General

Profile

Actions

Trunkdev-S0-Adapter » History » Revision 3

« Previous | Revision 3/7 (diff) | Next »
manawyrm, 08/13/2022 01:26 AM


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.

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.

Experimental test setup - Software

mISDN kernel modules need to be blacklisted (hfcpci, etc.)
https://gitea.osmocom.org/retronetworking/dahdi-linux needs to be installed, laforge/trunkdev branch !
https://gitea.osmocom.org/retronetworking/dahdi-tools needs to be installed.
https://gitea.osmocom.org/retronetworking/osmo-e1d/ 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:

modprobe zaphfc nt_modes=0
modprobe dahdi-trunkdev

Then, the trunkdev needs to be created manually (for now):

#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(td_c.name, name, sizeof(td_c.name));
        td_c.name[sizeof(td_c.name)-1] = 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");
}

gcc trunkdev.c
./a.out

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

osmo-e1d.cfg:

octoi-client 123.123.123.123 10013
 local-bind 0.0.0.0 3333
 account username
  mode dahdi-trunkdev
  dahdi-trunkdev name octoi
  dahdi-trunkdev line-number 0
e1d
 interface 0 dahdi-trunkdev
  trunkdev-name octoi
  line 0
   mode e1oip

/etc/dahdi/system.conf:

# Span 1: ZTHFC1 "HFC-S PCI A ISDN card 0 [NT] " (MASTER)
span=1,0,0,ccs,ami
# termtype: nt
bchan=1-2
hardhdlc=3

# Span 2: trunkdev/octoi/0 "Virtual trunk octoi span 0" 
span=2,1,0,ccs,hdb3,crc4
# termtype: te
bchan=4-18,20-34
dchan=19

# Global data

loadzone        = de
defaultzone     = de

/etc/asterisk/chan_dahdi.conf:

[trunkgroups]

[channels]
language=de
switchtype=euroisdn

echocancel=no
echocancelwhenbridged=no

pridialplan=unknown
prilocaldialplan=unknown
internationalprefix = 00
nationalprefix = 0

overlapdial=yes

#include dahdi-channels.conf

/etc/asterisk/dahdi-channels.conf:

; Span 1: ZTHFC1 "HFC-S PCI A ISDN card 0 [NT] " (MASTER) AMI/CCS
group=0,11
context=from-hfc
switchtype = euroisdn
signalling = bri_net_ptmp
channel => 1-2
context = default
group = 63

group=0,12
context=from-octoi
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!

extensions = {
    ["from-hfc"] = {
        ["_X."] = function(context, extension)
            app.dumpChan()
            channel.CALLERID("all"):set(string.format("%s <%s>", "HFC", '0306503' .. 1234))
            app.dial("Dahdi/g12/"..extension, 100, "tkTK")
        end;
    };
    ["from-octoi"] = {
        ["_X."] = function(context, extension)
            app.dumpChan()
            app.dial("Dahdi/g11/"..extension, 100, "tkTK")
        end;
    };
    hangup = {
        s = function(context, extension)
            app.verbose("WARNING: Unknown call!")
            app.hangup()
        end;

    };
    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";
    };
}

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.

Updated by manawyrm 4 months ago · 3 revisions

Add picture from clipboard (Maximum size: 48.8 MB)