Newshot

Where did the ACK go?

Summary

Breaking things with JioFiber, SIP and Asterisk. Comments

Original text(via Lobsters)
  • 2.How a Phone Call Actually Works?
  • 3.Getting the Credentials
  • 4.Setting up a PBX Server
  • 4.1.NixOS Setup
  • 4.2.Asterisk Configuration
  • 5.The Bugs Before the Real Bugs
  • 5.1.Wrong Dialplan Syntax
  • 5.2.Stale iOS Contacts
  • 6.No Audio in Call
  • 7.Registration Is Not a Ban
  • 8.Where Did the ACK Go?
  • 9.The Failure that Looked like MNP
  • 10.Everything I Tried that Didn’t Work
  • 11.What Other People’s Code Taught Me
  • 12.The *88 Experiment
  • 13.Building Asterisk-Jio
  • 14.It Works!
  • 15.Footnotes

I know the title is a bit clickbaity but it works for this post :P This is probably going to be a LONG one. I spent almost 3-4 days debugging and fighting on this and this is gonna be a proper log of what all I did. Fair warning though, I did exhaust my Cursor, OpenCode, and Claude limits debugging this one.⁠#

Bear with me as I try to explain all the complicated abbreviations that you might come across 😭⁠#

#The Plan

Some context as to what exactly I decided to do? My ISP, Jio provides a landline number with their Fiber connections and ever since I’ve removed their ONT box and replaced with my own Router, this did not really work and stayed broken.⁠#

While I was at home this month, a friend told me multiple times to extract those credentials from their box and set it up like he’s done.⁠#

That’s what this whole thing is about.⁠#

#How a Phone Call Actually Works?

Before going into all the technicalities, I’d like to explain the readers on how do calls over internet travel? It’s pretty straightforward (well, not really). There’s a protocol known as the Session Initiation Protocol (SIP) which was introduced in 1999 (crazy!).⁠#

But how does it work? Let’s look at this sequence diagram:⁠#

Looks pretty simple right? But SIP only handles the signaling, the “let’s have a call” part. The actual audio is described separately using SDP (Session Description Protocol), which gets sent inside the SIP messages. It’s basically a note that says “send audio here, in this format”:⁠#


        v=0
o=- 1234567890 1234567890 IN IP4 192.168.1.10
s=Phone Call
c=IN IP4 192.168.1.10  ; send audio to this address
t=0 0
m=audio 5004 RTP/AVP 0  ; on this port, using this codec
a=rtpmap:0 PCMU/8000
a=sendrecv  ; I want to both send and receive
      

This becomes important later when calls start failing with “invalid SDP offer or answer”.⁠#

#Getting the Credentials

Now onto the actual process. First thing I needed was the SIP credentials stored on the ONT by Jio.⁠#

I already had telnet access on the box since I enabled that earlier, they’ve since patched it in newer firmware’s! One of the reasons I don’t connect it to the Internet.⁠#

📝 Note: One key thing to note here is, it needs to be connected to internet at least once so it can get SIP credentials from their servers and store it on the disk!

What I wanted was basically a dump of the whole filesystem and somehow copying it back to my Mac (without internet). Luckily for this, I found that they use lighttpd for their admin interface which is great!⁠#

I connected to the WiFi exposed by the ONT and ran these commands:⁠#


        # 1. Dump everything to a tarball in /tmp
tar czf /tmp/ont_fs.tar.gz /pfrm2.0/etc/ /flash/ /flash2/ 2>/dev/null

# 2. Start lighttpd on port 9090 pointing at /tmp
cat > /tmp/lighty.conf << 'EOF'
server.document-root = "/tmp"
server.port = 9090
server.modules = ()
EOF
lighttpd -f /tmp/lighty.conf

# 3. Open the port in the firewall
/pfrm2.0/bin/iptables -I INPUT -p tcp --dport 9090 -j ACCEPT
/pfrm2.0/bin/iptables -I fwInBypass -p tcp --dport 9090 -j ACCEPT
      

Then, I could just simply do a curl request for the archive:⁠#


        curl http://192.168.29.1:9090/ont_scripts.tar.gz -o ~/ont_fs.tar.gz
      

The actual credentials were in a file called FixedVoiceCcsXML.dat under /flash/juice and it looked something like:⁠#


        <wap-provisioningdoc version="1.1">
    ...
    <characteristic type="APPAUTH">
        <parm name="AuthType" value="Digest" />
        <parm name="Realm" value="<your-realm>.ims.jio.com" />
        <parm name="UserName" value="+91XXXXXXXXXX@<your-realm>.ims.jio.com" />
        <parm name="UserPwd" value="..." />
    </characteristic>
    ...
</wap-provisioningdoc>
      

The key parts here are the Realm,UserName and UserPwd as you would’ve guessed and, Voila 🎉⁠#

#Setting up a PBX Server

Another term that might feel complicated, PBX also known as Private Branch Exchange. I’ll be using Asterisk for my setup.⁠#

Remember how the ONT was handling both, the internet, and landline? When I swapped it out, the internet kept working but the landline died. Nothing was talking to Jio’s voice servers anymore. Asterisk takes over that job.⁠#

It sits in the middle: on one side, my phone apps (Linphone on iOS, Zoiper on Mac) connect to it like it’s the carrier. On the other side, it connects to Jio’s IMS network and pretends to be a phone. When I make a call, it bridges the two.⁠#

Solid lines are signaling, dashed lines are audio. They travel separately, which matters a lot later.⁠#

#NixOS Setup

I use NixOS for my servers so I’ll be going through how I set it up on that, though it’s not that different if one is setting it up separately as well!⁠#

The Asterisk service is enabled with a custom overlay that swaps the default package for asterisk-with-jio — a patched build that includes the three extra modules we need (more on those later).⁠#


        services.asterisk = {
  package = pkgs.asterisk; # replaced by overlay with asterisk-with-jio
  useTheseDefaultConfFiles = [ ];
  confFiles = {
    "modules.conf" = ...;
    "rtp.conf" = ...;
    "http.conf" = ...;
  };
};
      

The sensitive config files (pjsip.conf, extensions.conf) are kept encrypted via SOPS and written directly to /etc/asterisk/ at activation.⁠#

#Asterisk Configuration

Asterisk has quite a few config files and here’s what I ended up with:⁠#

modules.conf — disables the old chan_sip and requires the three Jio-specific modules to be present at startup:⁠#


        [modules]
autoload = yes
noload = chan_sip.so
require = codec_amr.so
require = res_pjsip_amr.so
require = res_pjsip_jio.so
      

rtp.conf — sets the local UDP port range for audio:⁠#


        [general]
rtpstart = 52000
rtpend = 52200
strictrtp = yes
      

The firewall opens exactly those same ports:⁠#


        networking.firewall = {
  allowedUDPPorts = [ 5060 ];
  allowedTCPPorts = [ 5060 5061 ];
  allowedUDPPortRanges = [
    { from = 52000; to = 52200; }
  ];
};
      

pjsip.conf — this is where most of the actual SIP configuration lives. It has two sides, the Jio-facing trunk and the local phone apps.⁠#

First thing I noticed I had to set was the user_agent — we’re spoofing the router’s user agent so Jio thinks we’re a real CPE device:⁠#


        [global]
type = global
user_agent = JCO4032/JUICEJFV-1.3.30
keep_alive_interval = 10
      

For transports, I used UDP and TCP for local apps and ended up using TLS over IPv6:⁠#


        [transport-udp]
type = transport
protocol = udp
bind = 0.0.0.0:5060

[transport-udp6]
type = transport
protocol = udp
bind = [::]:5060

[transport-jio-tls6]
type = transport
protocol = tls
bind = [YOUR_IPV6_ADDRESS]:5062
method = tlsv1_2
verify_server = no
tcp_keepalive_enable = yes
tcp_keepalive_idle_time = 10
      

The Jio trunk endpoint ended up looking like this:⁠#


        [YOUR_NUMBER]
