Configure Asterisk to optimize your mobile phone costs.

    In order not to waste your and your time: in this topic there is no
    • chan_datacard configuration guides
    • SIP configuration guides in Asterisk
    • guides for setting up VoIP gateways and SIP clients.

    All this is perfectly google, and in the presence of experience - remembered and not forgotten.

    Recently there was a task to raise automatic telephone exchanges in a small office.
    One of the requirements was to optimally spend the funds allocated for mobile communications: from MTS to call only to MTS, from Beeline to Beeline, and so on. It was decided to use a bunch of Asterisk and several unlocked 3G-modems: SIM-cards with optimal rates already existed. As subscriber devices, softphones were used at employees' workplaces, as well as ordinary wired telephones connected to a VoIP gateway.

    The first thing that was done was to find and rewrite the DEF codes of domestic mobile operators. Of course, not all, but only the Big Three: for all other calls it was planned to use TELE2.
    Then an internal numbering plan was created: it was decided that the internal numbers would be four-digit, and would start with 5.

    Calls from SIP to the outside world were assigned the sip-incoming context, and external calls coming from modems were assigned datacard-incoming. The required modem was determined using the MCC / MNC (Mobile Country Code / Mobile Network Code) prefix from the IMSI SIM card. The Russian code is 250. Accordingly, MTS has MNC 25001, MegaFon has 25002, Beeline has 25099, Tele2 has 25020.

    Ubuntu Linux 11.10 x86-64 was used as a software platform, and if I remember correctly, Asterisk 1.8 . To control the modems was used chan_datacard 310th assembly.

    Actually, an example extensions.conf.
    [datacard-incoming]
    exten => sms, 1, Verbose (Incoming SMS from $ {CALLERID (num)} $ {SMS})
    exten => sms, n, System (echo '$ {STRFTIME ($ {EPOCH} ,,% Y-% m-% d% H:% M:% S)} - $ {DATACARD} - $ {CALLERID (num )}: $ {SMS} '>> /var/log/asterisk/sms.txt)
    exten => sms, n, Hangup ()
    exten => ussd, 1, Verbose (Incoming USSD: $ {USSD})
    exten => ussd, n, System (echo '$ {STRFTIME ($ {EPOCH} ,,% Y-% m-% d% H:% M:% S)} - $ {DATACARD}: $ {USSD}' >> /var/log/asterisk/ussd.txt)
    exten => ussd, n, Hangup ()
    exten => s, 1, Dial (SIP / 5001 ,,)
    exten => s, n, Hangup ()
    [sip-incoming]
    ; mobile operators
    exten => _8913XXXXXXX, 1, Dial (Datacard / s: 25001 / $ {EXTEN})
    exten => _8913XXXXXXX, n, Hangup
    exten => _8983XXXXXXX, 1, Dial (Datacard / s: 25001 / $ {EXTEN})
    exten => _8983XXXXXXX, n, Hangup
    exten => _8923XXXXXXX, 1, Dial (Datacard / s: 25002 / $ {EXTEN})
    exten => _8923XXXXXXX, n, Hangup
    exten => _8903XXXXXXX, 1, Dial (Datacard / s: 25099 / $ {EXTEN})
    exten => _8903XXXXXXX, n, Hangup
    exten => _8905XXXXXXX, 1, Dial (Datacard / s: 25099 / $ {EXTEN})
    exten => _8905XXXXXXX, n, Hangup
    exten => _89XXXXXXXXX, 1, Dial (Datacard / s: 25020 / $ {EXTEN})
    exten => _89XXXXXXXXX, n, Hangup
    ; local numbers
    exten => _5XXX, 1, Dial (SIP / $ {EXTEN})
    exten => _5XXX, n, Hangup
    


    A bit about setting chan_datacard. The 310th assembly can unbind from specific ports by indicating which IMEI / IMSI is expected for a particular logical device. Out of habit, I tuned into USB pseudo-terminals.

    example from datacard.conf
    [datacard0]
    audio = / dev / ttyUSB1; tty port for audio connection; no default value
    data = / dev / ttyUSB2; tty port for AT commands; no default value
    context = datacard-incoming
    autodeletesms = yes; auto delete incoming sms
    resetdatacard = yes; reset datacard during initialization
    u2diag = 0; set U2DIAG parameter (0 = disable everything except modem function)
    usecallingpres = yes; use the caller ID presentation or not
    callingpres = allowed_passed_screen; set caller ID presentation
    


    That's all, folks!

    Nuances of tuning and operation


    What is achieved by such a setting? Subscribers do not need to think about which prefix to go to. In fact, the Asterisk itself determines through which interface to redirect the call, guided by the number and its length. With a sufficient number of modems and other lines, a free channel in the direction is always provided.

    As for specifically 3G modems - Asterisk on modern AMD and Core processors holds well even 50-60 modems. True, this requires the fulfillment of several conditions:
    • Modems are removed from the housings and placed in USB hubs, also freed from the housings
    • Additional power from independent power supplies is supplied to the hubs
    • "Combs" of hubs and modems are placed in a case with good flow-air cooling - a case fan for the system unit is quite suitable
    • Hubs are recommended to be connected to separate host controllers installed on the PCI-E bus


    All this is due to the fact that when voice traffic goes through the modem, its chips heat up intensively and consume electricity. It happened that not very well-assembled E1550 overheated and “fell off” - the Asterisk stopped seeing them for a while.
    But the E173 is generally poorly adapted to work “naked”: unlike the E1550, they have a SIM card slot not a slot, but an invoice. I had to press the card to the contacts of the reader with a clothespin.

    That's all for sure.

    Also popular now: