|
|
|
@ -10,6 +10,7 @@ import (
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"gitlab.com/ics_cinnamon/voicegateway/icscbtimer"
|
|
|
|
|
"gitlab.com/ics_cinnamon/voicegateway/icsconf"
|
|
|
|
|
"gitlab.com/ics_cinnamon/voicegateway/icsdtmf"
|
|
|
|
@ -273,17 +274,23 @@ func (s *IcsSession) RequestInvite(inviteto string) {
|
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
|
format := conf.AgentConfig[s.ID].MediaConfig.Format
|
|
|
|
|
|
|
|
|
|
//sim
|
|
|
|
|
inviteMethod := fmt.Sprintf("sip:%s@192.168.0.83;transport=%s", s.AgentName, transport)
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", s.AgentName, ip)
|
|
|
|
|
to := fmt.Sprintf("<sip:%s@192.168.0.83;user=phone>", s.AgentName)
|
|
|
|
|
if conf.Representative.Value {
|
|
|
|
|
inviteMethod = fmt.Sprintf("sip:%s@192.168.0.83;transport=%s", "AISB", transport)
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", "AISB", ip)
|
|
|
|
|
to = fmt.Sprintf("<sip:%s@192.168.0.83;user=phone>", "AISB")
|
|
|
|
|
}
|
|
|
|
|
reqInvite := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_INVITE, inviteMethod)
|
|
|
|
|
|
|
|
|
|
via := fmt.Sprintf("SIP/2.0/UDP 192.168.0.83:5090;branch=%s", sipasm.GenerateBranch())
|
|
|
|
|
maxforwards := "70"
|
|
|
|
|
from := fmt.Sprintf("<sip:%s@%s>;tag=%s", inviteto, ip, sipasm.GenerateTag())
|
|
|
|
|
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", s.AgentName, ip)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
|
|
|
|
|
|
|
|
|
|
to := fmt.Sprintf("<sip:%s@192.168.0.83;user=phone>", s.AgentName)
|
|
|
|
|
postfix := "192.168.0.83"
|
|
|
|
|
var callid string
|
|
|
|
|
if len(s.callID) != 0 {
|
|
|
|
@ -331,7 +338,12 @@ func (s *IcsSession) RequestInvite(inviteto string) {
|
|
|
|
|
|
|
|
|
|
s.callID = callid
|
|
|
|
|
|
|
|
|
|
s.SetAgentStatus(STATUS_AGENT_CALLING)
|
|
|
|
|
if conf.Representative.Value {
|
|
|
|
|
s.SetAgentStatus(STATUS_AGENT_READY)
|
|
|
|
|
} else {
|
|
|
|
|
s.SetAgentStatus(STATUS_AGENT_CALLING)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
|
wlen,
|
|
|
|
@ -342,6 +354,93 @@ func (s *IcsSession) RequestInvite(inviteto string) {
|
|
|
|
|
inviteFunc()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pass invite for sim
|
|
|
|
|
func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
l := icslog.GetIcsLog()
|
|
|
|
|
conf := icsconf.GetIcsConfig()
|
|
|
|
|
|
|
|
|
|
// TODO - send bye
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_WARN, s.ID, "%s \n%s",
|
|
|
|
|
icserror.ICSERRNETNotConnectError.GetMessage(), debug.Stack())
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
ip := conf.InfoConfig.ServerIP
|
|
|
|
|
port := conf.SIPConfig.Port
|
|
|
|
|
|
|
|
|
|
fmt.Println("sip.Media ", sip.Media)
|
|
|
|
|
mediaPort, _ := strconv.Atoi(sip.Media)
|
|
|
|
|
|
|
|
|
|
proxy := conf.SIPConfig.SIPProxy
|
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
|
format := conf.AgentConfig[s.ID].MediaConfig.Format
|
|
|
|
|
|
|
|
|
|
inviteMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "AISB", proxy, transport)
|
|
|
|
|
reqInvite := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_INVITE, inviteMethod)
|
|
|
|
|
|
|
|
|
|
via := fmt.Sprintf("SIP/2.0/UDP %s;rport;branch=%s", ip, sipasm.GenerateBranch())
|
|
|
|
|
maxforwards := "70"
|
|
|
|
|
from := fmt.Sprintf("<sip:%s@%s:5090>;tag=%s", s.AgentName, ip, sipasm.GenerateTag())
|
|
|
|
|
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", s.AgentName, ip)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
|
|
|
|
|
|
|
|
|
|
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "01025670081", ip)
|
|
|
|
|
//to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip)
|
|
|
|
|
// postfix := fmt.Sprintf("@%s", ip)
|
|
|
|
|
var callid string
|
|
|
|
|
callid = uuid.New().String()
|
|
|
|
|
// if len(s.callID) != 0 {
|
|
|
|
|
// callid = s.callID
|
|
|
|
|
// //if len(s.regiCallID) != 0 {
|
|
|
|
|
// //callid = s.regiCallID
|
|
|
|
|
// } else {
|
|
|
|
|
// callid = sipasm.GenerateCallID(postfix)
|
|
|
|
|
// }
|
|
|
|
|
cseq := fmt.Sprintf("%d INVITE", s.Cseq)
|
|
|
|
|
s.Cseq++
|
|
|
|
|
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", s.AgentName, ip, port, transport)
|
|
|
|
|
//expires := fmt.Sprintf("%d", conf.AgentConfig[s.ID].RegisterConfig.RegisterExpire)
|
|
|
|
|
userAgent := conf.InfoConfig.Product
|
|
|
|
|
allow := "REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE"
|
|
|
|
|
supported := "timer,path,replaces"
|
|
|
|
|
|
|
|
|
|
formats := strings.Split(format, " ")
|
|
|
|
|
reqInvite.SDP = sipasm.NewSDPMessage(ip, mediaPort, formats[:], 0)
|
|
|
|
|
sdpLength := fmt.Sprintf("%d", len(reqInvite.SDP.String()))
|
|
|
|
|
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_VIA, via)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_MAX_FORWARDS, maxforwards)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_FROM, from)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_TO, to)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, callid)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, cseq)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
|
//reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_EXPIRES, expires)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_SUPPORTED, supported)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_TYPE, "application/sdp")
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, sdpLength)
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
|
|
|
|
|
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "sip 내용 전달! %+v", sip)
|
|
|
|
|
// sendINVITE := fmt.Sprintf("%+v",sip)
|
|
|
|
|
wlen, werr := (*s.sipNeter).WriteSIP([]byte(reqInvite.String()))
|
|
|
|
|
if werr != nil {
|
|
|
|
|
l.Print(icslog.LOG_LEVEL_FATAL, s.ID, werr.GetMessage())
|
|
|
|
|
s.SetAgentStatus(STATUS_AGENT_READY)
|
|
|
|
|
return werr
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(wlen)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s.RemoveSession()
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//response invite
|
|
|
|
|
func (s *IcsSession) ProcInvite(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
l := icslog.GetIcsLog()
|
|
|
|
@ -413,6 +512,7 @@ func (s *IcsSession) ProcInvite(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
remoteAddr := icsnet.NewNetAddrWithIPAddr(remoteAddrs)
|
|
|
|
|
//connect to remote RTP
|
|
|
|
|
s.rtpMediaNeter.SetRemoteAddr(&remoteAddr)
|
|
|
|
|
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set media remote address - %s(%s)", remoteAddr, s.rtpMediaNeter.RemoteAddr())
|
|
|
|
|
/*
|
|
|
|
|
cerr := s.rtpMediaNeter.Connect(nil, &remoteAddr)
|
|
|
|
@ -708,6 +808,7 @@ func (s *IcsSession) ProcInvite(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
l := icslog.GetIcsLog()
|
|
|
|
|
conf := icsconf.GetIcsConfig()
|
|
|
|
|
s.InviteSIP = sip
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
@ -748,7 +849,11 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError
|
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
|
format := conf.AgentConfig[s.ID].MediaConfig.Format
|
|
|
|
|
|
|
|
|
|
if conf.Representative.Value {// 대표번호일때 강제로 콜링으로 변환
|
|
|
|
|
s.SetAgentStatus(STATUS_AGENT_CALLING)
|
|
|
|
|
}
|
|
|
|
|
status := s.GetAgentStatus()
|
|
|
|
|
fmt.Println("BOT STATUS ", status == STATUS_AGENT_CALLING)
|
|
|
|
|
if status == STATUS_AGENT_CALLING {
|
|
|
|
|
ackMethod := fmt.Sprintf("sip:01025670081@%s;transport=%s", "192.168.0.222:5090", transport)
|
|
|
|
|
|
|
|
|
@ -941,6 +1046,8 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
fmt.Println(s)
|
|
|
|
|
fmt.Println("loop count ", s.simLoopCount)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
|
wlen,
|
|
|
|
|
(*s.sipNeter).LocalAddr().String(),
|
|
|
|
@ -1044,6 +1151,8 @@ func (s *IcsSession) ProcBye(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
//send call signal-end to VoiceAgent
|
|
|
|
|
/////////////////////////////////////////////
|
|
|
|
|
//set call signal addr
|
|
|
|
|
// fmt.Println(s)
|
|
|
|
|
fmt.Println(s)
|
|
|
|
|
csraddr := icsnet.NewNetAddrWithIPPort(s.AgentInfo.IP, s.AgentInfo.Port)
|
|
|
|
|
//csladdr := icsnet.NewNetAddrWithIPPort(conf.VoiceAgentConfig.MyAddr.ServerIP, conf.VoiceAgentConfig.MyAddr.ServerPort)
|
|
|
|
|
/*
|
|
|
|
@ -1132,40 +1241,18 @@ func (s *IcsSession) SendRequestInvite() {
|
|
|
|
|
fmt.Println("######### sim loop count!! ", conf.SimLoopCount)
|
|
|
|
|
fmt.Printf("Send Call Start Sip(%s) count %d!!!!!!!", s.AgentName, s.simLoopCount)
|
|
|
|
|
if s.simLoopCount < conf.SimLoopCount {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) count %d!!!!!!!", s.AgentName, s.simLoopCount)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) count %d!!!!!!!\r\n", s.AgentName, s.simLoopCount)
|
|
|
|
|
s.RequestInvite("01024342788")
|
|
|
|
|
// fmt.Printf("Sent Call Start sip(%s) count (%d)\n\n", s.AgentName, s.simLoopCount)
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Call Start sip(%s) count (%d)", s.AgentName, s.simLoopCount)
|
|
|
|
|
// tmp := "SIP/2.0 200 OK\r\nVia: SIP/2.0/UDP 192.168.0.83;received=192.168.0.21;rport=5090;branch=N2IwOGJjNmYtMTY5Zi00Y2NkLThjYzAtYWVhOTg3OGMyYTdj\r\nFrom: <sip:%s@192.168.83>;tag=MTY1MDk1NTEwNTY4NzgzNjI3NQ--\r\nTo: <sip:%s@192.168.0.83>;tag=1c1466330427\r\nCall-ID: 6a0b9cc3-e0c6-48da-a4f8-e7c40003bab2@192.168.0.21\r\nCSeq: 2 OPTIONS\r\nContact: <sip:192.168.0.222:5090>\r\nServer: M800B/v.7.20A.204.759\r\nContent-Length: 0\r\n"
|
|
|
|
|
// sendVal := []string{fmt.Sprintf(tmp, s.AgentName, s.AgentName)}
|
|
|
|
|
// address, err := net.ResolveUDPAddr("udp", "192.168.0.83:5090")
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// fmt.Printf("ERROR!: %s\n", err)
|
|
|
|
|
// }
|
|
|
|
|
// conn, err := net.DialUDP("udp", nil, address)
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "connect err", err)
|
|
|
|
|
// fmt.Println("## connect err", err)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "send val - %s", []string(sendVal))
|
|
|
|
|
// for _, elem := range sendVal[:] {
|
|
|
|
|
// sent, err := conn.Write([]byte(elem))
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// fmt.Printf("sent %d-%s\n", sent, elem)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// time.Sleep(time.Millisecond * 100)
|
|
|
|
|
// }
|
|
|
|
|
s.simLoopCount += 1
|
|
|
|
|
} else {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) END!!!!!!!", s.AgentName, s.simLoopCount)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) END!!!!!!!\r\n", s.AgentName, s.simLoopCount)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *IcsSession) ProcSIP20Bye(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
l := icslog.GetIcsLog()
|
|
|
|
|
conf := icsconf.GetIcsConfig()
|
|
|
|
|
// conf := icsconf.GetIcsConfig()
|
|
|
|
|
//ip := conf.InfoConfig.ServerIP
|
|
|
|
|
//mediaPort := conf.AgentConfig[s.ID].MediaConfig.Port
|
|
|
|
|
//sipPort := conf.SIPConfig.Port
|
|
|
|
@ -1173,65 +1260,75 @@ func (s *IcsSession) ProcSIP20Bye(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
//format := conf.AgentConfig[s.ID].MediaConfig.Format
|
|
|
|
|
|
|
|
|
|
l.Print(icslog.LOG_LEVEL_INFO, s.ID, "SIP2.0 BYE")
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
//send call signal-end to VoiceAgent
|
|
|
|
|
/////////////////////////////////////////////
|
|
|
|
|
//set call signal addr
|
|
|
|
|
csraddr := icsnet.NewNetAddrWithIPPort(s.AgentInfo.IP, s.AgentInfo.Port)
|
|
|
|
|
//csladdr := icsnet.NewNetAddrWithIPPort(conf.VoiceAgentConfig.MyAddr.ServerIP, conf.VoiceAgentConfig.MyAddr.ServerPort)
|
|
|
|
|
/*
|
|
|
|
|
csraddr := icsnet.NewNetAddrWithIPPort(conf.VoiceAgentConfig.AgentInfo[s.ID].IP, conf.VoiceAgentConfig.AgentInfo[s.ID].Port)
|
|
|
|
|
csladdr := icsnet.NewNetAddrWithIPPort(conf.VoiceAgentConfig.MyAddr.ServerIP, conf.VoiceAgentConfig.MyAddr.ServerPort)
|
|
|
|
|
*/
|
|
|
|
|
s.RemoveSession()
|
|
|
|
|
// ////////////////////////////////////////
|
|
|
|
|
// //send call signal-end to VoiceAgent
|
|
|
|
|
// /////////////////////////////////////////////
|
|
|
|
|
// //set call signal addr
|
|
|
|
|
// csraddr := icsnet.NewNetAddrWithIPPort(s.AgentInfo.IP, s.AgentInfo.Port)
|
|
|
|
|
// //csladdr := icsnet.NewNetAddrWithIPPort(conf.VoiceAgentConfig.MyAddr.ServerIP, conf.VoiceAgentConfig.MyAddr.ServerPort)
|
|
|
|
|
// /*
|
|
|
|
|
// csraddr := icsnet.NewNetAddrWithIPPort(conf.VoiceAgentConfig.AgentInfo[s.ID].IP, conf.VoiceAgentConfig.AgentInfo[s.ID].Port)
|
|
|
|
|
// csladdr := icsnet.NewNetAddrWithIPPort(conf.VoiceAgentConfig.MyAddr.ServerIP, conf.VoiceAgentConfig.MyAddr.ServerPort)
|
|
|
|
|
// */
|
|
|
|
|
|
|
|
|
|
// defer func() {
|
|
|
|
|
// if err := recover(); err != nil {
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_WARN, s.ID, "%s %s\n%s",
|
|
|
|
|
// icserror.ICSERRNETNotConnectError.GetMessage(), csraddr, debug.Stack())
|
|
|
|
|
// }
|
|
|
|
|
// }()
|
|
|
|
|
// var inout string = "O"
|
|
|
|
|
// s.SetDirection(true)
|
|
|
|
|
// if s.GetDirection() {
|
|
|
|
|
// inout = "I"
|
|
|
|
|
// }
|
|
|
|
|
// callsignal := writecallsignal.NewCallSignalData()
|
|
|
|
|
// s.StartTimeStamp = time.Now().UnixNano()
|
|
|
|
|
// s.EndTimeStamp = time.Now().UnixNano()
|
|
|
|
|
// s.ChannelID = conf.GetChannelID()
|
|
|
|
|
// s.ServerID = conf.GetServerID()
|
|
|
|
|
// station := conf.AgentConfig[s.ID].Name
|
|
|
|
|
// s.Station = station
|
|
|
|
|
// ///////////
|
|
|
|
|
// cust1 := strings.SplitN(sip.From, "@", 2)
|
|
|
|
|
// cust2 := strings.SplitN(cust1[0], ":", 2)
|
|
|
|
|
// s.CustID = cust2[1]
|
|
|
|
|
// //////////
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_DEBUG2, s.ID, ">>>>>channelid: %s, serverid: %d, station: %s, Custom: %s, starttimestamp: %d, START, inout: %s\n",
|
|
|
|
|
// s.ChannelID, s.ServerID, s.Station, s.CustID, s.StartTimeStamp, inout)
|
|
|
|
|
// callsignal.SetData(s.ChannelID, s.ServerID, s.Station, s.CustID, s.StartTimeStamp, s.EndTimeStamp, "E", inout)
|
|
|
|
|
// t, wlen, werr := icsnet.SendCallSignal(nil, &csraddr, callsignal.GetData())
|
|
|
|
|
// //t, wlen, werr := icsnet.SendCallSignal(&csladdr, &csraddr, callsignal.GetData())
|
|
|
|
|
// defer t.Close()
|
|
|
|
|
// if werr != nil {
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Failed to send Call-End signal to VoiceAgent(%s)", werr.GetError())
|
|
|
|
|
// } else {
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Call-End signal to VoiceAgent(%d)", wlen)
|
|
|
|
|
// }
|
|
|
|
|
// //close voiceneter(voice connection to voice agent)
|
|
|
|
|
// if s.VoiceNeter != nil {
|
|
|
|
|
// s.VoiceNeter.Close()
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_WARN, s.ID, "%s %s\n%s",
|
|
|
|
|
icserror.ICSERRNETNotConnectError.GetMessage(), csraddr, debug.Stack())
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
var inout string = "O"
|
|
|
|
|
s.SetDirection(true)
|
|
|
|
|
if s.GetDirection() {
|
|
|
|
|
inout = "I"
|
|
|
|
|
}
|
|
|
|
|
callsignal := writecallsignal.NewCallSignalData()
|
|
|
|
|
s.StartTimeStamp = time.Now().UnixNano()
|
|
|
|
|
s.EndTimeStamp = time.Now().UnixNano()
|
|
|
|
|
s.ChannelID = conf.GetChannelID()
|
|
|
|
|
s.ServerID = conf.GetServerID()
|
|
|
|
|
station := conf.AgentConfig[s.ID].Name
|
|
|
|
|
s.Station = station
|
|
|
|
|
///////////
|
|
|
|
|
cust1 := strings.SplitN(sip.From, "@", 2)
|
|
|
|
|
cust2 := strings.SplitN(cust1[0], ":", 2)
|
|
|
|
|
s.CustID = cust2[1]
|
|
|
|
|
//////////
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_DEBUG2, s.ID, ">>>>>channelid: %s, serverid: %d, station: %s, Custom: %s, starttimestamp: %d, START, inout: %s\n",
|
|
|
|
|
s.ChannelID, s.ServerID, s.Station, s.CustID, s.StartTimeStamp, inout)
|
|
|
|
|
callsignal.SetData(s.ChannelID, s.ServerID, s.Station, s.CustID, s.StartTimeStamp, s.EndTimeStamp, "E", inout)
|
|
|
|
|
t, wlen, werr := icsnet.SendCallSignal(nil, &csraddr, callsignal.GetData())
|
|
|
|
|
//t, wlen, werr := icsnet.SendCallSignal(&csladdr, &csraddr, callsignal.GetData())
|
|
|
|
|
defer t.Close()
|
|
|
|
|
if werr != nil {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Failed to send Call-End signal to VoiceAgent(%s)", werr.GetError())
|
|
|
|
|
// s.RemoveSession()
|
|
|
|
|
fmt.Println("######### sim loop count!! ", conf.SimLoopCount)
|
|
|
|
|
fmt.Printf("Send Call Start Sip(%s) count %d!!!!!!!", s.AgentName, s.simLoopCount)
|
|
|
|
|
if s.simLoopCount < conf.SimLoopCount {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) count %d!!!!!!!\r\n", s.AgentName, s.simLoopCount)
|
|
|
|
|
s.RequestInvite("01024342788")
|
|
|
|
|
s.simLoopCount += 1
|
|
|
|
|
} else {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Call-End signal to VoiceAgent(%d)", wlen)
|
|
|
|
|
}
|
|
|
|
|
//close voiceneter(voice connection to voice agent)
|
|
|
|
|
if s.VoiceNeter != nil {
|
|
|
|
|
s.VoiceNeter.Close()
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) END!!!!!!!\r\n", s.AgentName, s.simLoopCount)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.RemoveSession()
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//rtp sender callback timer function
|
|
|
|
|
func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
|
|
|
|
|
l := icslog.GetIcsLog()
|
|
|
|
|
//conf := icsconf.GetIcsConfig()
|
|
|
|
|
conf := icsconf.GetIcsConfig()
|
|
|
|
|
//format := conf.AgentConfig[s.ID].MediaConfig.Format
|
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
@ -1270,7 +1367,7 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// voiceFilePath := "/home/leejj9612/sim/voice/9001-RX-1648533187911907029.pcm"
|
|
|
|
|
voiceFilePath := "/home/leejj9612/sim/voice/Sample.pcm"
|
|
|
|
|
voiceFilePath := "/home/icsvsim/voice/Sample.pcm"
|
|
|
|
|
readPcmData, ferr := ioutil.ReadFile(voiceFilePath)
|
|
|
|
|
if ferr != nil {
|
|
|
|
|
fmt.Println("Read Voice File error ", ferr)
|
|
|
|
@ -1283,6 +1380,7 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
|
|
|
|
|
pcmDataLen := len(readPcmData)
|
|
|
|
|
pcmData := make([]byte, pcmDataLen)
|
|
|
|
|
copy(pcmData, readPcmData[44:]) //cut off wave header
|
|
|
|
|
// fmt.Printf("@@@@@ Read Data len: %d\r\n@@@@@ data: %+v\r\n@@@@@ copyData: %+v \r\n\r\n", pcmDataLen, readPcmData, pcmData)
|
|
|
|
|
//pcmData := s.tts[44:] //cut off wave header
|
|
|
|
|
//fmt.Println("pcmData len>>>", pcmDataLen, len(s.tts))
|
|
|
|
|
s.m.Unlock()
|
|
|
|
@ -1297,85 +1395,175 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
|
|
|
|
|
}
|
|
|
|
|
//defer s.TxConverter.Close()
|
|
|
|
|
|
|
|
|
|
fmt.Printf("@@@@@@@@@@@@@@@@@ pcmDataLen : %d, loop Count: %d \r\n", pcmDataLen, conf.CallEndInfo.Loop)
|
|
|
|
|
//fmt.Println(">>>", s.payloadType, icspacketparser.RTPPayloadInfo[s.payloadType].PSize)
|
|
|
|
|
var rtp *icsrtp.RTP
|
|
|
|
|
for {
|
|
|
|
|
iter := 0
|
|
|
|
|
totalSentLen := 0
|
|
|
|
|
offset := 0
|
|
|
|
|
psize := icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
ts := s.rtpTS
|
|
|
|
|
seq := s.rtpSeq
|
|
|
|
|
for t1 := range t.GetTick() {
|
|
|
|
|
if pcmDataLen < offset+psize*2 {
|
|
|
|
|
//fmt.Println("BREAK!", pcmDataLen, offset+psize*2)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
payload, convErr := s.TxConverter.Encode(pcmData[offset : offset+psize*2])
|
|
|
|
|
//payload, convErr := s.TxConverter.Encode(s.tts[offset : offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
|
|
|
|
|
if convErr != nil {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Encoding Error - %s", convErr.GetError())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("1048@@@@ %+v\n", s.rtpMediaNeter)
|
|
|
|
|
/*
|
|
|
|
|
wflen, wferr := ttsfile1.Write(payload)
|
|
|
|
|
if wferr != nil {
|
|
|
|
|
fmt.Println("file.write error", wferr, wflen)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
if conf.CallEndInfo.Value {
|
|
|
|
|
for lc := 0; lc < conf.CallEndInfo.Loop; lc++ {
|
|
|
|
|
fmt.Printf("@@@@@@@@@@@@@@@@@@@@@@ %d ", lc)
|
|
|
|
|
iter := 0
|
|
|
|
|
totalSentLen := 0
|
|
|
|
|
offset := 0
|
|
|
|
|
psize := icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
ts := s.rtpTS
|
|
|
|
|
seq := s.rtpSeq
|
|
|
|
|
for t1 := range t.GetTick() {
|
|
|
|
|
if pcmDataLen < offset+psize {
|
|
|
|
|
//fmt.Println("BREAK!", pcmDataLen, offset+psize*2)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
ttsfile1.Sync()
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
uplus에서 샘플 음성으로 pcma를 사용(이미 인코딩 되있는 음성파일이라 읽어서 160씩 보내주면됨)
|
|
|
|
|
- 인코딩 할 필요 없는 파일이라 인코딩 제거
|
|
|
|
|
- pcma여서 160으로 고정해서 전송(다른 경우는 추후 진행)
|
|
|
|
|
*/
|
|
|
|
|
payload := pcmData[offset : offset+psize]
|
|
|
|
|
//payload, convErr := s.TxConverter.Encode(s.tts[offset : offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
|
|
|
|
|
// if convErr != nil {
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Encoding Error - %s", convErr.GetError())
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("1048@@@@ %+v\n", s.rtpMediaNeter)
|
|
|
|
|
/*
|
|
|
|
|
wflen, wferr := ttsfile1.Write(payload)
|
|
|
|
|
if wferr != nil {
|
|
|
|
|
fmt.Println("file.write error", wferr, wflen)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
ttsfile1.Sync()
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if iter == 0 {
|
|
|
|
|
if offset+psize >= pcmDataLen {
|
|
|
|
|
//if offset+psize >= alawDataLen {
|
|
|
|
|
offset = 0
|
|
|
|
|
if iter == 0 {
|
|
|
|
|
if offset+psize >= pcmDataLen {
|
|
|
|
|
//if offset+psize >= alawDataLen {
|
|
|
|
|
offset = 0
|
|
|
|
|
}
|
|
|
|
|
rtp = icsrtp.NewRTP(1, //set mark bit
|
|
|
|
|
int(s.payloadType),
|
|
|
|
|
int(seq),
|
|
|
|
|
int(ts),
|
|
|
|
|
int(s.rtpSSRC),
|
|
|
|
|
payload)
|
|
|
|
|
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
|
|
|
|
|
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
offset += psize
|
|
|
|
|
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
} else {
|
|
|
|
|
if offset+psize >= pcmDataLen {
|
|
|
|
|
//if offset+psize >= alawDataLen {
|
|
|
|
|
offset = 0
|
|
|
|
|
}
|
|
|
|
|
rtp = icsrtp.NewRTP(0,
|
|
|
|
|
int(s.payloadType),
|
|
|
|
|
int(seq),
|
|
|
|
|
int(ts),
|
|
|
|
|
int(s.rtpSSRC),
|
|
|
|
|
payload)
|
|
|
|
|
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
|
|
|
|
|
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
offset += psize
|
|
|
|
|
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
}
|
|
|
|
|
rtp = icsrtp.NewRTP(1, //set mark bit
|
|
|
|
|
int(s.payloadType),
|
|
|
|
|
int(seq),
|
|
|
|
|
int(ts),
|
|
|
|
|
int(s.rtpSSRC),
|
|
|
|
|
payload)
|
|
|
|
|
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
|
|
|
|
|
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
offset += psize * 2
|
|
|
|
|
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
} else {
|
|
|
|
|
if offset+psize >= pcmDataLen {
|
|
|
|
|
//if offset+psize >= alawDataLen {
|
|
|
|
|
offset = 0
|
|
|
|
|
iter++
|
|
|
|
|
ts += uint32(psize)
|
|
|
|
|
seq++
|
|
|
|
|
s.txCnt++
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("1095@@@@ %+v\n", s.rtpMediaNeter)
|
|
|
|
|
wlen, werr := s.rtpMediaNeter.WriteRTP(rtp.Byte())
|
|
|
|
|
if werr != nil {
|
|
|
|
|
fmt.Println(t1, wlen, werr)
|
|
|
|
|
}
|
|
|
|
|
rtp = icsrtp.NewRTP(0,
|
|
|
|
|
int(s.payloadType),
|
|
|
|
|
int(seq),
|
|
|
|
|
int(ts),
|
|
|
|
|
int(s.rtpSSRC),
|
|
|
|
|
payload)
|
|
|
|
|
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
|
|
|
|
|
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
offset += psize * 2
|
|
|
|
|
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
}
|
|
|
|
|
iter++
|
|
|
|
|
ts += uint32(psize)
|
|
|
|
|
seq++
|
|
|
|
|
s.txCnt++
|
|
|
|
|
//fmt.Printf("wlen: %d\r", totalSentLen)
|
|
|
|
|
//l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent RTP(%d) to %s", wlen, s.rtpMediaNeter.RemoteAddr().String())
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("1095@@@@ %+v\n", s.rtpMediaNeter)
|
|
|
|
|
wlen, werr := s.rtpMediaNeter.WriteRTP(rtp.Byte())
|
|
|
|
|
if werr != nil {
|
|
|
|
|
fmt.Println(t1, wlen, werr)
|
|
|
|
|
}
|
|
|
|
|
//fmt.Printf("wlen: %d\r", totalSentLen)
|
|
|
|
|
//l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent RTP(%d) to %s", wlen, s.rtpMediaNeter.RemoteAddr().String())
|
|
|
|
|
// fmt.Printf("Sent RTP(%d) to [%s] [%s]\r\n", totalSentLen, s.rtpMediaNeter.RemoteAddr().String(), s.AgentName )
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent RTP(%d) to %s", totalSentLen, s.rtpMediaNeter.RemoteAddr().String())
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
}
|
|
|
|
|
s.RequestBYE(s.InviteSIP)
|
|
|
|
|
} else {
|
|
|
|
|
for {
|
|
|
|
|
iter := 0
|
|
|
|
|
totalSentLen := 0
|
|
|
|
|
offset := 0
|
|
|
|
|
psize := icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
ts := s.rtpTS
|
|
|
|
|
seq := s.rtpSeq
|
|
|
|
|
for t1 := range t.GetTick() {
|
|
|
|
|
if pcmDataLen < offset+psize*2 {
|
|
|
|
|
//fmt.Println("BREAK!", pcmDataLen, offset+psize*2)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
payload, convErr := s.TxConverter.Encode(pcmData[offset : offset+psize*2])
|
|
|
|
|
//payload, convErr := s.TxConverter.Encode(s.tts[offset : offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
|
|
|
|
|
if convErr != nil {
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Encoding Error - %s", convErr.GetError())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("1048@@@@ %+v\n", s.rtpMediaNeter)
|
|
|
|
|
/*
|
|
|
|
|
wflen, wferr := ttsfile1.Write(payload)
|
|
|
|
|
if wferr != nil {
|
|
|
|
|
fmt.Println("file.write error", wferr, wflen)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
ttsfile1.Sync()
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if iter == 0 {
|
|
|
|
|
if offset+psize >= pcmDataLen {
|
|
|
|
|
//if offset+psize >= alawDataLen {
|
|
|
|
|
offset = 0
|
|
|
|
|
}
|
|
|
|
|
rtp = icsrtp.NewRTP(1, //set mark bit
|
|
|
|
|
int(s.payloadType),
|
|
|
|
|
int(seq),
|
|
|
|
|
int(ts),
|
|
|
|
|
int(s.rtpSSRC),
|
|
|
|
|
payload)
|
|
|
|
|
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
|
|
|
|
|
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
offset += psize * 2
|
|
|
|
|
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
} else {
|
|
|
|
|
if offset+psize >= pcmDataLen {
|
|
|
|
|
//if offset+psize >= alawDataLen {
|
|
|
|
|
offset = 0
|
|
|
|
|
}
|
|
|
|
|
rtp = icsrtp.NewRTP(0,
|
|
|
|
|
int(s.payloadType),
|
|
|
|
|
int(seq),
|
|
|
|
|
int(ts),
|
|
|
|
|
int(s.rtpSSRC),
|
|
|
|
|
payload)
|
|
|
|
|
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
|
|
|
|
|
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
offset += psize * 2
|
|
|
|
|
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
|
|
|
|
|
}
|
|
|
|
|
iter++
|
|
|
|
|
ts += uint32(psize)
|
|
|
|
|
seq++
|
|
|
|
|
s.txCnt++
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("1095@@@@ %+v\n", s.rtpMediaNeter)
|
|
|
|
|
wlen, werr := s.rtpMediaNeter.WriteRTP(rtp.Byte())
|
|
|
|
|
if werr != nil {
|
|
|
|
|
fmt.Println(t1, wlen, werr)
|
|
|
|
|
}
|
|
|
|
|
//fmt.Printf("wlen: %d\r", totalSentLen)
|
|
|
|
|
//l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent RTP(%d) to %s", wlen, s.rtpMediaNeter.RemoteAddr().String())
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// fmt.Printf("Sent RTP(%d) to [%s] [%s]\r\n", totalSentLen, s.rtpMediaNeter.RemoteAddr().String(), s.AgentName )
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent RTP(%d) to %s", totalSentLen, s.rtpMediaNeter.RemoteAddr().String())
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
// s.RequestBYE(s.InviteSIP)
|
|
|
|
|
}
|
|
|
|
|
// fmt.Printf("Sent RTP(%d) to [%s] [%s]\r\n", totalSentLen, s.rtpMediaNeter.RemoteAddr().String(), s.AgentName )
|
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent RTP(%d) to %s", totalSentLen, s.rtpMediaNeter.RemoteAddr().String())
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1727,10 +1915,79 @@ func (s *IcsSession) ProcReferNotify200ok(sip *icspacketparser.SIP) {
|
|
|
|
|
optfunc()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *IcsSession) RequestBYESIM() {
|
|
|
|
|
l := icslog.GetIcsLog()
|
|
|
|
|
conf := icsconf.GetIcsConfig()
|
|
|
|
|
ip := conf.InfoConfig.ServerIP
|
|
|
|
|
port := conf.SIPConfig.Port
|
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
|
// contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", s.AgentName, ip, port, transport)
|
|
|
|
|
// fmt.Println(">>>contact", inviteSIP.Contact)
|
|
|
|
|
// contactName1 := strings.SplitN(inviteSIP.Contact, "sip:", 2)
|
|
|
|
|
// contactName := strings.SplitN(contactName1[1], "@", 2)
|
|
|
|
|
|
|
|
|
|
optfunc := func() {
|
|
|
|
|
optMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "AISB", conf.SIPConfig.SIPProxy, transport)
|
|
|
|
|
reqOpt := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_BYE, optMethod)
|
|
|
|
|
|
|
|
|
|
via := fmt.Sprintf("SIP/2.0/UDP %s:%d;branch=%s", ip, port, sipasm.GenerateBranch())
|
|
|
|
|
maxforwards := "70"
|
|
|
|
|
// from := strings.SplitN(s.CustID, ": ", 2)
|
|
|
|
|
from := s.AgentName
|
|
|
|
|
// from := fmt.Sprintf("<sip:%s@%s>;tag=%s", s.AgentName, ip, sipasm.GenerateTag())
|
|
|
|
|
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", s.AgentName, ip)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
|
|
|
|
|
|
|
|
|
|
// to := strings.SplitN(, ": ", 2)
|
|
|
|
|
to := s.CustID
|
|
|
|
|
//to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip)
|
|
|
|
|
callid := s.callID
|
|
|
|
|
cseq := fmt.Sprintf("%d BYE", s.Cseq)
|
|
|
|
|
s.Cseq++
|
|
|
|
|
//referto := fmt.Sprintf("<sip:01025670081@192.168.0.221>")
|
|
|
|
|
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", s.AgentName, ip, port, transport)
|
|
|
|
|
userAgent := conf.InfoConfig.Product
|
|
|
|
|
allow := "REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE"
|
|
|
|
|
supported := "timer,path,replaces"
|
|
|
|
|
contentLength := "0"
|
|
|
|
|
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_VIA, via)
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_MAX_FORWARDS, maxforwards)
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_FROM, to[0])
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_TO, from[0])
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, callid)
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, cseq)
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
|
//reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_REFER_TO, referto)
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_SUPPORTED, supported)
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, contentLength)
|
|
|
|
|
reqOpt.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
|
|
|
|
|
|
|
|
|
|
wlen, werr := (*s.sipNeter).WriteSIP([]byte(reqOpt.String()))
|
|
|
|
|
if werr != nil {
|
|
|
|
|
l.Print(icslog.LOG_LEVEL_FATAL, s.ID, werr.GetMessage())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//l.Printf(icslog.LOG_LEVEL_WARN, s.ID, "BYE CALL STACK\n%s", debug.Stack())
|
|
|
|
|
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
|
wlen,
|
|
|
|
|
(*s.sipNeter).LocalAddr().String(),
|
|
|
|
|
(*s.sipNeter).RemoteAddr().String(),
|
|
|
|
|
reqOpt.String())
|
|
|
|
|
}
|
|
|
|
|
optfunc()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//request bye
|
|
|
|
|
func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) {
|
|
|
|
|
l := icslog.GetIcsLog()
|
|
|
|
|
conf := icsconf.GetIcsConfig()
|
|
|
|
|
fmt.Printf("inviteSIP %+v\r\n", inviteSIP)
|
|
|
|
|
ip := conf.InfoConfig.ServerIP
|
|
|
|
|
port := conf.SIPConfig.Port
|
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
@ -1793,6 +2050,66 @@ func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) {
|
|
|
|
|
optfunc()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *IcsSession) Res486Ack(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
|
l := icslog.GetIcsLog()
|
|
|
|
|
conf := icsconf.GetIcsConfig()
|
|
|
|
|
|
|
|
|
|
ip := conf.InfoConfig.ServerIP
|
|
|
|
|
//mediaPort := conf.AgentConfig[s.ID].MediaConfig.Port
|
|
|
|
|
sipPort := conf.SIPConfig.Port
|
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
|
|
|
|
|
|
ackMethod := fmt.Sprintf("sip:01025670081@%s;transport=%s", "192.168.0.222:5090", transport)
|
|
|
|
|
|
|
|
|
|
reqAck := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_ACK, ackMethod)
|
|
|
|
|
|
|
|
|
|
//via := fmt.Sprintf("SIP/2.0/UDP %s;rport;branch=%s", ip, sipasm.GenerateBranch())
|
|
|
|
|
maxforwards := "70"
|
|
|
|
|
//from := fmt.Sprintf("<sip:%s@%s:5090>;tag=%s", s.AgentName, ip, sipasm.GenerateTag())
|
|
|
|
|
|
|
|
|
|
s.uri = fmt.Sprintf("sip:%s@%s", s.AgentName, ip)
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
|
|
|
|
|
|
|
|
|
|
//to := fmt.Sprintf("<sip:%s@%s;user=phone>", "01025670081", "192.168.0.221")
|
|
|
|
|
//to := fmt.Sprintf("<sip:%s@%s;user=phone>", "01025670081", ip)
|
|
|
|
|
//to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip)
|
|
|
|
|
//cseq := fmt.Sprintf("%d INVITE", s.Cseq)
|
|
|
|
|
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", s.AgentName, ip, sipPort, transport)
|
|
|
|
|
userAgent := conf.InfoConfig.Product
|
|
|
|
|
allow := "REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE"
|
|
|
|
|
supported := "timer,path,replaces"
|
|
|
|
|
|
|
|
|
|
for _, viav := range sip.Via {
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_VIA, viav)
|
|
|
|
|
}
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_MAX_FORWARDS, maxforwards)
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_FROM, sip.From)
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_TO, sip.To)
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, sip.CallID)
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, sip.Cseq)
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_SUPPORTED, supported)
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, "0")
|
|
|
|
|
reqAck.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
|
|
|
|
|
|
|
|
|
|
// wlen, werr := (*s.sipNeter).WriteSIPTo([]byte(reqAck.String()), s.remoteSIPAddr)
|
|
|
|
|
wlen, werr := (*s.sipNeter).WriteSIP([]byte(reqAck.String()))
|
|
|
|
|
if werr != nil {
|
|
|
|
|
l.Print(icslog.LOG_LEVEL_FATAL, s.ID, werr.GetMessage())
|
|
|
|
|
s.SetAgentStatus(STATUS_AGENT_READY)
|
|
|
|
|
return werr
|
|
|
|
|
}
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
|
wlen,
|
|
|
|
|
(*s.sipNeter).LocalAddr().String(),
|
|
|
|
|
(*s.sipNeter).RemoteAddr().String(),
|
|
|
|
|
reqAck.String())
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *IcsSession) ResError(sip *icspacketparser.SIP, errNum int) {
|
|
|
|
|
var resError *sipasm.SIPMessage
|
|
|
|
|
l := icslog.GetIcsLog()
|
|
|
|
|