type = endpoint
100rel = yes                                 ; support reliable provisional responses
disallow = all
allow = amr,amrwb,ulaw,alaw                  ; codecs in preference order
direct_media = no                            ; keep audio flowing through Asterisk
from_domain = <your-realm>.ims.jio.com
from_user = +91XXXXXXXXXX
outbound_auth = jio-ims-auth
outbound_proxy = sip:[JIO_PROXY]:5061\;transport=tls\;lr
media_address = YOUR_IPV6_ADDRESS            ; explicit IPv6 address for RTP
bind_rtp_to_media_address = yes              ; bind audio socket to that address
timers = yes
timers_min_se = 90
timers_sess_expires = 1800
transport = transport-jio-tls6

[jio-ims-auth]
type = auth
auth_type = userpass
username = 91XXXXXXXXXX@<your-realm>.ims.jio.com
password = YOUR_PASSWORD  ; from the ONT dump
realm = <your-realm>.ims.jio.com

[jio-ims-registration]
type = registration
outbound_auth = jio-ims-auth
server_uri = sip:<your-realm>.ims.jio.com
client_uri = sip:+91XXXXXXXXXX@<your-realm>.ims.jio.com
max_retries = 10
retry_interval = 300              ; wait 5 mins between retries
auth_rejection_permanent = no     ; keep retrying even after auth failure
expiration = 3605
transport = transport-jio-tls6
forbidden_retry_interval = 300    ; same wait after a 403
      

And for Linphone and Zoiper on the local side:⁠#


        [linphone]
type = endpoint
disallow = all
allow = alaw,ulaw           ; G.711 only, Asterisk handles transcoding to AMR for Jio
direct_media = no
force_rport = yes
rewrite_contact = yes       ; rewrite contact with actual source IP (needed behind NAT)
aors = linphone
auth = linphone-auth
context = linphone-out      ; routes outbound calls through the linphone-out dialplan

[linphone-auth]
type = auth
auth_type = userpass
username = YOUR_USERNAME
password = YOUR_PASSWORD
      

pjsip_jio.conf — some Jio-specific registration fields that come from the ONT dump11 access_network tells the IMS what access type you’re connecting from (GPON = fiber). instance_id is a unique device identifier that comes from the ONT’s config — Jio uses it to identify your device during registration. :⁠#


        [general]
realm = <your-realm>.ims.jio.com
username = 91XXXXXXXXXX@<your-realm>.ims.jio.com
digest_uri = sip:<your-realm>.ims.jio.com
access_network = GPON\;PSAPId=+91001120
instance_id = 00000000-0000-1000-8000-XXXXXXXXXXXX
      

extensions.conf — the dialplan, which tells Asterisk what to do with calls.⁠#

For inbound calls from Jio, I wanted it to ring all my registered apps:⁠#


        [jio-in]
exten => _[+0-9].,1,NoOp(Inbound Jio call from ${CALLERID(num)})
same => n,Set(CONTACTS=${PJSIP_DIAL_CONTACTS(linphone)})
same => n,GotoIf($["${CONTACTS}" = ""]?unavailable)
same => n,Dial(${CONTACTS})
same => n,Hangup(${HANGUPCAUSE})
same => n(unavailable),Hangup(20)
      

For outbound I added some number normalization so I could dial in any format and it’d work:⁠#


        [linphone-out]
exten => _[6-9]XXXXXXXXX,1,Goto(jio-out,+91${EXTEN},1)
exten => _0[1-9]XXXXXXXXX,1,Goto(jio-out,+91${EXTEN:1},1)
exten => _91[6-9]XXXXXXXXX,1,Goto(jio-out,+${EXTEN},1)
exten => _[+0-9].,1,Goto(jio-out,${EXTEN},1)

[jio-out]
exten => _[+0-9].,1,NoOp(Outbound to ${EXTEN} via Jio)
same => n,Dial(PJSIP/YOUR_NUMBER/sip:${EXTEN}@<your-realm>.ims.jio.com,,Ib(jio-outbound-handler^add_header^1))
same => n,Hangup(${HANGUPCAUSE})
      

Jio also needs a P-Asserted-Identity header on every outgoing call, so I added a small handler for that:⁠#


        [jio-outbound-handler]
exten => add_header,1,NoOp(Injecting Jio Identity)
same => n,Set(PJSIP_HEADER(add,P-Asserted-Identity)=<sip:+91XXXXXXXXXX@<your-realm>.ims.jio.com>)
same => n,Return()
      

