Niestety nie mam takiego modemu, więc nie przetestuję.
Umieściłeś w sekcji config interface 'wan' w parametrze mode komendę 'AT^NDISDUP=1,1'. W takiej sytuacji skrypt ndisup.gcom wysyła do modemu dwa razy tą komendę, i jego zachowanie może być dziwne.
Moim założeniem było, aby parametr mode był uzywany do ustawiania takich parametrów modemu jak np. uzywane pasma, roaming, tryby transmisji. (np. AT^SYSCFG=2,2,3FFFFFFF,2,1)

227

(148 odpowiedzi, napisanych Oprogramowanie / Software)

Tak, tyle, że mam trzy routery. No i inną adresację i nazewnictwo:)

228

(148 odpowiedzi, napisanych Oprogramowanie / Software)

Założenia:

  • typowa konfiguracja OpenWRT Backfire lub AA

  • dwa routery

  • „Router-A” – pełnić będzie rolę serwera OpenVPN,

    • LAN adres routera IP 192.168.1.1, DHCP 192.168.1.101-150

    • WAN adres routera IP 123.123.123.123 (poglądowy adres publiczny)

    • port serwera OpenVPN 1194

    • pula adresów dla klientów OpenVPN 192.168.1.201-210

  • „Router-B” – pełnić będzie rolę klienta OpenVPN,

    • LAN adres routera IP 192.168.1.2, DHCP 192.168.1.151-200

    • WAN adres routera bez znaczenia

  • Jedna pula adresów dla obydwóch LAN-ów 192.168.1.0/24

  • Komunikacja między serwerem a klientem VPN na poziomie warstwy drugiej (broadcast-y biegają w całym LAN-ie), połączenie typu most/bridge.

  • Wszystko opisane poniżej wykonujemy z poziomu konsoli

Konfiguracja Router-A:

W plik /etc/config/network zmieniamy adres IP routera ipaddr i dodajemy interfejs tap0.
było:

config interface 'lan'
        option 'eth0.1'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'

powinno być:

config interface 'lan'
        list ifname 'eth0.1'
        list ifname 'tap0'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'

W pliku /etc/config/dhcp dodajemy wykluczenie interfejsu notinterface i zmieniamy zakres przydzielanych adresów w sekcji dhcp lan.
było:

config 'dnsmasq'
        option 'domainneeded' '1'
        option 'boguspriv' '1'
        option 'filterwin2k' '0'
        option 'localise_queries' '1'
        option 'rebind_protection' '1'
        option 'rebind_localhost' '1'
        option 'local' '/lan/'
        option 'domain' 'lan'
        option 'expandhosts' '1'
        option 'nonegcache' '0'
        option 'authoritative' '1'
        option 'readethers' '1'
        option 'leasefile' '/tmp/dhcp.leases'
        option 'resolvfile' '/tmp/resolv.conf.auto'

config 'dhcp' 'lan'
        option 'interface' 'lan'
        option 'start' '100'
        option 'limit' '100'

powinno być:

config 'dnsmasq'
        option 'domainneeded' '1'
        option 'boguspriv' '1'
        option 'filterwin2k' '0'
        option 'localise_queries' '1'
        option 'rebind_protection' '1'
        option 'rebind_localhost' '1'
        option 'local' '/lan/'
        option 'domain' 'lan'
        option 'expandhosts' '1'
        option 'nonegcache' '0'
        option 'authoritative' '1'
        option 'readethers' '1'
        option 'leasefile' '/tmp/dhcp.leases'
        option 'resolvfile' '/tmp/resolv.conf.auto'
        option 'notinterface' 'tap0'

config 'dhcp' 'lan'
        option 'interface' 'lan'
        option 'start' '101'
        option 'limit' '50'

W pliku /etc/config/firewall dodajemy regułę:

config rule
        option '_name' 'Allow-OpenVPN'
        option 'target' 'ACCEPT'
        option 'dest_port' '1194'
        option 'src' 'wan'
        option 'proto' 'tcp'
        option 'family' 'ipv4'

oraz tymczasowo przekierowanie i regułę:

config 'redirect'
        option '_name' 'Allow-SSH TMP'
        option 'src' 'wan'
        option 'proto' 'tcp'
        option 'dest_ip' '192.168.1.1'
        option 'dest_port' '22'

config 'rule'
        option '_name' 'Allow-SSH TMP'
        option 'src' 'wan'
        option 'target' 'ACCEPT'
        option 'proto' 'tcp'
        option 'dest_port' '22'

Uwaga, te dwie sekcje powyżej należy usunąć po zakończeniu wszystkich działań!

Do pliku /etc/firewall.user dodajemy następujące polecenia:

ebtables -F
ebtables -I FORWARD -i tap0 -p IPv4 --ip-protocol udp --ip-destination-port 67:68 -j DROP
ebtables -I FORWARD -o tap0 -p IPv4 --ip-protocol udp --ip-destination-port 67:68 -j DROP
ebtables -I INPUT -i tap0 -p IPv4 --ip-protocol udp --ip-destination-port 67:68 -j DROP
ebtables -I OUTPUT -o tap0 -p IPv4 --ip-protocol udp --ip-destination-port 67:68 -j DROP

Instalujemy oprogramowanie, wydając komendy:

opkg update
opkg install openvpn openvpn-easy-rsa kmod-ebtables-ipv4 ebtables ntpclient

W pliku /etc/easy-rsa/vars modyfikujemy ustawienia kluczy, powinno/może być:

export KEY_COUNTRY="PL"
export KEY_PROVINCE="MAZ"
export KEY_CITY="Warszawa"
export KEY_ORG="SiecDomowa"
export KEY_EMAIL="mojadres@polska.com.pl"

Weryfikujemy ustawienia czasu systemowego routera, wydając komendę:

date

Wykonujemy następujące polecenia:

clean-all
build-ca
build-dh
build-key-server Router-A
build-key Router-B
cp /etc/easy-rsa/keys/ca.crt  /etc/openvpn/
cp /etc/easy-rsa/keys/dh1024.pem /etc/openvpn/
cp /etc/easy-rsa/keys/Router-A.crt /etc/openvpn/
cp /etc/easy-rsa/keys/Router-A.key /etc/openvpn/

W pliku /etc/config/openvpn dodajemy lub modyfikujemy następujące elementy:

package 'openvpn'

config 'openvpn' 'SiecDomowa'
        option 'enabled' '1'
        option 'mode' 'server'
        option 'proto' 'tcp-server'
        option 'dev_type' 'tap'
        option 'dev' 'tap0'
        option 'port' '1194'
        option 'tun_mtu' '1500'
        option 'comp_lzo' '1'
        option 'server_bridge' '192.168.1.1 255.255.255.0 192.168.1.201 192.168.1.210'
        option 'client_to_client' '1'
        option 'keepalive' '60 120'
        option 'persist_key' '1'
        option 'persist_tun' '1'
        option 'ca' '/etc/openvpn/ca.crt'
        option 'cert' '/etc/openvpn/Router-A.crt'
        option 'key' '/etc/openvpn/Router-A.key'
        option 'dh' '/etc/openvpn/dh1024.pem'

Aby włączyć OpenVPN i ponownie uruchomić router należy wydać polecenie:

/etc/init.d/openvpn enable
reboot

Konfiguracja Router-B:

W plik /etc/config/network zmieniamy adres IP routera ipaddr i dodajemy interfejs tap0.
było:

config interface 'lan'
        option 'eth0.1'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'

powinno być:

config interface 'lan'
        list ifname 'eth0.1'
        list ifname 'tap0'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.2'
        option netmask '255.255.255.0'

W pliku /etc/config/dhcp dodajemy wykluczenie interfejsu notinterface i zmieniamy zakres przydzielanych adresów w sekcji dhcp lan.
było:

config 'dnsmasq'
        option 'domainneeded' '1'
        option 'boguspriv' '1'
        option 'filterwin2k' '0'
        option 'localise_queries' '1'
        option 'rebind_protection' '1'
        option 'rebind_localhost' '1'
        option 'local' '/lan/'
        option 'domain' 'lan'
        option 'expandhosts' '1'
        option 'nonegcache' '0'
        option 'authoritative' '1'
        option 'readethers' '1'
        option 'leasefile' '/tmp/dhcp.leases'
        option 'resolvfile' '/tmp/resolv.conf.auto'

config 'dhcp' 'lan'
        option 'interface' 'lan'
        option 'start' '100'
        option 'limit' '100'

powinno być:

config 'dnsmasq'
        option 'domainneeded' '1'
        option 'boguspriv' '1'
        option 'filterwin2k' '0'
        option 'localise_queries' '1'
        option 'rebind_protection' '1'
        option 'rebind_localhost' '1'
        option 'local' '/lan/'
        option 'domain' 'lan'
        option 'expandhosts' '1'
        option 'nonegcache' '0'
        option 'authoritative' '1'
        option 'readethers' '1'
        option 'leasefile' '/tmp/dhcp.leases'
        option 'resolvfile' '/tmp/resolv.conf.auto'
        option 'notinterface' 'tap0'

config 'dhcp' 'lan'
        option 'interface' 'lan'
        option 'start' '151'
        option 'limit' '50'

Do pliku /etc/firewall.user dodajemy następujące polecenia:

ebtables -F
ebtables -I FORWARD -i tap0 -p IPv4 --ip-protocol udp --ip-destination-port 67:68 -j DROP
ebtables -I FORWARD -o tap0 -p IPv4 --ip-protocol udp --ip-destination-port 67:68 -j DROP
ebtables -I INPUT -i tap0 -p IPv4 --ip-protocol udp --ip-destination-port 67:68 -j DROP
ebtables -I OUTPUT -o tap0 -p IPv4 --ip-protocol udp --ip-destination-port 67:68 -j DROP

Instalujemy oprogramowanie, wydając komendy:

opkg update
opkg install openvpn kmod-ebtables-ipv4 ebtables ntpclient

W pliku /etc/config/openvpn dodajemy lub modyfikujemy następujące elementy:

package 'openvpn'

config 'openvpn' 'SiecDomowa'
        option 'enabled' '1'
        option 'client' '1'
        option 'daemon' '1'
        option 'proto' 'tcp-client'
        option 'dev_type' 'tap'
        option 'dev' 'tap0'
        option 'tun_mtu' '1500'
        option 'comp_lzo' '1'
        option 'remote' '123.123.123.123 1194'
        option 'resolv_retry' 'infinite'
        option 'nobind' '1'
        option 'persist_key' '1'
        option 'persist_tun' '1'
        option 'ns_cert_type' 'server'
        option 'ca' '/etc/openvpn/ca.crt'
        option 'cert' '/etc/openvpn/Router-B.crt'
        option 'key' '/etc/openvpn/Router-B.key'

