I've a sip phone that when called, if not answered and you hangup on the caller side, sends out "487 Request Terminated" . But seems that * don't get that message (I think * ignore it) so the phone don't get an OK and keep ringing until timeout, even if the caller has hanged up. Could that be added to *? Attached some debug. Matteo Brancaleoni mbrancaleoni@espia.it Emmegi System Administrator EspiA - EMMEGI Srl - e*solution provider Uffici: Via Pascoli, 37 20129 Milano - Italy Sede Legale: Corso Sempione 67 20149 Milano - Italy Tel. +39 0270633354 Fax. +39 0245487890 http://www.espia.it -------------- next part -------------- Sip read: CANCEL sip:52@192.168.1.53 SIP/2.0 Via: SIP/2.0/UDP 192.168.1.20:5060;branch=z9hG4bK-7004jlcuqj2d Max-Forwards: 70 To: <sip:52@192.168.1.53;user=phone> From: "snom100" <sip:snom100@192.168.1.53>;tag=tb43w10q72 Call-ID: 000000ff716a-ysfhvpady07b@192.168.1.20 CSeq: 2 CANCEL Contact: <sip:snom100@192.168.1.20:5060;line=1> Proxy-Authorization: Digest username="snom100",realm="asterisk",nonce="4007d2b5",uri="sip:",response="1a6f3d00825f5871b066576619a03ea5",algorithm=md5 Content-Length: 0 astro*CLI> 10 headers, 0 lines Transmitting (no NAT): SIP/2.0 200 OK Via: SIP/2.0/UDP 192.168.1.20:5060;branch=z9hG4bK-7004jlcuqj2d From: "snom100" <sip:snom100@192.168.1.53>;tag=tb43w10q72 To: <sip:52@192.168.1.53;user=phone>;tag=3f9b68df Call-ID: 000000ff716a-ysfhvpady07b@192.168.1.20 CSeq: 2 CANCEL User-Agent: Asterisk PBX Contact: <sip:52@192.168.1.53> Content-Length: 0 to 192.168.1.20:5060 XXX Need to handle Retransmitting XXX: CANCEL sip:sip52@192.168.1.22 SIP/2.0 Via: SIP/2.0/UDP 192.168.1.53:5060;branch=2f2cdb18 From: "Snom100" <sip:8001@192.168.1.53>;tag=0e0f8a69 To: <sip:sip52@192.168.1.22>;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 CANCEL User-Agent: Asterisk PBX Content-Length: 0 (no NAT) to 192.168.1.22:5060 == Spawn extension (local, 52, 1) exited non-zero on 'SIP/snom100-1d79' Sip read: SIP/2.0 200 OK From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 CANCEL Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Sip read: SIP/2.0 487 Request Terminated From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 INVITE Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Interface is eth0 IP Address is 192.168.1.53 Sip read: SIP/2.0 487 Request Terminated From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 INVITE Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Interface is eth0 IP Address is 192.168.1.53 Sip read: SIP/2.0 487 Request Terminated From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 INVITE Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Interface is eth0 IP Address is 192.168.1.53 Sip read: SIP/2.0 487 Request Terminated From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 INVITE Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Interface is eth0 IP Address is 192.168.1.53 Sip read: SIP/2.0 487 Request Terminated From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 INVITE Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Interface is eth0 IP Address is 192.168.1.53 Sip read: SIP/2.0 487 Request Terminated From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 INVITE Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Interface is eth0 IP Address is 192.168.1.53 Sip read: SIP/2.0 487 Request Terminated From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 INVITE Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Interface is eth0 IP Address is 192.168.1.53 Sip read: SIP/2.0 487 Request Terminated From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 INVITE Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Interface is eth0 IP Address is 192.168.1.53 Sip read: SIP/2.0 487 Request Terminated From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 INVITE Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Interface is eth0 IP Address is 192.168.1.53 Sip read: SIP/2.0 487 Request Terminated From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 INVITE Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Interface is eth0 IP Address is 192.168.1.53 Sip read: SIP/2.0 487 Request Terminated From: "Snom100"<sip:8001@192.168.1.53> ;tag=0e0f8a69 To: <sip:sip52@192.168.1.22> ;tag=c0a80116-13c4-3e75f06c-2e581-20a0 Call-ID: 079fc5a2329463973db606e02cea59c0@192.168.1.53 CSeq: 102 INVITE Via: SIP/2.0/UDP 192.168.1.53:5060 ;branch=2f2cdb18 User-Agent: FXS_GW (2sipfxs.102) Content-Length:0 8 headers, 0 lines Interface is eth0 IP Address is 192.168.1.53 astro*CLI> quit
Brancaleoni Matteo
2003-Mar-18 07:33 UTC
[Asterisk-Users] FIXED - 487 Request Terminated ?
Ok guys, that's it a patch for chan_sip.c The problem is: some devices transmit late packets, even when asterisk has already destroyed the channels. For example 487 is sent by various ipphones , like kphone, snom & some fxs-sip gw) when a request is cancelled by the caller (for eg. when the caller Cancel an Invite Request). But since 487 is sent *after* cancel , the sip channel are already destroyed to asterisk can't ack them. That's wrong, since some phone just ignore the lacking of ack, other keep ringing if not ack'ed . So my patch just adds a timer to do_monitor, in order to wait 10 seconds before destroying the sip channel. Probably that will fix also some reported problems on cisco phones that go on ringing even if the caller hangs up. Lemme know. P.S. I'm not a C-guru . The patch works well , but if someone wants to improve it, feel free to blame me. Matteo Il lun, 2003-03-17 alle 18:06, Matteo Brancaleoni ha scritto:> I've a sip phone that when called, > if not answered and you hangup > on the caller side, sends out > "487 Request Terminated" . > But seems that * don't get that > message (I think * ignore it) > so the phone don't get an OK > and keep ringing until timeout, > even if the caller has hanged > up. > > Could that be added to *? > Attached some debug. > > Matteo Brancaleoni > mbrancaleoni@espia.it > Emmegi System Administrator > > EspiA - EMMEGI Srl - e*solution provider > Uffici: Via Pascoli, 37 > 20129 Milano - Italy > Sede Legale: Corso Sempione 67 > 20149 Milano - Italy > Tel. +39 0270633354 > Fax. +39 0245487890 > http://www.espia.it-------------- next part -------------- --- ./asterisk/channels/chan_sip.c 2003-03-18 01:35:29.000000000 +0100 +++ ./myasterisk/channels/chan_sip.c 2003-03-18 15:04:04.000000000 +0100 @@ -183,6 +183,7 @@ int initid; /* Auto-congest ID if appropriate */ int dtmfmode; + int needhanguptimer; /* hangup timer started or not*/ struct ast_dsp *vad; struct sip_peer *peerpoke; /* If this calls is to poke a peer, which one */ @@ -3260,6 +3261,7 @@ break; } transmit_request(p, "ACK", 0); + ast_log(LOG_DEBUG, "ooh, SIP DESTROY 4xx user=%s\n",p->username); __sip_destroy(p, 0); p = NULL; } else @@ -3711,6 +3713,7 @@ struct sip_pvt *sip; struct sip_peer *peer; time_t t; + time_t hanguptimer,temptime; /* Add an I/O event to our UDP socket */ if (sipsock > -1) ast_io_add(io, sipsock, sipsock_read, AST_IO_IN, NULL); @@ -3724,7 +3727,30 @@ restartsearch: sip = iflist; while(sip) { - if (sip->needdestroy) { + /* Ok, start wait before destroying a channel */ + /* in order to get late responses and ack them */ + if ((sip->needdestroy) && !(sip->needhanguptimer)) + { + ast_log(LOG_DEBUG, "Starting timer check\n"); + sip->needhanguptimer = 1; + time(&hanguptimer); + goto restartsearch; + } + /* Ok, already started the timer, check it */ + else if ((sip->needdestroy) && (sip->needhanguptimer)) + { + time(&temptime); + /* 10 secs for late packets */ + if((temptime - hanguptimer) > 10) + { + ast_log(LOG_DEBUG, "Time Expired!\n"); + sip->needhanguptimer = 2; + } + } + /* If we are here, the timer is started */ + /* check if it's set as expired , then destroy */ + if ((sip->needdestroy) && (sip->needhanguptimer == 2)) { + ast_log(LOG_DEBUG, "Gotta a SIP Destroy! Username=%s callid=%s \n",sip->username,sip->callid); __sip_destroy(sip, 1); goto restartsearch; }
Brancaleoni Matteo
2003-Mar-18 07:52 UTC
[Asterisk-Users] FIXED2 - 487 Request Terminated ?
Oops, the previous patch had a little bug... now it's fixed. please use this one. Matteo Il lun, 2003-03-17 alle 18:06, Matteo Brancaleoni ha scritto:> I've a sip phone that when called, > if not answered and you hangup > on the caller side, sends out > "487 Request Terminated" . > But seems that * don't get that > message (I think * ignore it) > so the phone don't get an OK > and keep ringing until timeout, > even if the caller has hanged > up. > > Could that be added to *? > Attached some debug. > > Matteo Brancaleoni > mbrancaleoni@espia.it > Emmegi System Administrator > > EspiA - EMMEGI Srl - e*solution provider > Uffici: Via Pascoli, 37 > 20129 Milano - Italy > Sede Legale: Corso Sempione 67 > 20149 Milano - Italy > Tel. +39 0270633354 > Fax. +39 0245487890 > http://www.espia.it-------------- next part -------------- --- ./asterisk/channels/chan_sip.c 2003-03-18 01:35:29.000000000 +0100 +++ ./myasterisk/channels/chan_sip.c 2003-03-18 15:47:43.000000000 +0100 @@ -183,6 +183,8 @@ int initid; /* Auto-congest ID if appropriate */ int dtmfmode; + time_t hanguptimer; /* hangup timer */ + int needhanguptimer; /* hangup timer started or not*/ struct ast_dsp *vad; struct sip_peer *peerpoke; /* If this calls is to poke a peer, which one */ @@ -3260,6 +3262,7 @@ break; } transmit_request(p, "ACK", 0); + ast_log(LOG_DEBUG, "ooh, SIP DESTROY 4xx user=%s\n",p->username); __sip_destroy(p, 0); p = NULL; } else @@ -3711,6 +3714,7 @@ struct sip_pvt *sip; struct sip_peer *peer; time_t t; + time_t hanguptimer,temptime; /* Add an I/O event to our UDP socket */ if (sipsock > -1) ast_io_add(io, sipsock, sipsock_read, AST_IO_IN, NULL); @@ -3724,7 +3728,31 @@ restartsearch: sip = iflist; while(sip) { - if (sip->needdestroy) { + /* Ok, start wait before destroying a channel */ + /* in order to get late responses and ack them */ + if ((sip->needdestroy) && !(sip->needhanguptimer)) + { + ast_log(LOG_DEBUG, "Starting timer check\n"); + sip->needhanguptimer = 1; + time(&hanguptimer); + sip->hanguptimer = hanguptimer; + goto restartsearch; + } + /* Ok, already started the timer, check it */ + else if ((sip->needdestroy) && (sip->needhanguptimer)) + { + time(&temptime); + /* 10 secs for late packets */ + if((temptime - sip->hanguptimer) > 10) + { + ast_log(LOG_DEBUG, "Time Expired!\n"); + sip->needhanguptimer = 2; + } + } + /* If we are here, the timer is started */ + /* check if it's set as expired , then destroy */ + if ((sip->needdestroy) && (sip->needhanguptimer == 2)) { + ast_log(LOG_DEBUG, "Gotta a SIP Destroy! Username=%s callid=%s \n",sip->username,sip->callid); __sip_destroy(sip, 1); goto restartsearch; }