#The Bugs Before the Real Bugs

Before I even got to the interesting stuff, I managed to shoot myself in the foot a few times.⁠#

#Wrong Dialplan Syntax

I had my dialplan set up like this initially:⁠#


        exten => _[+0-9].,1,Dial(PJSIP/${EXTEN}/sip:${EXTEN}@<your-realm>.ims.jio.com)
      

What I didn’t realise is that Asterisk treats the first argument as an endpoint name, not a SIP URI. My endpoint was named jiofiber, so every outbound call just failed with “endpoint not found”. Took me quite a while to figure out that the correct way is:⁠#


        exten => _[+0-9].,1,Dial(PJSIP/${EXTEN}@jiofiber)
      

#Stale iOS Contacts

This one was annoying. Every time Linphone restarts on iOS it registers a fresh contact, but the old one doesn’t go away. So when an inbound call came in, Asterisk tried to ring all of them at the same time including the dead ones from previous sessions. The dead contact would fail immediately and bring the whole call down with a 503. Adding these two lines fixed it:⁠#


        [linphone]
type = aor
max_contacts = 1
remove_existing = yes
      

#No Audio in Call

So I could make calls and they would connect, but there was no audio on either side. The issue was that just opening port 5060 for SIP is not enough. The actual audio travels over RTP on a completely separate range of UDP ports, 52000-52200 in my case as configured in rtp.conf. I had not opened those on my MikroTik router.⁠#

I had to add two IPv6 forward rules on the MikroTik to let SIP and RTP through from the WAN interface to the server:⁠#


        /ipv6 firewall filter add chain=forward action=accept connection-state=new protocol=tcp \
    dst-address=YOUR_IPV6_SUBNET/64 in-interface=vlan-xpon out-interface=vlan20-servers \
    dst-port=5060 comment="Jio IMS TCP to Asterisk SIP"

/ipv6 firewall filter add chain=forward action=accept connection-state=new protocol=udp \
    dst-address=YOUR_IPV6_SUBNET/64 in-interface=vlan-xpon out-interface=vlan20-servers \
    dst-port=5060,52000-52200 comment="Jio media server RTP to Asterisk"
      

There was also an IPv6 issue where my server has multiple IPv6 addresses and Asterisk was advertising one in the SDP but the actual RTP socket was binding to a different one. I had to be explicit about which address to use:⁠#


        media_address = YOUR_IPV6_ADDRESS
bind_rtp_to_media_address = yes
      

media_address alone only sets what gets advertised in SDP, it doesn’t actually bind the socket. bind_rtp_to_media_address = yes is what makes the packets go out from the right address.⁠#

#Registration Is Not a Ban

Every time I restarted Asterisk during debugging it would fire a fresh REGISTER. I was restarting a lot. At some point Jio’s registrar started responding with 401 Unauthorized with stale=true on every attempt and the registration just stayed stuck in Rejected.⁠#

My first thought was that Jio had blocked the line or the credentials were wrong. But stale=true on a 401 just means the nonce expired, it’s a normal challenge telling you to retry with a fresh one. It’s not a ban.⁠#

What was actually happening is that with max_retries = 10 and retry_interval = 60, Asterisk was sending up to ten authenticated REGISTERs per minute. Each one triggered another auth attempt. Jio’s rate limiter blocked further attempts and the lockout kept extending because Asterisk kept retrying.⁠#

To confirm the credentials were actually correct I manually recomputed the Digest response from scratch and it matched byte for byte what Asterisk was sending:⁠#


        HA1 = MD5(username:realm:password)
HA2 = MD5(method:digest-uri)
response = MD5(HA1:nonce:nc:cnonce:qop:HA2)
      

The credential was fine, I was just hammering the registrar too fast. The fix was to back off:⁠#


        [jio-ims-registration]
max_retries = 1
retry_interval = 300
forbidden_retry_interval = 300
      

Once the lockout expired and Asterisk fired one clean authenticated REGISTER, it went straight to Registered.⁠#

#Where Did the ACK Go?

This is the one the title is about. And it happened twice.⁠#