Z Routera-A z katalogu /etc/easy-rsa/keys/ kopiujemy pliki ca.crt, Router-B.crt, Router-B.key do katalogu /etc/openvpn/ na Routerze-B wydając polecenie:

scp root@123.123.123.123:"/etc/easy-rsa/keys/ca.crt /etc/easy-rsa/keys/Router-B.crt /etc/easy-rsa/keys/Router-B.key" /etc/openvpn/

Weryfikujemy ustawienia czasu systemowego routera, wydając komendę:

date

Na koniec, na tym routerze także należy włączyć OpenVPN i także go zrestartować. W tym celu należy wydać polecenia:

/etc/init.d/openvpn enable
reboot

  • Na Routrze-A w pliku /etc/config/firewall należy usunąć tymczasowe sekcje role i redirect o nazwach Allow-SSH TMP i wykonać komendę /etc/init.d/firewall restart

  • Warto z Routera-A wykonać kopię plików z katalogu /etc/easy-rsa/ do bezpiecznego miejsca a następnie katalog ten usunąć.

  • Można z Routera-A odinstalować pakiet easy-rsa wydając komendę opkg remove openvpn-easy-rsa

  • Powyżej znajdują się tylko fragmenty plików konfiguracyjnych. W rzeczywistości pliki te mogą zawierać także inne parametry.

  • Należy zwrócić uwagę na poprawne ustawienie czasu w trakcie generowania kluczy.

  • Ważne, aby na obydwóch routerach poprawnie działała synchronizacja czasu.

Chcę się dostać do hosta podpiętego, do R-B z zewnątrz wchodząc przez R-A. Między LAN-ami działa mi wszystko tak jak trzeba.

Może tak będzie jaśniej:

  • Router R-A
    WAN: (eth1) Internet z IP publicznym 12.34.56.78
    LAN: Bride (wlan0 + eth0 + edge0)
    Redirect 100 -> 192.168.1.10:80
    Redirect 101 -> 192.168.1.20:80

  • Router R-B
    WAN: (eth1) Internet z IP prywatnym
    LAN: Bride (wlan0 + eth0 + edge0)

Gdzie edge0 z R-A i R-B tworzą pomost, czyli LAN R-A = LAN R-B.

  • Komputer K-A
    LAN: 192.168.1.10 wpięty do R-A
    serwer WWW port 80

  • Komputer K-B
    LAN: 192.168.1.20 wpięty do R-BA
    serwer WWW port 80

  1. Z K-A ping do K-B – OK.

  2. Z K-B ping do K-A – OK.

  3. Z K-A próba otwarcia portu 80 na K-B – OK.

  4. Z K-B próba otwarcia portu 80 na K-A – OK.

  5. Z Internetu próba otwarcia portu 100 na 12.34.56.78 – OK.

  6. Z Internetu próba otwarcia portu 101 na 12.34.56.78 – TIMEOUT (nmap – port filtered).

Cezary, forwarding działa poprawnie, ale nie w przypadku, jaki mam.

Mam w dwóch lokalizacjach A i B po jednym routerze R-A i R-B każdy z dostępem do Internetu. LAN-y obsługiwane przez RA- i R-B są w tej samej puli adresowej 192.168.1.0/24. Na obydwóch routerach działa N2N w taki sposób, że do brydża dopięty jest interfejs egde0. Uzyskałem w ten sposób jeden LAN, a urządzenia widzą się bez problemu niezależnie, w której lokalizacji są. DHCP w R-A ma inny zakres niż DHCP w R-B i obydwa nie rozgłaszają po interfejsach edge0. Ogólnie mówiąc wewnątrz LAN-ów wszystko działa jak należy.

Problem polega na tym że R-A ma publiczny IP  i na nim mogę zrobić forwarding, a R-B niema publicznego IP. Natomiast do R-B podpięty jest host, do którego chcę się dostać z zewnątrz.

Forwarding działa poprawnie dopóki przekierowuję porty do hostów dopiętych do R-A, nie działa natomiast gdy robię to do hostów wpiętych do R-B.

Czy masz jakiś pomysł?

Dzięki koledze fruits jest kolejna wersja skryptu ndisup.gcom:

opengt
    let $x="ndisup:"+$basename($dev())+" "
    print $x+"Establishing 3G modem connection in NDIS mode\n"
    print $x+"Script for comgt version 1.05 Rafal Drzymala 2012\n"
#
# Changelog
#    1.00    RD    First stable code
#    1.01    RD    Moved "Getting received signal strength" section
#                Reset command changed from ATZ to ATZ0
#                Changed wait time for establish connection from 20 to 30 secs
#    1.02    RD    Changed signal level bar
#    1.03    RD    Added support for SYSINFOEX modem command
#    1.04    RD    Moved "Checking for password input request" section (frutis suggestion)
#    1.05    RD    Reset command changed AT+CFUN=1 to AT+CFUN=1,1
#                Corrected decode result of AT^SYSINFOEX modem command (frutis suggestion)
#
# Modem succesfuly tested
# - HUAWEI E173        11.126.85.00.209
# Modem tested, not supported 
# - HUAWEI E160G    11.608.02.02.55
# - HUAWEI E160        11.604.09.00.00
# - HUAWEI E220
#
    set com 115200n81
    set ignorecase on
    set comecho off
    set senddelay 0.02

    let $a=$env("APN")
    let $m=$env("MODE")
    let $p=$env("PINCODE")

    if  $a = "" print $x+"APN environment var not specified\n" goto finish    
    let r1=1

:start
# Initializing communication with modem
    if r1=1 print $x+"Try to communicate with modem\n"
    if r1>1 print $x+"Again try to communicate with modem (",r1,")\n"
    waitquiet 2 0.5
    send "ATQ0; E0^m"
    waitfor 1 "OK"
    if % = -1 goto comm_timeout
    send "AT+CMEE=2^m"
    waitfor 1 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 2 waitquiet 1 0.5
    send "AT\^CURC=0^m"
    waitfor 1 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 2 waitquiet 1 0.5

# Checking for password input request
    print $x+"Checking for password input request\n"
    let u=0
    send "AT+CPIN?^m"
    waitfor 5 "+CPIN: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while checking for password input request\n" goto end_chkpin
    if % = 2 gosub cme_error print $x+"Error "+$e+" while checking for password input request\n" goto end_chkpin
    if % = 3 print $x+"Command not supported\n" goto end_chkpin
    get 1 "^mOK^m" $i1
    if % != 0 goto comm_timeout
    let $d="Unknown modem response ("+$i1+")"
    if $i1 = "READY" let $d="MT without password input request"
    if $i1 = "SIM PIN" let $d="UICC/SIM PIN password request"
    if $i1 = "SIM PUK" let $d="UICC/SIM PUK password request, to unblock the SIM PIN which was blocked for 3 verification failure"
    if $i1 = "SIM PIN2" let $d="PIN2 password request"
    if $i1 = "SIM PUK2" let $d="PUK2 password request, to unblock the SIM PIN2 which was blocked for 3 verification failure"
    if $i1 = "PH-SIM PIN" let $d="SIM lock (phone-to-SIM) is required"
    if $i1 = "PH-NET PIN" let $d="Network personnalisation is required"
    print $x+"- state: "+$d+"\n"
    if $i1 = "SIM PIN" goto do_pin_unlock
    if $i1 <> "READY" goto finish
:end_chkpin

# Unlock the PIN 
    goto end_pin_unlock
:do_pin_unlock
    print $x+"UICC/SIM unlocking by PIN\n"
    if $p = "" print $x+"PINCODE environment var not specified\n" goto abort
    send "AT+CPIN="+$p"^m"
    waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while unlocking by PIN\n" goto abort
    if % = 2 gosub cme_error print $x+"Error "+$e+" while unlocking by PIN\n" goto abort
    if % = 3 print $x+"Command not supported\n" goto abort
    print $x+"UICC/SIM unlocked successfully\n"
    let r2=0
:wait_for_reg
    let r2=r2+1
    if r2>5 print $x+"Number of retries exhausted\n" goto abort
    print $x+"Waiting for network registration (",r2,")\n"
    send "AT+CGREG=0; +CGREG?^m"
    waitfor 2 "+CGREG: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while getting network registration status\n" goto end_pin_unlock
    if % = 2 gosub cme_error print $x+"Error "+$e+" while getting network registration status\n" goto end_pin_unlock
    if % = 3 print $x+"Command not supported\n" goto end_pin_unlock
    get 1 "," $i1
    if % != 0 goto comm_timeout
    get 1 "^m^mOK^m" $i2
    if % != 0 goto comm_timeout
    let $d="Unknown modem response ("+$i2+")"
    if $i2 = "0" waitquiet 1 5 goto wait_for_reg
    if $i2 = "1" goto end_pin_unlock
    if $i2 = "2" waitquiet 1 5 goto wait_for_reg
    if $i2 = "3" let $d="Registration rejected"
    if $i2 = "4" let $d="Unknown reasons"
    if $i2 = "5" goto end_pin_unlock
    print $x+"- error: "+$d+"\n"
    goto abort
:end_pin_unlock

# Getting device information
    print $x+"Getting device information\n"
    waitquiet 1 0.2 
    send "AT+CGMI^m"
    get 1 "^mOK^m" $i1
    if % != 0 goto comm_timeout
    waitquiet 1 0.1
    send "AT+CGMM^m"
    get 1 "^mOK^m" $i2
    if % != 0 goto comm_timeout
    waitquiet 1 0.1 
    send "AT+CGMR^m"
    get 1 "^mOK^m" $i3
    if % != 0 goto comm_timeout
    waitquiet 1 0.1
    send "AT+CGSN^m"
    get 1 "^mOK^m" $i4
    if % != 0 goto comm_timeout
    if len($i1)>1 let $i1=$right($i1,len($i1)-1)
    if len($i2)>1 let $i2=$right($i2,len($i2)-1)
    if len($i3)>1 let $i3=$right($i3,len($i3)-1)
    if len($i4)>1 let $i4=$right($i4,len($i4)-1)
    print $x+"- modem: "+$toupper($i1)+" "+$toupper($i2)+"\n"
    print $x+"- firmware: "+$i3+"\n"
    print $x+"- IMEI: "+$i4+"\n"

