diff --git a/third_party/vowifi-go/internal/vowifi/imscore/sms_24_341_test.go b/third_party/vowifi-go/internal/vowifi/imscore/sms_24_341_test.go index 7001ee7e..544fc638 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/sms_24_341_test.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/sms_24_341_test.go @@ -84,7 +84,7 @@ func TestInboundMemoryFullSendsRPError22ThenSMMA(t *testing.T) { }); err != nil { t.Fatal(err) } - if !strings.HasPrefix(response, "SIP/2.0 200") { + if !strings.HasPrefix(response, "SIP/2.0 202") { t.Fatalf("SIP response = %q", response) } select { @@ -290,7 +290,7 @@ func TestInboundDummyMSISDNWithoutFeatureCapsIsDiscarded(t *testing.T) { }); err != nil { t.Fatal(err) } - if !strings.HasPrefix(response, "SIP/2.0 200") { + if !strings.HasPrefix(response, "SIP/2.0 202") { t.Fatalf("SIP response = %q", response) } select { diff --git a/third_party/vowifi-go/internal/vowifi/imscore/sms_delivery_report.go b/third_party/vowifi-go/internal/vowifi/imscore/sms_delivery_report.go index ae200dbf..33635d7d 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/sms_delivery_report.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/sms_delivery_report.go @@ -66,7 +66,7 @@ func (s *Service) handleInboundTPStatusReport(raw string, rpMR byte, payload []b if err != nil { return s.inboundSMSProtocolError(raw, 400, rpMR, true, err) } - response, err := buildSIPRequestResponse(raw, 200) + response, err := buildSIPRequestResponse(raw, inboundRPDataSIPStatus) if err != nil { return inboundSIPResult{}, err } diff --git a/third_party/vowifi-go/internal/vowifi/imscore/sms_inbound.go b/third_party/vowifi-go/internal/vowifi/imscore/sms_inbound.go index fcd680ec..ba3d4bd9 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/sms_inbound.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/sms_inbound.go @@ -17,8 +17,11 @@ import ( const ( imsSMSContentType = "application/vnd.3gpp.sms" rpCauseTemporaryFailure = byte(41) - inboundSMSAckTimeout = 10 * time.Second - inboundSMSFragmentTTL = 3 * time.Minute + // TS 24.341 5.3.2.3: MT RP-DATA is accepted with SIP 202, then RP-ACK + // is sent in a separate MESSAGE. RP-ACK/RP-ERROR of our MO stay 200. + inboundRPDataSIPStatus = 202 + inboundSMSAckTimeout = 10 * time.Second + inboundSMSFragmentTTL = 3 * time.Minute // A carrier response arrived 35m37s late in production. One hour keeps a // bounded recovery margin without delaying the 3-minute user notification. inboundSMSLateReassemblyTTL = time.Hour @@ -172,7 +175,7 @@ func (s *Service) handleInboundRPData(raw string, rpdu []byte, rpMR byte, xml sh } if smscodec.IsDummyMSISDN(message.sender) { if !hasMSISDNLessFeatureCaps(raw) { - response, responseErr := buildSIPRequestResponse(raw, 200) + response, responseErr := buildSIPRequestResponse(raw, inboundRPDataSIPStatus) return inboundSIPResult{response: response}, responseErr } message.msisdnLess = true @@ -182,7 +185,7 @@ func (s *Service) handleInboundRPData(raw string, rpdu []byte, rpMR byte, xml sh } } s.logInboundSMSCorrelation(raw, message) - response, err := buildSIPRequestResponse(raw, 200) + response, err := buildSIPRequestResponse(raw, inboundRPDataSIPStatus) if err != nil { return inboundSIPResult{}, err } diff --git a/third_party/vowifi-go/internal/vowifi/imscore/sms_inbound_test.go b/third_party/vowifi-go/internal/vowifi/imscore/sms_inbound_test.go index 9ce22540..9766cf80 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/sms_inbound_test.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/sms_inbound_test.go @@ -35,7 +35,7 @@ func TestInboundSMSDeliversEventAndSendsRPAck(t *testing.T) { }); err != nil { t.Fatalf("dispatchInboundSIP: %v", err) } - if !strings.HasPrefix(response, "SIP/2.0 200") { + if !strings.HasPrefix(response, "SIP/2.0 202") { t.Fatalf("SIP response = %q", response) } diff --git a/third_party/vowifi-go/internal/vowifi/imscore/sms_multipart_test.go b/third_party/vowifi-go/internal/vowifi/imscore/sms_multipart_test.go index 0d4db0eb..6e111330 100644 --- a/third_party/vowifi-go/internal/vowifi/imscore/sms_multipart_test.go +++ b/third_party/vowifi-go/internal/vowifi/imscore/sms_multipart_test.go @@ -178,7 +178,7 @@ func dispatchInboundMultipartPart(t *testing.T, service *Service, rawTPDU []byte }); err != nil { t.Fatal(err) } - if !strings.HasPrefix(response, "SIP/2.0 200") { + if !strings.HasPrefix(response, "SIP/2.0 202") { t.Fatalf("SIP response = %q", response) } } diff --git a/third_party/vowifi-go/internal/vowifi/voice/builder.go b/third_party/vowifi-go/internal/vowifi/voice/builder.go index ce250b3a..68826d12 100644 --- a/third_party/vowifi-go/internal/vowifi/voice/builder.go +++ b/third_party/vowifi-go/internal/vowifi/voice/builder.go @@ -255,8 +255,10 @@ func buildBasicSDP(ip string, port int, sessionID int64) []byte { "s=VoHive Call\r\n"+ "c=IN %s %s\r\n"+ "t=0 0\r\n"+ - "m=audio %d RTP/AVP 104 110 102 108 106 101 0\r\n"+ + "m=audio %d RTP/AVP 104 110 102 108 106 96 101\r\n"+ "b=AS:80\r\n"+ + "b=RS:0\r\n"+ + "b=RR:0\r\n"+ "a=rtpmap:104 AMR-WB/16000\r\n"+ "a=fmtp:104 mode-change-capability=2;max-red=0\r\n"+ "a=rtpmap:110 AMR-WB/16000\r\n"+ @@ -267,14 +269,16 @@ func buildBasicSDP(ip string, port int, sessionID int64) []byte { "a=fmtp:108 octet-align=1;mode-change-capability=2;max-red=0\r\n"+ "a=rtpmap:106 EVS/16000\r\n"+ "a=fmtp:106 evs-mode-switch=1;hf-only=0;br=6.6-23.85;bw=wb;ch-aw-recv=-1;max-red=0\r\n"+ + "a=rtpmap:96 telephone-event/16000\r\n"+ + "a=fmtp:96 0-15\r\n"+ "a=rtpmap:101 telephone-event/8000\r\n"+ "a=fmtp:101 0-15\r\n"+ - "a=rtpmap:0 PCMU/8000\r\n"+ - sdpQoSReservedLocal + + sdpQoSReservedLocal+ "a=sendrecv\r\n"+ "a=ptime:20\r\n"+ - "a=maxptime:20\r\n", - sessionID, sessionID, ipFamily, ip, ipFamily, ip, port)) + "a=maxptime:240\r\n"+ + "a=rtcp:%d\r\n", + sessionID, sessionID, ipFamily, ip, ipFamily, ip, port, port+1)) } func (a *Agent) localAddr() string { diff --git a/third_party/vowifi-go/internal/vowifi/voice/hold.go b/third_party/vowifi-go/internal/vowifi/voice/hold.go index fb9267a5..0fffc576 100644 --- a/third_party/vowifi-go/internal/vowifi/voice/hold.go +++ b/third_party/vowifi-go/internal/vowifi/voice/hold.go @@ -9,12 +9,17 @@ import ( "github.com/iniwex5/vowifi-go/internal/vowifi/voice/callstate" ) -// HoldCall puts an established call on hold with a sendonly re-INVITE. +// ErrHoldNotAligned is kept for the phone/API mapping of a hold that the +// live IMS dialog cannot send. Originating hold/resume now sends the +// TS 24.610 re-INVITE via setCallHold. +var ErrHoldNotAligned = errors.New("voice: hold is not aligned to 24.229/24.610 on the live network") + +// HoldCall sends a mid-dialog hold re-INVITE (a=sendonly). func (a *Agent) HoldCall(ctx context.Context, callID string) error { return a.setCallHold(ctx, callID, true) } -// ResumeCall retrieves a locally held call with a sendrecv re-INVITE. +// ResumeCall sends a mid-dialog resume re-INVITE (a=sendrecv). func (a *Agent) ResumeCall(ctx context.Context, callID string) error { return a.setCallHold(ctx, callID, false) } diff --git a/third_party/vowifi-go/internal/vowifi/voice/outbound_simulate.go b/third_party/vowifi-go/internal/vowifi/voice/outbound_simulate.go index 399a49ed..4d409f11 100644 --- a/third_party/vowifi-go/internal/vowifi/voice/outbound_simulate.go +++ b/third_party/vowifi-go/internal/vowifi/voice/outbound_simulate.go @@ -6,6 +6,8 @@ import ( "fmt" "strings" "time" + + "github.com/iniwex5/vowifi-go/internal/vowifi/logging" ) const ( @@ -50,9 +52,31 @@ func (a *Agent) SimulateCall( if request.OnConnected != nil { request.OnConnected() } + if request.HoldSeconds >= 8 { + go a.exerciseSimulatedHoldResume(call) + } return a.holdSimulatedCall(ctx, call, request.HoldSeconds, startedAt) } +func (a *Agent) exerciseSimulatedHoldResume(call *Call) { + if a == nil || call == nil { + return + } + callID := call.CallID() + time.Sleep(2 * time.Second) + if err := a.HoldCall(context.Background(), callID); err != nil { + logging.Info("IMS simulated hold failed", "device", a.deviceID, "err", err) + return + } + logging.Info("IMS simulated hold sent", "device", a.deviceID) + time.Sleep(3 * time.Second) + if err := a.ResumeCall(context.Background(), callID); err != nil { + logging.Info("IMS simulated resume failed", "device", a.deviceID, "err", err) + return + } + logging.Info("IMS simulated resume sent", "device", a.deviceID) +} + func (a *Agent) waitForSimulateRegistration(ctx context.Context) error { endpoint := a.imsEndpoint() if endpoint == nil { diff --git a/third_party/vowifi-go/internal/vowifi/voice/sdp_restoration_test.go b/third_party/vowifi-go/internal/vowifi/voice/sdp_restoration_test.go index afd1c525..74e611aa 100644 --- a/third_party/vowifi-go/internal/vowifi/voice/sdp_restoration_test.go +++ b/third_party/vowifi-go/internal/vowifi/voice/sdp_restoration_test.go @@ -293,7 +293,7 @@ func TestGenerateBasicSDPUsesRecoveredPortSelection(t *testing.T) { gateway := NewGateway(agent) gateway.SetClientAdapter(&agentVoiceClientAdapter{}) got := string(agent.generateBasicSDP()) - if !strings.Contains(got, "m=audio 19998 RTP/AVP 104 110 102 108 106 101 0") { + if !strings.Contains(got, "m=audio 19998 RTP/AVP 104 110 102 108 106 96 101") { t.Fatalf("basic SDP uses wrong payload order or port: %q", got) } if !strings.Contains(got, "a=fmtp:104 mode-change-capability=2;max-red=0") || @@ -301,6 +301,13 @@ func TestGenerateBasicSDPUsesRecoveredPortSelection(t *testing.T) { !strings.Contains(got, "a=fmtp:110 octet-align=1") || !strings.Contains(got, "a=rtpmap:106 EVS/16000") || !strings.Contains(got, "a=fmtp:106 evs-mode-switch=1") || + !strings.Contains(got, "a=rtpmap:96 telephone-event/16000") || + !strings.Contains(got, "a=rtpmap:101 telephone-event/8000") || + strings.Contains(got, "a=rtpmap:0 PCMU") || + !strings.Contains(got, "a=maxptime:240") || + !strings.Contains(got, "a=rtcp:19999") || + !strings.Contains(got, "b=RS:0") || + !strings.Contains(got, "b=RR:0") || !strings.Contains(got, "a=curr:qos local sendrecv") || strings.Contains(got, "a=curr:qos local none") || !strings.Contains(got, "a=des:qos mandatory local sendrecv") || diff --git a/third_party/vowifi-go/internal/vowifi/voice/voice_test.go b/third_party/vowifi-go/internal/vowifi/voice/voice_test.go index 3fb99a95..97c90826 100644 --- a/third_party/vowifi-go/internal/vowifi/voice/voice_test.go +++ b/third_party/vowifi-go/internal/vowifi/voice/voice_test.go @@ -572,7 +572,10 @@ func TestBuildIMSInvite(t *testing.T) { t.Errorf("invite missing Call-ID: %q", invite) } if strings.Contains(invite, "m=audio 0 ") || - !strings.Contains(invite, "m=audio 12000 RTP/AVP 104 110 102 108 106 101 0") { + !strings.Contains(invite, "m=audio 12000 RTP/AVP 104 110 102 108 106 96 101") || + strings.Contains(invite, "a=rtpmap:0 PCMU") || + !strings.Contains(invite, "a=rtpmap:96 telephone-event/16000") || + !strings.Contains(invite, "a=maxptime:240") { t.Errorf("builder did not emit the recovered basic offer: %q", invite) } if !strings.Contains(invite, "P-Early-Media: supported") { diff --git a/third_party/vowifi-go/runtimehost/adapters_test.go b/third_party/vowifi-go/runtimehost/adapters_test.go index 1e68572e..f95c44c9 100644 --- a/third_party/vowifi-go/runtimehost/adapters_test.go +++ b/third_party/vowifi-go/runtimehost/adapters_test.go @@ -483,7 +483,7 @@ func assertProductionVoiceRequests(t *testing.T, requests <-chan string) { case request := <-requests: method := strings.Fields(request)[0] seen[method] = true - if method == "INVITE" && (strings.Contains(request, "m=audio 0 ") || !strings.Contains(request, "RTP/AVP 104 110 102 108 106 101 0")) { + if method == "INVITE" && (strings.Contains(request, "m=audio 0 ") || !strings.Contains(request, "RTP/AVP 104 110 102 108 106 96 101") || strings.Contains(request, "a=rtpmap:0 PCMU")) { t.Fatalf("INVITE did not advertise the allocated production media endpoint: %q", request) } default: diff --git a/third_party/vowifi-go/runtimehost/voicehost/async.go b/third_party/vowifi-go/runtimehost/voicehost/async.go index 0237ee5f..fae8a329 100644 --- a/third_party/vowifi-go/runtimehost/voicehost/async.go +++ b/third_party/vowifi-go/runtimehost/voicehost/async.go @@ -10,6 +10,10 @@ import ( "github.com/iniwex5/vowifi-go/internal/vowifi/voice" ) +// ErrHoldNotAligned is kept so the phone API can still map a hold that the +// live IMS dialog cannot send. +var ErrHoldNotAligned = voice.ErrHoldNotAligned + // BeginCallRequest starts a browser-media-backed outbound call. type BeginCallRequest struct { DeviceID string