The first time, I noticed inbound calls were dying at exactly 32 seconds and set timers=no on the trunk endpoint. That removes the session timer requirement from the 200 OK and it seemed to stop the drops, so I moved on. That was a mistake because it wasn’t actually the cause.⁠#

Later, the same 32-second symptom came back and this time I had to actually understand it. Inbound calls were going through the full signaling flow, Jio would send the INVITE, Asterisk would send back a 200 OK, and then nothing. No ACK ever came from Jio. Asterisk would retransmit the 200 OK eleven times, Timer H22 64 × T1 (500ms) = 32 seconds. SIP uses this to give up waiting for an ACK after sending a final response. would fire, and Asterisk would hang up the call with cause=408.⁠#

To make sure this wasn’t a network issue I ran a packet capture on all IPv6 traffic on the server. It showed that Jio’s P-CSCF was receiving every byte of the 200 OK, TCP was acknowledging it, but Jio was sending absolutely nothing back. No ACK, no CANCEL, no ICMPv6 error. The problem was inside Jio’s SBC, not in the network path.⁠#

I went through six hypotheses one by one:⁠#

  • P-Asserted-Identity missing from the 200 OK. Jio’s IMS requires the terminating UE to include PAI in its 2xx. I added it via an on_tx_response hook and confirmed it was present in the retransmitted responses. Still no ACK.
  • Wrong PAI realm. The first attempt had the S-CSCF hostname in the PAI instead of the home realm. Corrected it. Still no ACK.
  • Session timer requirement. Set timers=no to remove the Require: timer from the 200 OK. Still no ACK.
  • IPv6 UDP listener missing. Added a UDP transport on IPv6. Still no ACK and the capture confirmed Jio wasn’t sending anything on any port at all.
  • rewrite_contact mangling the Record-Route. This was the most interesting one.33 rewrite_contact rewrites Record-Route headers with the observed source IP and port. Jio’s Record-Route had no port, but we were echoing it back with :34588 — the ephemeral source port of the P-CSCF’s TCP connection, which is not a listener. Jio was routing its ACK to an unreachable socket. Removing rewrite_contact from the trunk endpoint fixed the Record-Route. Jio still sent no ACK though.
  • P-Called-Party-ID not echoed. Jio’s INVITE includes a P-Called-Party-ID header and a real CPE echoes it in the 200 OK. Added it via the hook. Still no ACK.

Every fix was correct on its own terms but none of them moved the specific symptom. The unfiltered packet capture was the most useful tool here because it eliminated every reachability hypothesis and proved the silence was coming from inside Jio’s SBC. I never fully resolved this one at the time.⁠#

#The Failure that Looked like MNP

This was the most frustrating part. Some calls to some numbers would just fail every time. Both Linphone and Zoiper, so it wasn’t the app. The failing sequence looked like this:⁠#

The 183 would come back with a Contact header containing rn and npdi parameters44 rn is a routing number used after a port. npdi means a portability lookup was done — it can appear even for non-ported numbers. and an identifier pointing to an Alcatel-Lucent 5060 MGC. These are MNP markers, they show up when a number has been ported to another carrier.⁠#

So the initial hypothesis was that these were ported numbers and the carrier’s routing database was broken for them. It looked very convincing. Roughly one out of fifteen attempts would go through on a visibly different route without those markers, and the rest would die with 487 / P-14018.⁠#

I went too far and called it a carrier-only problem. That was wrong.⁠#

#Everything I Tried that Didn’t Work

Over two days I tried a lot of things. Here’s a short summary of that:⁠#

ChangeWhat happened
Remove leading + from the destination number484 Address Incomplete for both the failing and working numbers. Jio requires E.164 format. Reverted.
Shorter CRLF keepalive at 10 secondsKeepalives confirmed on the wire. Same failure.
Remove maxptime from the SDPSame failure.
Fix malformed Content-Type and Content-LengthNecessary cleanup but the original failure remained.
Move carrier leg to TLS over IPv6Registration worked fine. Same call rejection.
Offer PCMU instead of PCMAFirst call worked. Next attempt on a marked route failed with the same error.
Added P-Early-Media: supportedCarrier echoed it back correctly, same 487 followed.
Added P-Early-Media: unsupportedCarrier ignored it entirely, still returned 183 with SDP.
Retry the callSometimes got a different visible route. Not consistently successful.