# Getting received signal strength
    print $x+"Getting received signal strength\n"
    send "AT+CSQ^m"
    waitfor 5 "+CSQ: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while getting received signal strength\n" goto end_sigstr
    if % = 2 gosub cme_error print $x+"Error "+$e+" while getting received signal strength\n" goto end_sigstr
    get 1 "," $i1
    if % != 0 goto comm_timeout
    get 1 "^mOK^m" $i2
    if % != 0 goto comm_timeout
    if $i1 = "99" print $x+"- signal strength: unknown\n" goto end_sigstr
    let s1=val($i1)
    let s2=(s1*2)-113 
    let s3=((s1*100000)/31000)
    print $x+"- signal strength: (",s1,"), ",s2," dBm, ",s3,"%\n"
    let s3=s3/2
    let $s3=$left("##################################################",s3)
    let $s3=$s3+$right("----1----2----3----5----5----6----7----8----9----$",50-s3)
    print $x+"- level: ["+$s3+"]\n"
:end_sigstr

# Checking modem for NDIS support
    print $x+"Checking modem for NDIS support\n"
    send "AT\^DIALMODE?^m" 
    waitfor 5 "\^DIALMODE:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % > 0 print $x+"- This modem doesn't support NDIS mode\n" goto abort
    get 1 "^mOK^m" $i1
    if % != 0 goto comm_timeout
    let $i1=$left($i1,1)
    if $i1 = "1" goto ok_ndis_check
    if $i1 = "2" goto ok_ndis_check
    print $x+"- This modem doesn't support NDIS mode\n"
    goto abort
:ok_ndis_check
    print $x+"- NDIS mode is supported by this modem\n"
    waitquiet 1 1

# Getting system information
    print $x+"Getting system information\n"
:do_sysinfoex
    send "AT\^SYSINFOEX^m"
    waitfor 5 "\^SYSINFOEX:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 goto end_sysinfoex
    if % = 2 gosub cme_error goto end_sysinfoex
    if % = 3 goto end_sysinfoex
    get 1 "," $i1
    if % != 0 goto comm_timeout
    get 1 "," $i2
    if % != 0 goto comm_timeout
    get 1 "," $i3
    if % != 0 goto comm_timeout
    get 1 "," $i4
    if % != 0 goto comm_timeout
    get 1 "," $i5
    if % != 0 goto comm_timeout
    get 1 "," $i6
    if % != 0 goto comm_timeout
    get 1 "," $i7
    if % != 0 goto comm_timeout
    get 1 "," $i8
    if % != 0 goto comm_timeout
    get 1 "^mOK^m" $i9
    if % != 0 goto comm_timeout
    let $d="Unknown modem response ("+$i1+")"
    if $i1 = "0" let $d="No service"
    if $i1 = "1" let $d="Restricted service"
    if $i1 = "2" let $d="Valid service"
    if $i1 = "3" let $d="Restricted regional service"
    if $i1 = "4" let $d="Power-saving and deep sleep state"
    print $x+"- service state: "+$d+"\n"
    let $d="Unknown modem response ("+$i2+")"
    if $i2 = "0" let $d="No service"
    if $i2 = "1" let $d="Only CS service"
    if $i2 = "2" let $d="Only PS service"
    if $i2 = "3" let $d="PS+CS service"
    if $i2 = "4" let $d="CS and PS not registered, searching"
    print $x+"- domain: "+$d+"\n"    
    let $d="Unknown modem response ("+$i3+")"
    if $i3 = "0" let $d="Non roaming state"
    if $i3 = "1" let $d="Roaming state"
    print $x+"- roaming: "+$d+"\n"
    let $d="Unknown modem response ("+$i4+")"
    if $i4 = "0" let $d="Invalid USIM card state or pin code locked"
    if $i4 = "1" let $d="Valid USIM card state"
    if $i4 = "2" let $d="USIM is invalid in case of CS"
    if $i4 = "3" let $d="USIM is invalid in case of PS"
    if $i4 = "4" let $d="USIM is invalid in case of either CS or PS"
    if $i4 = "240" let $d="ROMSIM"
    if $i4 = "255" let $d="USIM card is not existent"
    print $x+"- SIM: "+$d+"\n"
    let $d="Unknown modem response ("+$i6+")"
    if $i7 != "" let d$=$i7 let $i6=""
    if $i6 = "0" let $d="No service"
    if $i6 = "1" let $d="GSM"
    if $i6 = "2" let $d="CDMA"
    if $i6 = "3" let $d="WCDMA"
    if $i6 = "4" let $d="TD-SCDMA"
    if $i6 = "5" let $d="WIMAX"
    if $i6 = "6" let $d="LTE"
    print $x+"- mode: "+$d+"\n"
    let $d="Unknown modem response ("+$i8+")"
    if $i9 != "" let d$=$i9 let $i8=""
    if $i8 = "0" let $d="No service"
    if $i8 = "1" let $d="GSM"
    if $i8 = "2" let $d="GPRS"
    if $i8 = "3" let $d="EDGE"
    if $i8 = "21" let $d="IS95A"
    if $i8 = "22" let $d="IS95B"
    if $i8 = "23" let $d="CDMA2000 1X"
    if $i8 = "24" let $d="EVDO Rel0"
    if $i8 = "25" let $d="EVDO RelA"
    if $i8 = "26" let $d="EVDO RelB"
    if $i8 = "27" let $d="HYBRID (CDMA2000 1X)"
    if $i8 = "28" let $d="HYBRID (EVDO Rel0)"
    if $i8 = "29" let $d="HYBRID (EVDO RelA)"
    if $i8 = "30" let $d="HYBRID (EVDO RelB)"
    if $i8 = "41" let $d="WCDMA"
    if $i8 = "42" let $d="HSDPA"
    if $i8 = "43" let $d="HSUPA"
    if $i8 = "44" let $d="HSPA"
    if $i8 = "45" let $d="HSPA+"
    if $i8 = "46" let $d="DC-HSPA+"
    if $i8 = "61" let $d="TD-SCDMA"
    if $i8 = "62" let $d="HSDPA"
    if $i8 = "63" let $d="HSUPA"
    if $i8 = "64" let $d="HSPA"
    if $i8 = "65" let $d="HSPA+"
    if $i8 = "81" let $d="802.16e"
    if $i8 = "101" let $d="LTE"
    print $x+"- sub mode: "+$d+"\n"
    # Invalid state do finish
    if $i2 = "1" goto abort
    if $i4 = "0" goto abort
    if $i4 = "3" goto finish
    if $i4 = "4" goto finish
    if $i4 = "255" goto finish
    # Invalid state do restart_modem
    if $i1 = "0" goto restart_modem
    if $i1 = "4" goto restart_modem
    if $i2 = "0" goto restart_modem
    if $i2 = "4" goto restart_modem
    if $i6 = "0" goto restart_modem
    goto end_sysinfo
:end_sysinfoex

:do_sysinfo
    send "AT\^SYSINFO^m"
    waitfor 5 "\^SYSINFO:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while getting system information\n" goto end_sysinfo
    if % = 2 gosub cme_error print $x+"Error "+$e+" while getting system information\n" goto end_sysinfo
    if % = 3 print $x+"Command not supported\n" goto end_sysinfo
    get 1 "," $i1
    if % != 0 goto comm_timeout
    get 1 "," $i2
    if % != 0 goto comm_timeout
    get 1 "," $i3
    if % != 0 goto comm_timeout
    get 1 "," $i4
    if % != 0 goto comm_timeout
    get 1 "^mOK^m" $i5
    if % != 0 goto comm_timeout
    if len($i5)>3 let $i6=$right($i5,1)
    let $i5=$left($i5,1)
    let $d="Unknown modem response ("+$i1+")"
    if $i1 = "0" let $d="No service"
    if $i1 = "1" let $d="Restricted service"
    if $i1 = "2" let $d="Valid service"
    if $i1 = "3" let $d="Restricted regional service"
    if $i1 = "4" let $d="Power-saving and deep sleep state"
    print $x+"- service state: "+$d+"\n"
    let $d="Unknown modem response ("+$i2+")"
    if $i2 = "0" let $d="No service"
    if $i2 = "1" let $d="Only CS service"
    if $i2 = "2" let $d="Only PS service"
    if $i2 = "3" let $d="PS+CS service"
    if $i2 = "4" let $d="CS and PS not registered, searching"
    print $x+"- domain: "+$d+"\n"    
    let $d="Unknown modem response ("+$i3+")"
    if $i3 = "0" let $d="Non roaming state"
    if $i3 = "1" let $d="Roaming state"
    print $x+"- roaming: "+$d+"\n"
    let $d="Unknown modem response ("+$i4+")"
    if $i4 = "0" let $d="No service"
    if $i4 = "1" let $d="AMPS"
    if $i4 = "2" let $d="CDMA"
    if $i4 = "3" let $d="GSM/GPRS"
    if $i4 = "4" let $d="HDR"
    if $i4 = "5" let $d="WCDMA"
    if $i4 = "6" let $d="GPS"
    if $i4 = "7" let $d="GSM/WCDMA"
    if $i4 = "8" let $d="CDMA/HDR HYBRID"
    if $i4 = "15" let $d="TD-SCDMA"
    print $x+"- mode: "+$d+"\n"
    let $d="Unknown modem response ("+$i5+")"
    if $i5 = "0" let $d="Invalid USIM card state or pin code locked"
    if $i5 = "1" let $d="Valid USIM card state"
    if $i5 = "2" let $d="USIM is invalid in case of CS"
    if $i5 = "3" let $d="USIM is invalid in case of PS"
    if $i5 = "4" let $d="USIM is invalid in case of either CS or PS"
    if $i5 = "255" let $d="USIM card is not existent"
    print $x+"- SIM: "+$d+"\n"
    let $d="Unknown modem response ("+$i6+")"
    if $i6 = "0" let $d="No service"
    if $i6 = "1" let $d="GSM"
    if $i6 = "2" let $d="GPRS"
    if $i6 = "3" let $d="EDGE"
    if $i6 = "4" let $d="WCDMA"
    if $i6 = "5" let $d="HSDPA"
    if $i6 = "6" let $d="HSUPA"
    if $i6 = "7" let $d="HSDPA and HSUPA"
    if $i6 = "8" let $d="TD_SCDMA"
    if $i6 = "9" let $d="HSPA+"
    if $i6 = "17" let $d="HSPA+(64QAM)"
    if $i6 = "18" let $d="HSPA+(MIMO)"
    print $x+"- sub mode: "+$d+"\n"
    # Invalid state do finish
    if $i2 = "1" goto abort
    if $i5 = "0" goto abort
    if $i5 = "3" goto finish
    if $i5 = "4" goto finish
    if $i5 = "255" goto finish
    # Invalid state do restart_modem
    if $i1 = "0" goto restart_modem
    if $i1 = "4" goto restart_modem
    if $i2 = "0" goto restart_modem
    if $i2 = "4" goto restart_modem
    if $i4 = "0" goto restart_modem
