Hi all.

I have a problem for the following scenario.
When I make a call for PSTN and on hook by PSTN side,
Cisco As can't send BYE for SER.

  01. [UA via Asterisk] dialing "08022223333" -> [SER]
  02. [SER] prefix("0333") and rewritehostport("my.cisco.ip.address:5060") -> [Cisco]
  03. [Cisco] dial-peer voice 6000 pots, translate-outgoing called from "033308022223333" to "008022223333"
  04. [Cisco] process an outbound call to "008022223333" -> [e.g. Mobile]
  05. [e.g. Mobile] Catch call
  06. [SER] log CDR start
  07. [Cisco] talking
  08. [e.g. Mobile] On hook and call disconnect
  09. [Cisco] can't send BYE for SER *****why??*****
  10. [UA via Asterisk] On hook
  11. [UA via Asterisk] Send BYE for SER
  12. [SER] log CDR End [Cisco] Call finished

But another scenario, if make a call from PSTN to Asterisk and
on hook by PSTN side, Cisco As send BYE to SER.

  01. [e.g. Mobile] dialing "0377771111(Asterisk user number)"
  02. [Cisco] receive "77771111" call number
  03. [Cisco] dial-peer voice 5000 voip, session target ipv4:my.ser.ip.address -> [SER]
  04. [SER] process an incoming call to "0377771111" -> [UA via Asterisk]
  05. [UA via Asterisk] Catch call
  06. [SER] log CDR start
  07. [UA via Asterisk] talking
  08. [e.g. Mobile] On hook and call disconnect
  09. [Cisco] Send BYE to SER
  10. [SER] log CDR End [Cisco] Call finished
  11. [UA via Asterisk] receive BYE from SER

And sorry for my diffucult example.

Why Cisco AS 5300 can't send BYE to SER
When PSTN call is disconnected by PSTN side?

My ser.cfg as follows:

# --------------------------------------------------------------------------
# global configuration parameters
# --------------------------------------------------------------------------
fork=no
log_stderror=yes
check_via=no
dns=no
rev_dns=no
listen=my.ser.ip.address
port=5060
fifo="/tmp/ser_fifo"
fifo_db_url="mysql://ser:heslo@localhost/ser"

# --------------------------------------------------------------------------
# module loading
# --------------------------------------------------------------------------
loadmodule "/usr/local/lib/ser/modules/mysql.so"
loadmodule "/usr/local/lib/ser/modules/sl.so"
loadmodule "/usr/local/lib/ser/modules/tm.so"
loadmodule "/usr/local/lib/ser/modules/rr.so"
loadmodule "/usr/local/lib/ser/modules/maxfwd.so"
loadmodule "/usr/local/lib/ser/modules/usrloc.so"
loadmodule "/usr/local/lib/ser/modules/registrar.so"
loadmodule "/usr/local/lib/ser/modules/textops.so"
loadmodule "/usr/local/lib/ser/modules/auth.so"
loadmodule "/usr/local/lib/ser/modules/auth_db.so"
loadmodule "/usr/local/lib/ser/modules/avpops.so"
loadmodule "/usr/local/lib/ser/modules/permissions.so"
loadmodule "/usr/local/lib/ser/modules/acc.so"
loadmodule "/usr/local/lib/ser/modules/exec.so"

# --------------------------------------------------------------------------
# setting module-specific parameters
# --------------------------------------------------------------------------
modparam("usrloc", "db_mode", 2)
modparam("auth_db", "calculate_ha1", yes)
modparam("auth_db", "password_column", "password")
modparam("rr", "enable_full_lr", 1)
modparam("usrloc", "db_url", " mysql://ser:heslo@localhost/ser")
modparam("auth_db", "db_url", "mysql://ser:heslo@localhost/ser")
modparam("permissions", "db_url", " mysql://ser:heslo@localhost /ser")
modparam("tm", "fr_inv_timer", 27)
modparam("tm", "fr_inv_timer_avp", "inv_timeout")
modparam("permissions", "db_mode", 1)
modparam("permissions", "trusted_table", "trusted")
modparam("acc", "db_url", "mysql://ser:heslo@localhost/ser")
modparam("acc", "db_flag", 2)
modparam("acc", "db_missed_flag", 3)

# --------------------------------------------------------------------------
# route pattern
# --------------------------------------------------------------------------
route {
 
  if (!mf_process_maxfwd_header("10")) {
    sl_send_reply("483","Too Many Hops");
    break;
  };

  if ( msg:len > max_len ) {
    sl_send_reply("513", "Message too big");
    break;
  };
 
  record_route();
        
  if (loose_route()) {
    if (method=="ACK") {
      acc_db_request("01:CallStart\n", "acc");
    };
    if (method=="BYE" || method=="CANCEL") {
      acc_db_request("02:CallEnd\n", "acc");
    };
    t_relay();
    break;
  };

  if (uri==myself) {
    if (method=="REGISTER") {
      if (!www_authorize("", "subscriber")) {
        www_challenge("", "0");
        break;
      };
      save("location");
      break;
    };

    if (search("^(f|From): .*@(my\.cisco\.ip\.address)")) {
      #PSTN Incoming call from Cisco AS 5300 e.g. 0377771111
      rewritehost("my.asterisk.ip.address ");
    };

    lookup("aliases");

    if (!lookup("location")) {
      if (method=="INVITE" && !search("^(f|From): .*@(my\.cisco\.ip\.address)")) {
        if (!proxy_authorize("", "subscriber")) {
          proxy_challenge("", "0");
          break;
        };
        if (uri=~"^sip:0[0-9]{10}@") {
          # PSTN Outgoing call to Cisco AS 5300 e.g. 08022223333
          prefix("0333");
          rewritehostport("my.cisco.ip.address:5060");
          avp_write("i:45", "inv_timeout");
        } else {
          sl_send_reply("404", "Not Found");
          break;
        };
        consume_credentials();
      };
    };
   
  };

  if (!t_relay()) {
    sl_reply_error();
  };
 
}

And my Cisco AS 5300 config as follows:

voice call send-alert
voice rtp send-recv

voice service pots
 fax protocol t38 ls-redundancy 0 hs-redundancy 0 fallback cisco

voice service voip
 fax protocol t38 ls-redundancy 0 hs-redundancy 0 fallback cisco
 sip
  min-se  60

translation-rule 50
 Rule 0 0333 0
 Rule 1 ^7777 037777

voice class codec 2
 codec preference 1 g711ulaw
 codec preference 2 g711alaw

dial-peer voice 5000 voip
 tone ringback alert-no-PI
 description ser-asterisk-cisco-test
 huntstop
 destination-pattern 77771111$
 translate-outgoing called 50
 voice-class codec 2
 session protocol sipv2
 session target ipv4:my.ser.ip.address
 dtmf-relay rtp-nte
 max-conn 1

dial-peer voice 6000 pots
 application session
 max-conn 2
 destination-pattern 0333T
 progress_ind alert enable 8
 translate-outgoing called 50
 port 0:D

Thanks,
Sahria