The PCMU attempt was especially good at producing false hope. I called my mom, she picked up, I could hear her. Then the next attempt failed with the same error on a marked route. The first call had just taken a different path.⁠#

#What Other People’s Code Taught Me

At some point I found sivatheja10/jiofiber-bridge which had a full DIRECT_IMS implementation for Jio. This was much more useful than a random config snippet because it was an actual working client implementation I could compare against. It offered PCMU, AMR and AMR-WB to the carrier, handled Jio-specific registration quirks, and had its own transport and signaling choices.⁠#

I also found a fix in another project, gsm-sip-bridge, where the exact same P-14018 error text had appeared but the cause was completely different. That project was treating a 200 OK for PRACK as though it were a 200 OK for INVITE and sending a premature ACK. Our traces didn’t show that mistake at all, but it completely overruled the idea that P-14018 uniquely meant an MNP database problem. The same error text but a totally different bug!⁠#

The rule I should have applied earlier: compare the exact transaction, not just the error string.⁠#

#The *88 Experiment

Rather than replace the production setup I put a temporary bridge behind a 88 dial prefix. So dialing 88 9876543210 would route through the bridge to Jio instead of going through native Asterisk directly. This let me test a completely different SIP implementation against the same carrier path without touching the working setup.⁠#

The bridge was built from the jiofiber-bridge code and handled two SIP legs with its own signaling behavior. I paused the production Asterisk registration while testing so there wouldn’t be two things registering at the same time.⁠#

The result was pretty clear. A PCMU-only call to a number with rn and npdi markers in the Contact went all the way through, then 180 Ringing, then 200 OK, then two-way audio. The same kind of marked route that had been rejecting everything from native Asterisk.⁠#

This broke the “carrier-only problem” conclusion completely. The endpoint implementation was what mattered, not just the codec or the destination.⁠#

I also tested an AMR-only offer through the bridge. It got reliable progress and ringing, then I cancelled it to avoid making yet another call to my mom. So AMR at least got past the early rejection point, but I didn’t let it complete.⁠#

#Building Asterisk-Jio

After the bridge experiment I wanted a proper solution instead of keeping a temporary bridge running forever. The bridge worked but it wasn’t something I could maintain long term and it wasn’t packaged for NixOS.⁠#

Stock Asterisk 22 has no AMR support at all. allow = amr in the config does nothing if the codec module isn’t there. I needed three things:⁠#

  • codec_amr.so for the actual AMR format, RTP payload handling, and transcoding between AMR and G.711
  • res_pjsip_amr.so for AMR SDP negotiation in PJSIP
  • res_pjsip_jio.so for Jio-specific registration quirks, the initial empty Digest authorization and the scoped 483 challenge handling

I started from traud/asterisk-amr for the codec work and built on top of it. The result is asterisk-jio, packaged as a Nix flake that builds against stock Asterisk 22.11.0 headers. The NixOS overlay we saw earlier swaps the default Asterisk package for asterisk-with-jio which includes all three modules.⁠#

#It Works!

After deploying and restarting the service, everything worked! Outbound calls, inbound calls, MNP numbers that were failing before! Yay 🥳⁠#

If you want to try this yourself, the asterisk-jio repo has build instructions and the config structure we went through here should get you most of the way there. You’ll need your own credentials from the ONT dump and your own realm and proxy addresses.⁠#

Until next time! 👋⁠#

#Footnotes

  • access_network tells the IMS what access type you’re connecting from (GPON = fiber). instance_id is a unique device identifier that comes from the ONT’s config — Jio uses it to identify your device during registration. ↩
  • 64 × T1 (500ms) = 32 seconds. SIP uses this to give up waiting for an ACK after sending a final response. ↩
  • rewrite_contact rewrites Record-Route headers with the observed source IP and port. Jio’s Record-Route had no port, but we were echoing it back with :34588 — the ephemeral source port of the P-CSCF’s TCP connection, which is not a listener. Jio was routing its ACK to an unreachable socket. ↩
  • rn is a routing number used after a port. npdi means a portability lookup was done — it can appear even for non-ported numbers. ↩

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by Lobsters
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