:end_sysinfo

# Getting network registration status
    print $x+"Getting network registration status\n"
    let $i2=""
    send "AT+CGREG=2; +CGREG?^m"
    waitfor 2 "+CGREG: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while getting network registration status\n" goto end_cgreg
    if % = 2 gosub cme_error print $x+"Error "+$e+" while getting network registration status\n" goto end_cgreg
    if % = 3 print $x+"Command not supported\n" goto end_cgreg
    get 1 "," $i1
    if % != 0 goto comm_timeout
    get 1 "^m^mOK^m" $i4
    if % != 0 goto comm_timeout
    let $i2=$left($i4,1)
    if len($i4)>2 let $i3=$mid($i4,2,len($i4)-2)
    let $d="Unknown modem response ("+$i2+")"
    if $i2 = "0" let $d="Not registered. The MS is not searching the new operators to be registered"
    if $i2 = "1" let $d="Local network is registered"
    if $i2 = "2" let $d="Not registered. But the MS is searching the new operators to be registered"
    if $i2 = "3" let $d="Registration rejected"
    if $i2 = "4" let $d="Unknown reasons"
    if $i2 = "5" let $d="Roaming network is registered"
    print $x+"- status: "+$d+"\n"
    print $x+"- lac, ci: "+$i3+"\n"
    send "AT+CGREG=0^m"
    waitfor 1 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 2 waitquiet 1 0.5
:end_cgreg

# Disable CME error report
    send "AT+CMEE=0^m"
    waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout

# Verify if the modem is connected to APN
    print $x+"Verify if the modem is connected to APN\n"
    send "AT\^DHCP?^m"
    waitfor 5 "\^DHCP:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 0 print $x+"Modem is already connected\n" goto do_disconnect
    if % = 3 print $x+"Command not supported\n" goto abort
    print $x+"No connection detected\n"

# Disconnecting from current APN
goto end_disconnect
:do_disconnect
    print $x+"Disconnecting from current APN\n"
    send "AT\^NDISDUP=1,0^m"
    waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while disconnecting from current APN\n" goto abort
    if % = 2 gosub cme_error print $x+"Error "+$e+" while disconnecting from current APN\n" goto abort
    if % = 3 print $x+"Command not supported\n" goto abort
    print $x+"Disconnected successfully\n"
    waitquiet 1 0.5
:end_disconnect    

# Setting mode
    if $m = "" goto end_mode_set
    print $x+"Setting mode "+$m+"\n"
    send $m+"^m"
    waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while setting mode error\n" goto abort
    if % = 2 gosub cme_error print $x+"Error "+$e+" while setting mode error\n" goto abort
    if % = 3 print $x+"Command not supported\n" goto abort
    print $x+"Mode set successfully\n"
:end_mode_set

# Establishing connection
    print $x+"Try to establish connection via APN "+$a+"\n"
    send "AT\^NDISDUP=1,1,\""+$a+"\"^m" 
    waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while connecting\n" goto abort
    if % = 2 gosub cme_error print $x+"Error "+$e+" while connecting\n" goto abort
    if % = 3 print $x+"Command not supported\n" goto abort
    print $x+"Waiting for establish connection\n"
    let r3=0
:wait_for_connection    
    let r3=r3+1
    if r3>30 goto restart_modem
    send "AT\^DHCP?^m"
    waitfor 5 "\^DHCP:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 0 print $x+"Connection established\n" goto finish
    if % = 1 waitquiet 1 1 goto wait_for_connection
    if % = 2 waitquiet 1 1 goto wait_for_connection
    if % = 3 print $x+"Command not supported\n" goto abort

# In case of normal exit
:finish
    print $x+"Done.\n"
    exit 0

# In case of occurred an error
:abort
    print $x+"Done!\n"
    exit 1

# Error CME routine
:cme_error
    get 1 "^m" $e
    let $e="'"+$e+"'"
    return

# Restarting modem and start all
:restart_modem
    let r1=r1+1
    if r1>5 print $x+"Number of restart retries was exhausted\n" goto abort
    print $x+"Restarting modem\n"
    waitquiet 2 2
    send "AT\^NDISDUP=1,0^m"
    waitquiet 2 1
    send "ATZ0^m"
    waitquiet 2 1
    send "AT&F^m"
    waitquiet 2 1
    send "AT+CFUN=1,1^m"
    waitquiet 2 1
    goto start

# Timeout detected
:comm_timeout
    print $x+"Modem is not responding, timeout detected\n"
    goto restart_modem
# Done

Nie, skrypty nie są uniwersalne. Miałem tylko kilka modemów i klika różnych router-ów, a patrząc na ich ilość na rynku nie można założyć że skrypty zadziałają z każdą konfiguracją.

Niestety takie same efekty z iptables jak i konfiguracja z przez UCI. Każdy niby otwarty port jest widziany jako filtered. Dzisiaj będę testował na fabrycznym firmware.

Cezary czy Ty testowałeś na TL-WDR4300 z AA 12.09-rc1?

Podsunąłeś mi pomysł z AT+CFUN=1,1, zmienię ndisup.gcom i sprawdzę. Potem sprawdzę AT+CFUN=4 a później AT+CFUN=6.

W moim przypadku reboot działa idealnie. Jak maiłem TL-MR3420 to w nim wyłączałem zasilanie modemu przez GPIO:

echo 0 > /sys/devices/virtual/gpio/gpio6/value
sleep 1
echo 1 > /sys/devices/virtual/gpio/gpio6/value

ale to nie zawsze pomagało. Teraz w jego miejscu pracuje WRT160NL a on niema możliwości wyłączenia zasilania GPIO.

Witaj,
sprawdzę kod.
A co do automatycznego restartu router-a, to raz na jakiś czas występują problemy z nawiązaniem połączenia (słaby sygnał, przez który często zrywa się połączenie) i żadne soft-resety modemu nie pomagają. Dzięki reboot-owi odzyskuję połączenie i władzę nad ruoterem, który pracuje kilkaset kilometrów ode mnie.

Witam,
dodałem do skryptu 3gtester.sh opcjonalny reboot routera, gdy upłynie zadany czas od ostatniego poprawnie wysłanego ICMP przez dany interfejs.

Jeżeli w network dodamy opcję rebootafter z ilością sekund:

uci set network.wan2=interface
uci set network.wan2.ifname=usb0
uci set network.wan2.proto=dhcp
uci set network.wan2.comm=/dev/ttyUSB2
uci set network.wan2.mode="AT^SYSCFG=2,2,3FFFFFFF,2,4"
uci set network.wan2.pincode=
uci set network.wan2.apn=darmowy
uci set network.wan2.username=
uci set network.wan2.password=
uci set network.wan2.macaddr=00:01:02:03:04:05
uci set network.wan2.auto=0
uci set network.wan2.defaultroute=0
uci set network.wan2.peerdns=0
uci set network.wan2.dns='8.8.8.8 8.8.4.4'
uci set network.wan2.rebootafter=900

to skrypt będzie reboot-ował router, gdy tylko przez wskazany czas nieuka się wysłać pinga przez ten właśnie interfejs.

Nowa wersja pliku 3gtester.sh:

#!/bin/sh
# Establishing 3G modem connection in dialup or NDIS mode
# Script version 1.07 Rafal Drzymala 2012
#
# Changelog
#    1.00    RD    First stable code
#    1.01    RD    Prevent from parallel comgt/gcom execution
#    1.02    RD    Added logger priority, redirect comgt/gcom to logger
#    1.03    RD    Changed ICMP monitoring, use device, multiwan or default dns
#    1.04    RD    Changed ICMP data size to 1 byte
#    1.05    RD    Changed log messages, added wwan interface detection (frutis suggestion)
#    1.06    RD    Added router auto-reboot after connection timeout detected (if rebootafter option in network present)
#    1.07    RD    Added reboots log
#
SCR=$(basename $0)
DEF_ICMP="8.8.8.8 8.8.4.4"
COMGT_APP="gcom"
NDISUP="/etc/gcom/ndisup.gcom"
FPATH="/usr/data/"
WANS=$(uci show network | awk -F[.=] '{if (($3=="proto" && $4=="3g") || ($3=="ifname" && (match($4,"usb[0-9]") || match($4,"wwan[0-9]")))) print $2}')
for WAN in $WANS; do
    NDIS="N"
    UPTIME=$(cut -d "." -f1 /proc/uptime)
    NOW=$(date -u +"%Y.%m.%d-%H:%M:%S %s")
    [ $(uci -q get network.$WAN.proto) != "3g" ] && NDIS="Y"
    DEV_IFNAME=$(uci -q get network.$WAN.ifname)
    DEV_APN=$(uci -q get network.$WAN.apn)
    DEV_PINCODE=$(uci -q get network.$WAN.pincode)
    DEV_MODE=$(uci -q get network.$WAN.mode)
    DEV_REBOOTAFTER=$(uci -q get network.$WAN.rebootafter)
    [ "$NDIS" == "Y" ] && DEV_COMM=$(uci -q get network.$WAN.comm)
    [ "$NDIS" == "N" ] && DEV_COMM=$(uci -q get network.$WAN.device)
    DEV_AUTO="1"
    [ "$NDIS" == "N" ] && DEV_AUTO=$(uci -q get network.$WAN.auto)
    DEV_ICMP=$(uci -q get network.$WAN.dns)
    [ "$DEV_ICMP" == "" ] && DEV_ICMP=$(uci -q get multiwan.$WAN.dns)
    [ "$DEV_ICMP" == "" ] && DEV_ICMP=$DEF_ICMP
    logger -p user.notice -t $SCR "Checking for active connection $WAN ($DEV_IFNAME) attempting to ping $DEV_ICMP"
    if [ "$DEV_AUTO" == "1" ]; then
        if [ -e $DEV_COMM ]; then
            echo "$NOW $UPTIME" >$FPATH$SCR.$WAN.check
            for ICMP in $DEV_ICMP; do
                if ping -q -c 1 -W 2 -s 1 -I $DEV_IFNAME $ICMP &>/dev/null; then
                    ICMP_OK=$ICMP
                    break
                fi
            done
            if [ "$ICMP_OK" != "" ]; then
                logger -p user.notice -t $SCR "ICMP successfully sent via $WAN ($DEV_IFNAME) to $ICMP_OK"
                echo "$NOW $UPTIME" >$FPATH$SCR.$WAN.ok
            else
                logger -p user.notice -t $SCR "Restarting connection $WAN ($DEV_IFNAME) using device $DEV_COMM and apn $DEV_APN"
                [ "$DEV_MODE" != "" ] && logger -t $SCR "Using additional modem command $DEV_MODE"
                if [ "$NDIS" == "N" ]; then
                    (ifdown $WAN; sleep 2; ifup $WAN) &
                else
                    COMGT_DEV="-d $DEV_COMM"
                    COMGT_SCR="-s $NDISUP"
                    if pgrep -l -f "$COMGT_APP $COMGT_DEV $COMGT_SCR"> /dev/null; then
                        logger -p user.notice -t $SCR "Connection $WAN ($DEV_IFNAME) is already restarted"
                    elif pgrep -l -f "$COMGT_APP $COMGT_DEV"> /dev/null; then
                        logger -p user.notice -t $SCR "Device $DEV_COMM used by another instance of $COMGT_APP"
                    elif ([ "$DEV_COMM" == "/dev/ttyUSB2" ] || [ "$DEV_COMM" == "/dev/noz2" ] || [ "$DEV_COMM" == "/dev/modem" ]) && pgrep -l -f  "$COMGT_APP" | grep -q -v "\-d"> /dev/null; then
                        logger -p user.notice -t $SCR "Device $DEV_COMM used by another instance of $COMGT_APP"
                    else
                        (ifdown $WAN; PINCODE=$DEV_PINCODE APN=$DEV_APN MODE=$DEV_MODE $COMGT_APP $COMGT_DEV $COMGT_SCR | logger -p user.notice -t $COMGT_APP; sleep 2; ifup $WAN) &
                    fi
                fi
            fi
            if [ "$DEV_REBOOTAFTER" != "" ] && [ "$UPTIME" -ge "$DEV_REBOOTAFTER" ]; then
                LAST_ICMP_CHK=$(cut -d " " -f3 $FPATH$SCR.$WAN.check)
                LAST_ICMP_OK=$(cut -d " " -f3 $FPATH$SCR.$WAN.ok)
                if [ "$LAST_ICMP_CHK" != "" ] && [ "$LAST_ICMP_OK" != "" ] && [ "$(($UPTIME-$LAST_ICMP_OK))" -ge "$DEV_REBOOTAFTER" ]; then
                    logger -p user.notice -t $SCR "Device $WAN ($DEV_IFNAME) reboot timeout detected, rebooting router..."
                    echo "$NOW $UPTIME $WAN" >>$FPATH$SCR.reboots
                    reboot
                fi
            fi
        else
            logger -p user.error -t $SCR "Device $DEV_COMM for $WAN not exist"
        fi
    fi
done
# Done

Do funkcjonowania nowej opcji potrzebny jest katalog /usr/data/

Witam ponownie. Mielę ten temat do kilku dni bez wyraźnego skutku.
Doszedłem do tego że gdy reguła ma jw. option src_dport ‘xxx’ to otwiera się dużo więcej portów niż tylko wskazany ‘xxx’. Oczywiście w tym przypadku zamiast, powinno być option dest_port.

Mam publiczne IP, próbuję od dłuższego czasu zrobić forwarding jw. portu 443 na port 7000 jednego z hostów w moim LAN-ie. Niby proste ale nie działa. Pod ręką mam tylko WDR4300 i najnowsze AA 12.09-rc1 od Cezarego.

Dodam że wewnętrzny forwarding działa, gdy dodałem regułę dla ICMP mogę sobie ping-ować do woli ale żaden forwarding z zewnątrz nie działa.

Robiłem forwarding z Backfire na innym sprzęcie i działało. Pomocy!

Dzięki. Wymiękam:(

Witam ponownie,
napisałem że otwierają się porty 80 i 443 bo takie zauważyłem, okazuje się że otwiera się wszystko:(
Jeżeli ktoś ma taką rolę lub chce mu się sprawdzić na AA 12.09 i przeskanuje porty będę wdzięczny za info.

Domyślne są w pierwszym poście.

Po restarcie routera i kompa lokalny (drugi) redirect nadal działa.

config redirect
        option _name 'Redir-LAN-xx'
        option src 'lan'
        option src_dport '443'
        option src_dip 'yy.yy.yy.yy'
        option proto 'tcp'
        option dest_ip '192.168.1.xx'
        option dest_port '7000'

Takie coś robi skrypt dla tych ustawień:

. . .
Loading rules
iptables --table filter --insert zone_wan 1 --jump ACCEPT -p udp --dport 68
iptables --table filter --insert zone_hotspot 1 --jump ACCEPT -p udp --sport 67:68 --dport 67:68 -m limit --limit 10/sec
iptables --table filter --insert zone_hotspot 2 --jump ACCEPT -p tcp --dport 53 -m limit --limit 1000/sec
iptables --table filter --insert zone_hotspot 3 --jump ACCEPT -p udp --dport 53 -m limit --limit 1000/sec
iptables --table filter --insert zone_wan 2 --jump ACCEPT -p tcp
Loading redirects
iptables --table nat --insert zone_wan_prerouting 1 --jump DNAT -p tcp --dport 443 --to-destination 192.168.1.xx:7000
iptables --table filter --insert zone_wan_forward 1 --jump ACCEPT -d 192.168.1.xx/32 -p tcp --dport 7000
iptables --table nat --insert zone_lan_prerouting 1 --jump DNAT -d yy.yy.yy.yy/32 -p tcp --dport 443 --to-destination 192.168.1.xx:7000
iptables --table filter --insert zone_lan_forward 1 --jump ACCEPT -d 192.168.1.xx/32 -p tcp --dport 7000
Loading includes
. . .

Ani jednego ani drugiego redirection dla 443, a działają obydwa. Sprawdzałem kilka razy.

Sprawdzam mxtoolbox.com oraz z drugiego kompa podpiętego bezpośrenio do internetu przez inne łącze.

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
   13   728 ACCEPT     all  --  any    any     anywhere             anywhere            ctstate RELATED,ESTABLISHED
    0     0 DROP       all  --  any    any     anywhere             anywhere            ctstate INVALID
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere
    0     0 syn_flood  tcp  --  any    any     anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/SYN
    1   351 input_rule  all  --  any    any     anywhere             anywhere
    1   351 input      all  --  any    any     anywhere             anywhere

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  any    any     anywhere             anywhere            ctstate RELATED,ESTABLISHED
    0     0 DROP       all  --  any    any     anywhere             anywhere            ctstate INVALID
    0     0 forwarding_rule  all  --  any    any     anywhere             anywhere
    0     0 forward    all  --  any    any     anywhere             anywhere
    0     0 reject     all  --  any    any     anywhere             anywhere

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
   13  1584 ACCEPT     all  --  any    any     anywhere             anywhere            ctstate RELATED,ESTABLISHED
    0     0 DROP       all  --  any    any     anywhere             anywhere            ctstate INVALID
    0     0 ACCEPT     all  --  any    lo      anywhere             anywhere
    0     0 output_rule  all  --  any    any     anywhere             anywhere
    0     0 output     all  --  any    any     anywhere             anywhere

Chain forward (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 zone_lan_forward  all  --  br-lan any     anywhere             anywhere
    0     0 zone_wan_forward  all  --  eth0.2 any     anywhere             anywhere

Chain forwarding_hotspot (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain forwarding_lan (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain forwarding_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 nat_reflection_fwd  all  --  any    any     anywhere             anywhere

Chain forwarding_wan (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain input (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 zone_lan   all  --  br-lan any     anywhere             anywhere
    1   351 zone_wan   all  --  eth0.2 any     anywhere             anywhere

Chain input_hotspot (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain input_lan (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain input_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain input_wan (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain nat_reflection_fwd (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     tcp  --  any    any     192.168.1.0/24       192.168.1.xx     tcp dpt:7000

Chain output (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 zone_lan_ACCEPT  all  --  any    any     anywhere             anywhere
    0     0 zone_wan_ACCEPT  all  --  any    any     anywhere             anywhere
    0     0 zone_hotspot_ACCEPT  all  --  any    any     anywhere             anywhere

Chain output_rule (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain reject (5 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 REJECT     tcp  --  any    any     anywhere             anywhere            reject-with tcp-reset
    0     0 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-port-unreachable

Chain syn_flood (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 RETURN     tcp  --  any    any     anywhere             anywhere            tcp flags:FIN,SYN,RST,ACK/SYN limit: avg 25/sec burst 50
    0     0 DROP       all  --  any    any     anywhere             anywhere

Chain zone_hotspot (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     udp  --  any    any     anywhere             anywhere            udp spts:bootps:bootpc dpts:bootps:bootpc limit: avg 10/sec burst 5
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere            tcp dpt:domain limit: avg 1000/sec burst 5
    0     0 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:domain limit: avg 1000/sec burst 5
    0     0 input_hotspot  all  --  any    any     anywhere             anywhere
    0     0 zone_hotspot_REJECT  all  --  any    any     anywhere             anywhere

Chain zone_hotspot_ACCEPT (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain zone_hotspot_DROP (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 LOG        all  --  any    any     anywhere             anywhere            limit: avg 10/min burst 5 LOG level warning prefix `DROP(hotspot):'

Chain zone_hotspot_REJECT (2 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 LOG        all  --  any    any     anywhere             anywhere            limit: avg 10/min burst 5 LOG level warning prefix `REJECT(hotspot):'

Chain zone_hotspot_forward (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 zone_wan_ACCEPT  all  --  any    any     anywhere             anywhere
    0     0 forwarding_hotspot  all  --  any    any     anywhere             anywhere
    0     0 zone_hotspot_REJECT  all  --  any    any     anywhere             anywhere

Chain zone_lan (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 input_lan  all  --  any    any     anywhere             anywhere
    0     0 zone_lan_ACCEPT  all  --  any    any     anywhere             anywhere

Chain zone_lan_ACCEPT (2 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  any    br-lan  anywhere             anywhere
    0     0 ACCEPT     all  --  br-lan any     anywhere             anywhere

Chain zone_lan_DROP (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all  --  any    br-lan  anywhere             anywhere
    0     0 DROP       all  --  br-lan any     anywhere             anywhere

Chain zone_lan_REJECT (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 reject     all  --  any    br-lan  anywhere             anywhere
    0     0 reject     all  --  br-lan any     anywhere             anywhere

Chain zone_lan_forward (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     tcp  --  any    any     anywhere             192.168.1.xx     tcp dpt:7000
    0     0 zone_wan_ACCEPT  all  --  any    any     anywhere             anywhere
    0     0 forwarding_lan  all  --  any    any     anywhere             anywhere
    0     0 zone_lan_REJECT  all  --  any    any     anywhere             anywhere

Chain zone_wan (1 references)
 pkts bytes target     prot opt in     out     source               destination
    1   351 ACCEPT     udp  --  any    any     anywhere             anywhere            udp dpt:bootpc
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere
    0     0 input_wan  all  --  any    any     anywhere             anywhere
    0     0 zone_wan_REJECT  all  --  any    any     anywhere             anywhere

Chain zone_wan_ACCEPT (3 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  any    eth0.2  anywhere             anywhere
    0     0 ACCEPT     all  --  eth0.2 any     anywhere             anywhere

Chain zone_wan_DROP (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all  --  any    eth0.2  anywhere             anywhere
    0     0 DROP       all  --  eth0.2 any     anywhere             anywhere

Chain zone_wan_REJECT (2 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 reject     all  --  any    eth0.2  anywhere             anywhere
    0     0 reject     all  --  eth0.2 any     anywhere             anywhere

Chain zone_wan_forward (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     tcp  --  any    any     anywhere             192.168.1.xx     tcp dpt:7000
    0     0 forwarding_wan  all  --  any    any     anywhere             anywhere
    0     0 zone_wan_REJECT  all  --  any    any     anywhere             anywhere

dla pełnego obrazu jest jeszcze czesc dla Hotspot-a

config rule
        option _name 'Allow-DHCP-Renew-Hotspot'
        option src 'hotspot'
        option proto 'udp'
        option limit '10/sec'
        option src_port '67-68'
        option dest_port '67-68'
        option target 'ACCEPT'
        option family 'ipv4'

config rule
        option _name 'Allow-DNS-Request-Hotspot'
        option src 'hotspot'
        option dest_port '53'
        option limit '1000/sec'
        option target 'ACCEPT'
        option family 'ipv4'
        option proto 'tcpudp'

config zone
        option name 'hotspot'
        option network 'hotspot'
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option log '1'

config forwarding
        option src 'hotspot'
        option dest 'wan'
        option family 'ipv4'

Witam,
Coś dziwnego dzieje mi się z firewall-em, po dodaniu reguły otwiera mi się zarówno port 443 jak i 80.

Podstawowe ustawienia firewall (brak „dziur”):

config defaults
        option syn_flood '1'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option block_static_ip_mismatches '1'
        option force_router_dns '1'
        option drop_invalid '1'

config zone
        option name 'lan'
        option network 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'

config zone
        option name 'wan'
        list network 'wan'
        list network 'wan2'
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option masq '1'
        option mtu_fix '1'

config forwarding
        option src 'lan'
        option dest 'wan'

config rule
        option _name 'Allow-DHCP-Renew'
        option src 'wan'
        option proto 'udp'
        option dest_port '68'
        option target 'ACCEPT'
        option family 'ipv4'

config include
        option path '/etc/firewall.user'

Dodanie poniższego przekierowania otwiera port 443:

config redirect
        option _name 'Redir-WAN-xx'
        option src 'wan'
        option src_dport '443'
        option proto 'tcp'
        option dest 'lan'
        option dest_ip '192.168.1.xx'
        option dest_port '7000'

config redirect
        option _name 'Redir-LAN-xx'
        option src 'lan'
        option src_dport '443'
        option src_dip 'yy.yy.yy.yy'
        option proto 'tcp'
        option dest_ip '192.168.1.xx'
        option dest_port '7000'

Dodanie poniższej reguły otwiera także port 80:

config rule
       option _name 'Allow-WAN-xx'
       option src 'wan'
       option src_dport '443'
       option proto 'tcp'
       option target 'ACCEPT'

Czy ma ktoś taki problem i wie jak go rozwiązać?

247

(175 odpowiedzi, napisanych Oprogramowanie / Software)

Było by fajnie.
To nie tylko skrypt, Aleksander trochę się napisał tu są np. kody biblioteki dla QMI http://www.lanedo.com/~aleksander/libqmi-glib/.

248

(175 odpowiedzi, napisanych Oprogramowanie / Software)

Cezary, czy możesz dodać do swojego repozytorium AA wsparcie dla QMI (https://gitorious.org/lanedo/openwrt-pa … mi-support)?
Po testowałbym to rozwiązanie.

Zmodyfikowałem skrypty zgodnie z Twoimi spostrzeżeniami

frutis napisał/a:

Mam pewne uwagi co do skryptów.
W trunku interfejs sieciowy modemu nazywa się wwan0 a nie usb0 jak to było wcześniej i trzeba by dodać wyszukiwanie takich interfejsów w 3gtester.sh.
W skrypcie ndisup.gcom wpisywanie pinu powinno znajdować się gdzieś na początku. Inaczej dostaje komunikat, że modem (E372) nie obsługuje NDIS.
Wydaje mi się też, że logowanie informacji o interfejsie lub apn przy każdym uruchomieniu skryptu (a jest on często uruchamiany) jest zbędne.

skrypt /bin/3gtester.sh

#!/bin/sh
# Establishing 3G modem connection in dialup or NDIS mode
# Script version 1.05 Rafal Drzymala 2012
#
# Changelog
#    1.00    RD    First stable code
#    1.01    RD    Prevent from parallel comgt/gcom execution
#    1.02    RD    Added logger priority, redirect comgt/gcom to logger
#    1.03    RD    Changed ICMP monitoring, use device, multiwan or default dns
#    1.04    RD    Changed ICMP data size to 1 byte
#    1.05    RD    Changed log messages, added wwan interface detection (frutis suggestion)
#
SCR=$(basename $0)
DEF_ICMP="8.8.8.8 8.8.4.4"
COMGT_APP="gcom"
NDISUP="/etc/gcom/ndisup.gcom"
WANS=$(uci show network | awk -F[.=] '{if (($3=="proto" && $4=="3g") || ($3=="ifname" && (match($4,"usb[0-9]") || match($4,"wwan[0-9]")))) print $2}')
for WAN in $WANS; do
    NDIS="N"
    [ $(uci -q get network.$WAN.proto) != "3g" ] && NDIS="Y"
    DEV_IFNAME=$(uci -q get network.$WAN.ifname)
    DEV_APN=$(uci -q get network.$WAN.apn)
    DEV_PINCODE=$(uci -q get network.$WAN.pincode)
    DEV_MODE=$(uci -q get network.$WAN.mode)
    [ "$NDIS" == "Y" ] && DEV_COMM=$(uci -q get network.$WAN.comm)
    [ "$NDIS" == "N" ] && DEV_COMM=$(uci -q get network.$WAN.device)
    DEV_AUTO="1"
    [ "$NDIS" == "N" ] && DEV_AUTO=$(uci -q get network.$WAN.auto)
    DEV_ICMP=$(uci -q get network.$WAN.dns)
    [ "$DEV_ICMP" == "" ] && DEV_ICMP=$(uci -q get multiwan.$WAN.dns)
    [ "$DEV_ICMP" == "" ] && DEV_ICMP=$DEF_ICMP
    logger -p user.notice -t $SCR "Checking for active connection $WAN ($DEV_IFNAME) attempting to ping $DEV_ICMP"
    if [ "$DEV_AUTO" == "1" ]; then
        if [ -e $DEV_COMM ]; then
            for ICMP in $DEV_ICMP; do
                if ping -q -c 1 -W 2 -s 1 -I $DEV_IFNAME $ICMP &>/dev/null; then
                    ICMP_OK=$ICMP
                    break
                fi
            done
            if [ "$ICMP_OK" != "" ]; then
                logger -p user.notice -t $SCR "ICMP successfully sent via $WAN ($DEV_IFNAME) to $ICMP_OK"
            else
                logger -p user.notice -t $SCR "Restarting connection $WAN ($DEV_IFNAME) using device $DEV_COMM and apn $DEV_APN"
                [ "$DEV_MODE" != "" ] && logger -t $SCR "Using additional modem command $DEV_MODE"
                if [ "$NDIS" == "N" ]; then
                    (ifdown $WAN; sleep 2; ifup $WAN) &
                else
                    COMGT_DEV="-d $DEV_COMM"
                    COMGT_SCR="-s $NDISUP"
                    if pgrep -l -f "$COMGT_APP $COMGT_DEV $COMGT_SCR"> /dev/null; then
                        logger -p user.notice -t $SCR "Connection $WAN ($DEV_IFNAME) is already restarted"
                    elif pgrep -l -f "$COMGT_APP $COMGT_DEV"> /dev/null; then
                        logger -p user.notice -t $SCR "Device $DEV_COMM used by another instance of $COMGT_APP"
                    elif ([ "$DEV_COMM" == "/dev/ttyUSB2" ] || [ "$DEV_COMM" == "/dev/noz2" ] || [ "$DEV_COMM" == "/dev/modem" ]) && pgrep -l -f  "$COMGT_APP" | grep -q -v "\-d"> /dev/null; then
                        logger -p user.notice -t $SCR "Device $DEV_COMM used by another instance of $COMGT_APP"
                    else
                        (ifdown $WAN; PINCODE=$DEV_PINCODE APN=$DEV_APN MODE=$DEV_MODE $COMGT_APP $COMGT_DEV $COMGT_SCR | logger -p user.notice -t $COMGT_APP; sleep 2; ifup $WAN) &
                    fi
                fi
            fi
        else
            logger -p user.error -t $SCR "Device $DEV_COMM for $WAN not exist"
        fi
    fi
done
# Done

skrypt /etc/gcom/ndisup.gcom

opengt
    let $x="ndisup:"+$basename($dev())+" "
    print $x+"Establishing 3G modem connection in NDIS mode\n"
    print $x+"Script for comgt version 1.04 Rafal Drzymala 2012\n"
#
# Changelog
#    1.00    RD    First stable code
#    1.01    RD    Moved "Getting received signal strength" section
#                Reset command changed from ATZ to ATZ0
#                Changed wait time for establish connection from 20 to 30 secs
#    1.02    RD    Changed signal level bar
#    1.03    RD    Added support for SYSINFOEX modem command
#    1.04    RD    Moved "Checking for password input request" section (frutis suggestion)
#
# Modem succesfuly tested
# - HUAWEI E173        11.126.85.00.209
# Modem tested, not supported 
# - HUAWEI E160G    11.608.02.02.55
# - HUAWEI E160        11.604.09.00.00
# - HUAWEI E220
#
    set com 115200n81
    set ignorecase on
    set comecho off
    set senddelay 0.02

    let $a=$env("APN")
    let $m=$env("MODE")
    let $p=$env("PINCODE")

    if  $a = "" print $x+"APN environment var not specified\n" goto finish    
    let r1=1

:start
# Initializing communication with modem
    if r1=1 print $x+"Try to communicate with modem\n"
    if r1>1 print $x+"Again try to communicate with modem (",r1,")\n"
    waitquiet 2 0.5
    send "ATQ0; E0^m"
    waitfor 1 "OK"
    if % = -1 goto comm_timeout
    send "AT+CMEE=2^m"
    waitfor 1 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 2 waitquiet 1 0.5
    send "AT\^CURC=0^m"
    waitfor 1 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 2 waitquiet 1 0.5

# Checking for password input request
    print $x+"Checking for password input request\n"
    let u=0
    send "AT+CPIN?^m"
    waitfor 5 "+CPIN: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while checking for password input request\n" goto end_chkpin
    if % = 2 gosub cme_error print $x+"Error "+$e+" while checking for password input request\n" goto end_chkpin
    if % = 3 print $x+"Command not supported\n" goto end_chkpin
    get 1 "^mOK^m" $i1
    if % != 0 goto comm_timeout
    let $d="Unknown modem response ("+$i1+")"
    if $i1 = "READY" let $d="MT without password input request"
    if $i1 = "SIM PIN" let $d="UICC/SIM PIN password request"
    if $i1 = "SIM PUK" let $d="UICC/SIM PUK password request, to unblock the SIM PIN which was blocked for 3 verification failure"
    if $i1 = "SIM PIN2" let $d="PIN2 password request"
    if $i1 = "SIM PUK2" let $d="PUK2 password request, to unblock the SIM PIN2 which was blocked for 3 verification failure"
    if $i1 = "PH-SIM PIN" let $d="SIM lock (phone-to-SIM) is required"
    if $i1 = "PH-NET PIN" let $d="Network personnalisation is required"
    print $x+"- state: "+$d+"\n"
    if $i1 = "SIM PIN" goto do_pin_unlock
    if $i1 <> "READY" goto finish
:end_chkpin

# Unlock the PIN 
    goto end_pin_unlock
:do_pin_unlock
    print $x+"UICC/SIM unlocking by PIN\n"
    if $p = "" print $x+"PINCODE environment var not specified\n" goto abort
    send "AT+CPIN="+$p"^m"
    waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while unlocking by PIN\n" goto abort
    if % = 2 gosub cme_error print $x+"Error "+$e+" while unlocking by PIN\n" goto abort
    if % = 3 print $x+"Command not supported\n" goto abort
    print $x+"UICC/SIM unlocked successfully\n"
    let r2=0
:wait_for_reg
    let r2=r2+1
    if r2>5 print $x+"Number of retries exhausted\n" goto abort
    print $x+"Waiting for network registration (",r2,")\n"
    send "AT+CGREG=0; +CGREG?^m"
    waitfor 2 "+CGREG: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while getting network registration status\n" goto end_pin_unlock
    if % = 2 gosub cme_error print $x+"Error "+$e+" while getting network registration status\n" goto end_pin_unlock
    if % = 3 print $x+"Command not supported\n" goto end_pin_unlock
    get 1 "," $i1
    if % != 0 goto comm_timeout
    get 1 "^m^mOK^m" $i2
    if % != 0 goto comm_timeout
    let $d="Unknown modem response ("+$i2+")"
    if $i2 = "0" waitquiet 1 5 goto wait_for_reg
    if $i2 = "1" goto end_pin_unlock
    if $i2 = "2" waitquiet 1 5 goto wait_for_reg
    if $i2 = "3" let $d="Registration rejected"
    if $i2 = "4" let $d="Unknown reasons"
    if $i2 = "5" goto end_pin_unlock
    print $x+"- error: "+$d+"\n"
    goto abort
:end_pin_unlock

# Getting device information
    print $x+"Getting device information\n"
    waitquiet 1 0.2 
    send "AT+CGMI^m"
    get 1 "^mOK^m" $i1
    if % != 0 goto comm_timeout
    waitquiet 1 0.1
    send "AT+CGMM^m"
    get 1 "^mOK^m" $i2
    if % != 0 goto comm_timeout
    waitquiet 1 0.1 
    send "AT+CGMR^m"
    get 1 "^mOK^m" $i3
    if % != 0 goto comm_timeout
    waitquiet 1 0.1
    send "AT+CGSN^m"
    get 1 "^mOK^m" $i4
    if % != 0 goto comm_timeout
    if len($i1)>1 let $i1=$right($i1,len($i1)-1)
    if len($i2)>1 let $i2=$right($i2,len($i2)-1)
    if len($i3)>1 let $i3=$right($i3,len($i3)-1)
    if len($i4)>1 let $i4=$right($i4,len($i4)-1)
    print $x+"- modem: "+$toupper($i1)+" "+$toupper($i2)+"\n"
    print $x+"- firmware: "+$i3+"\n"
    print $x+"- IMEI: "+$i4+"\n"

# Getting received signal strength
    print $x+"Getting received signal strength\n"
    send "AT+CSQ^m"
    waitfor 5 "+CSQ: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while getting received signal strength\n" goto end_sigstr
    if % = 2 gosub cme_error print $x+"Error "+$e+" while getting received signal strength\n" goto end_sigstr
    get 1 "," $i1
    if % != 0 goto comm_timeout
    get 1 "^mOK^m" $i2
    if % != 0 goto comm_timeout
    if $i1 = "99" print $x+"- signal strength: unknown\n" goto end_sigstr
    let s1=val($i1)
    let s2=(s1*2)-113 
    let s3=((s1*100000)/31000)
    print $x+"- signal strength: (",s1,"), ",s2," dBm, ",s3,"%\n"
    let s3=s3/2
    let $s3=$left("##################################################",s3)
    let $s3=$s3+$right("----1----2----3----5----5----6----7----8----9----$",50-s3)
    print $x+"- level: ["+$s3+"]\n"
:end_sigstr

# Checking modem for NDIS support
    print $x+"Checking modem for NDIS support\n"
    send "AT\^DIALMODE?^m" 
    waitfor 5 "\^DIALMODE:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % > 0 print $x+"- This modem doesn't support NDIS mode\n" goto abort
    get 1 "^mOK^m" $i1
    if % != 0 goto comm_timeout
    let $i1=$left($i1,1)
    if $i1 = "1" goto ok_ndis_check
    if $i1 = "2" goto ok_ndis_check
    print $x+"- This modem doesn't support NDIS mode\n"
    goto abort
:ok_ndis_check
    print $x+"- NDIS mode is supported by this modem\n"
    waitquiet 1 1

# Getting system information
    print $x+"Getting system information\n"
:do_sysinfoex
    send "AT\^SYSINFOEX^m"
    waitfor 5 "\^SYSINFOEX:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 goto end_sysinfoex
    if % = 2 gosub cme_error goto end_sysinfoex
    if % = 3 goto end_sysinfoex
    get 1 "," $i1
    if % != 0 goto comm_timeout
    get 1 "," $i2
    if % != 0 goto comm_timeout
    get 1 "," $i3
    if % != 0 goto comm_timeout
    get 1 "," $i4
    if % != 0 goto comm_timeout
    get 1 "," $i5
    if % != 0 goto comm_timeout
    get 1 "," $i6
    if % != 0 goto comm_timeout
    get 1 "," $i7
    if % != 0 goto comm_timeout
    get 1 "," $i8
    if % != 0 goto comm_timeout
    get 1 "^mOK^m" $i9
    if % != 0 goto comm_timeout
    let $d="Unknown modem response ("+$i1+")"
    if $i1 = "0" let $d="No service"
    if $i1 = "1" let $d="Restricted service"
    if $i1 = "2" let $d="Valid service"
    if $i1 = "3" let $d="Restricted regional service"
    if $i1 = "4" let $d="Power-saving and deep sleep state"
    print $x+"- service state: "+$d+"\n"
    let $d="Unknown modem response ("+$i2+")"
    if $i2 = "0" let $d="No service"
    if $i2 = "1" let $d="Only CS service"
    if $i2 = "2" let $d="Only PS service"
    if $i2 = "3" let $d="PS+CS service"
    if $i2 = "4" let $d="CS and PS not registered, searching"
    print $x+"- domain: "+$d+"\n"    
    let $d="Unknown modem response ("+$i3+")"
    if $i3 = "0" let $d="Non roaming state"
    if $i3 = "1" let $d="Roaming state"
    print $x+"- roaming: "+$d+"\n"
    let $d="Unknown modem response ("+$i4+")"
    if $i4 = "0" let $d="Invalid USIM card state or pin code locked"
    if $i4 = "1" let $d="Valid USIM card state"
    if $i4 = "2" let $d="USIM is invalid in case of CS"
    if $i4 = "3" let $d="USIM is invalid in case of PS"
    if $i4 = "4" let $d="USIM is invalid in case of either CS or PS"
    if $i4 = "240" let $d="ROMSIM"
    if $i4 = "255" let $d="USIM card is not existent"
    print $x+"- SIM: "+$d+"\n"
    let $d="Unknown modem response ("+$i6+")"
    if $i7 != "" let d$=$i7 let $i6=""
    if $i6 = "0" let $d="No service"
    if $i6 = "1" let $d="GSM"
    if $i6 = "2" let $d="CDMA"
    if $i6 = "3" let $d="WCDMA"
    if $i6 = "4" let $d="TD-SCDMA"
    if $i6 = "5" let $d="WIMAX"
    if $i6 = "6" let $d="LTE"
    print $x+"- mode: "+$d+"\n"
    let $d="Unknown modem response ("+$i8+")"
    if $i9 != "" let d$=$i9 let $i8=""
    if $i8 = "0" let $d="No service"
    if $i8 = "1" let $d="GSM"
    if $i8 = "2" let $d="GPRS"
    if $i8 = "3" let $d="EDGE"
    if $i8 = "21" let $d="IS95A"
    if $i8 = "22" let $d="IS95B"
    if $i8 = "23" let $d="CDMA2000 1X"
    if $i8 = "24" let $d="EVDO Rel0"
    if $i8 = "25" let $d="EVDO RelA"
    if $i8 = "26" let $d="EVDO RelB"
    if $i8 = "27" let $d="HYBRID (CDMA2000 1X)"
    if $i8 = "28" let $d="HYBRID (EVDO Rel0)"
    if $i8 = "29" let $d="HYBRID (EVDO RelA)"
    if $i8 = "30" let $d="HYBRID (EVDO RelB)"
    if $i8 = "41" let $d="WCDMA"
    if $i8 = "42" let $d="HSDPA"
    if $i8 = "43" let $d="HSUPA"
    if $i8 = "44" let $d="HSPA"
    if $i8 = "45" let $d="HSPA+"
    if $i8 = "46" let $d="DC-HSPA+"
    if $i8 = "61" let $d="TD-SCDMA"
    if $i8 = "62" let $d="HSDPA"
    if $i8 = "63" let $d="HSUPA"
    if $i8 = "64" let $d="HSPA"
    if $i8 = "65" let $d="HSPA+"
    if $i8 = "81" let $d="802.16e"
    if $i8 = "101" let $d="LTE"
    print $x+"- sub mode: "+$d+"\n"
    # Invalid state do finish
    if $i2 = "1" goto abort
    if $i4 = "0" goto abort
    if $i4 = "3" goto finish
    if $i4 = "4" goto finish
    if $i4 = "255" goto finish
    # Invalid state do restart_modem
    if $i1 = "0" goto restart_modem
    if $i1 = "4" goto restart_modem
    if $i2 = "0" goto restart_modem
    if $i2 = "4" goto restart_modem
    if $i6 = "0" goto restart_modem
    goto end_sysinfo
:end_sysinfoex

:do_sysinfo
    send "AT\^SYSINFO^m"
    waitfor 5 "\^SYSINFO:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while getting system information\n" goto end_sysinfo
    if % = 2 gosub cme_error print $x+"Error "+$e+" while getting system information\n" goto end_sysinfo
    if % = 3 print $x+"Command not supported\n" goto end_sysinfo
    get 1 "," $i1
    if % != 0 goto comm_timeout
    get 1 "," $i2
    if % != 0 goto comm_timeout
    get 1 "," $i3
    if % != 0 goto comm_timeout
    get 1 "," $i4
    if % != 0 goto comm_timeout
    get 1 "^mOK^m" $i5
    if % != 0 goto comm_timeout
    if len($i5)>3 let $i6=$right($i5,1)
    let $i5=$left($i5,1)
    let $d="Unknown modem response ("+$i1+")"
    if $i1 = "0" let $d="No service"
    if $i1 = "1" let $d="Restricted service"
    if $i1 = "2" let $d="Valid service"
    if $i1 = "3" let $d="Restricted regional service"
    if $i1 = "4" let $d="Power-saving and deep sleep state"
    print $x+"- service state: "+$d+"\n"
    let $d="Unknown modem response ("+$i2+")"
    if $i2 = "0" let $d="No service"
    if $i2 = "1" let $d="Only CS service"
    if $i2 = "2" let $d="Only PS service"
    if $i2 = "3" let $d="PS+CS service"
    if $i2 = "4" let $d="CS and PS not registered, searching"
    print $x+"- domain: "+$d+"\n"    
    let $d="Unknown modem response ("+$i3+")"
    if $i3 = "0" let $d="Non roaming state"
    if $i3 = "1" let $d="Roaming state"
    print $x+"- roaming: "+$d+"\n"
    let $d="Unknown modem response ("+$i4+")"
    if $i4 = "0" let $d="No service"
    if $i4 = "1" let $d="AMPS"
    if $i4 = "2" let $d="CDMA"
    if $i4 = "3" let $d="GSM/GPRS"
    if $i4 = "4" let $d="HDR"
    if $i4 = "5" let $d="WCDMA"
    if $i4 = "6" let $d="GPS"
    if $i4 = "7" let $d="GSM/WCDMA"
    if $i4 = "8" let $d="CDMA/HDR HYBRID"
    if $i4 = "15" let $d="TD-SCDMA"
    print $x+"- mode: "+$d+"\n"
    let $d="Unknown modem response ("+$i5+")"
    if $i5 = "0" let $d="Invalid USIM card state or pin code locked"
    if $i5 = "1" let $d="Valid USIM card state"
    if $i5 = "2" let $d="USIM is invalid in case of CS"
    if $i5 = "3" let $d="USIM is invalid in case of PS"
    if $i5 = "4" let $d="USIM is invalid in case of either CS or PS"
    if $i5 = "255" let $d="USIM card is not existent"
    print $x+"- SIM: "+$d+"\n"
    let $d="Unknown modem response ("+$i6+")"
    if $i6 = "0" let $d="No service"
    if $i6 = "1" let $d="GSM"
    if $i6 = "2" let $d="GPRS"
    if $i6 = "3" let $d="EDGE"
    if $i6 = "4" let $d="WCDMA"
    if $i6 = "5" let $d="HSDPA"
    if $i6 = "6" let $d="HSUPA"
    if $i6 = "7" let $d="HSDPA and HSUPA"
    if $i6 = "8" let $d="TD_SCDMA"
    if $i6 = "9" let $d="HSPA+"
    if $i6 = "17" let $d="HSPA+(64QAM)"
    if $i6 = "18" let $d="HSPA+(MIMO)"
    print $x+"- sub mode: "+$d+"\n"
    # Invalid state do finish
    if $i2 = "1" goto abort
    if $i5 = "0" goto abort
    if $i5 = "3" goto finish
    if $i5 = "4" goto finish
    if $i5 = "255" goto finish
    # Invalid state do restart_modem
    if $i1 = "0" goto restart_modem
    if $i1 = "4" goto restart_modem
    if $i2 = "0" goto restart_modem
    if $i2 = "4" goto restart_modem
    if $i4 = "0" goto restart_modem
:end_sysinfo

# Getting network registration status
    print $x+"Getting network registration status\n"
    let $i2=""
    send "AT+CGREG=2; +CGREG?^m"
    waitfor 2 "+CGREG: ","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while getting network registration status\n" goto end_cgreg
    if % = 2 gosub cme_error print $x+"Error "+$e+" while getting network registration status\n" goto end_cgreg
    if % = 3 print $x+"Command not supported\n" goto end_cgreg
    get 1 "," $i1
    if % != 0 goto comm_timeout
    get 1 "^m^mOK^m" $i4
    if % != 0 goto comm_timeout
    let $i2=$left($i4,1)
    if len($i4)>2 let $i3=$mid($i4,2,len($i4)-2)
    let $d="Unknown modem response ("+$i2+")"
    if $i2 = "0" let $d="Not registered. The MS is not searching the new operators to be registered"
    if $i2 = "1" let $d="Local network is registered"
    if $i2 = "2" let $d="Not registered. But the MS is searching the new operators to be registered"
    if $i2 = "3" let $d="Registration rejected"
    if $i2 = "4" let $d="Unknown reasons"
    if $i2 = "5" let $d="Roaming network is registered"
    print $x+"- status: "+$d+"\n"
    print $x+"- lac, ci: "+$i3+"\n"
    send "AT+CGREG=0^m"
    waitfor 1 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 2 waitquiet 1 0.5
:end_cgreg

# Disable CME error report
    send "AT+CMEE=0^m"
    waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout

# Verify if the modem is connected to APN
    print $x+"Verify if the modem is connected to APN\n"
    send "AT\^DHCP?^m"
    waitfor 5 "\^DHCP:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 0 print $x+"Modem is already connected\n" goto do_disconnect
    if % = 3 print $x+"Command not supported\n" goto abort
    print $x+"No connection detected\n"

# Disconnecting from current APN
goto end_disconnect
:do_disconnect
    print $x+"Disconnecting from current APN\n"
    send "AT\^NDISDUP=1,0^m"
    waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while disconnecting from current APN\n" goto abort
    if % = 2 gosub cme_error print $x+"Error "+$e+" while disconnecting from current APN\n" goto abort
    if % = 3 print $x+"Command not supported\n" goto abort
    print $x+"Disconnected successfully\n"
    waitquiet 1 0.5
:end_disconnect    

# Setting mode
    if $m = "" goto end_mode_set
    print $x+"Setting mode "+$m+"\n"
    send $m+"^m"
    waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while setting mode error\n" goto abort
    if % = 2 gosub cme_error print $x+"Error "+$e+" while setting mode error\n" goto abort
    if % = 3 print $x+"Command not supported\n" goto abort
    print $x+"Mode set successfully\n"
:end_mode_set

# Establishing connection
    print $x+"Try to establish connection via APN "+$a+"\n"
    send "AT\^NDISDUP=1,1,\""+$a+"\"^m" 
    waitfor 5 "OK","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 1 print $x+"Error while connecting\n" goto abort
    if % = 2 gosub cme_error print $x+"Error "+$e+" while connecting\n" goto abort
    if % = 3 print $x+"Command not supported\n" goto abort
    print $x+"Waiting for establish connection\n"
    let r3=0
:wait_for_connection    
    let r3=r3+1
    if r3>30 goto restart_modem
    send "AT\^DHCP?^m"
    waitfor 5 "\^DHCP:","ERROR","+CME ERROR: ","COMMAND NOT SUPPORT"
    if % = -1 goto comm_timeout
    if % = 0 print $x+"Connection established\n" goto finish
    if % = 1 waitquiet 1 1 goto wait_for_connection
    if % = 2 waitquiet 1 1 goto wait_for_connection
    if % = 3 print $x+"Command not supported\n" goto abort

# In case of normal exit
:finish
    print $x+"Done.\n"
    exit 0

# In case of occurred an error
:abort
    print $x+"Done!\n"
    exit 1

# Error CME routine
:cme_error
    get 1 "^m" $e
    let $e="'"+$e+"'"
    return

# Restarting modem and start all
:restart_modem
    let r1=r1+1
    if r1>5 print $x+"Number of restart retries was exhausted\n" goto abort
    print $x+"Restarting modem\n"
    waitquiet 2 2
    send "AT\^NDISDUP=1,0^m"
    waitquiet 2 1
    send "ATZ0^m"
    waitquiet 2 1
    send "AT&F^m"
    waitquiet 2 1
    send "AT+CFUN=1^m"
    waitquiet 2 1
    goto start

# Timeout detected
:comm_timeout
    print $x+"Modem is not responding, timeout detected\n"
    goto restart_modem
# Done

Dziękuję za spostrzeżenia, z chęcią dokonam takich zmian w skryptach. Miło, że są osoby, które z tego skorzystały smile