Adding Custom Header to 183 Session Progress in Asterisk

Hi,

As we know, Asterisk only supports custom headers in INVITE messages. However, we have a scenario where we need to include the P-Early-Media: supported header in 183 Session Progress responses. This is required for our provider to accept media from our side.

Could you please guide me on which file needs to be modified to hardcode this header into every 183 Session Progress response?

Thank you in advance for your support!

The C file would be asterisk/channels/chan_pjsip.c at master · asterisk/asterisk · GitHub and you’d find the specific 183 parts by searching for 183.

1 Like

Yes, I have found the section handling 183 Session Progress in chan_pjsip.c. Is there a method available that allows me to set a custom header, such as P-Early-Media: supported, within this response?

I appreciate any guidance on this.

We provide a helper function[1] to add a header to a message.

[1] asterisk/include/asterisk/res_pjsip.h at master · asterisk/asterisk · GitHub

1 Like

Thanks! I’ll rebuild Asterisk after modifying the code and follow up here.

Hi, can you show how you modified code to add your specific header? I am interested in something similar. Regards

Hi Jcolp,

Should I use the ast_sip_add_header() method below(screenshot) to add the required header on the caller’s side in the 183 response?

I think above function only triggers when 183 received from B leg , but I am testing without creating channel B.

Where to call ast_sip_add_header() function when asterisk itself sending 183.

My current test flow: Local Extension → asterisk → Progress(183) → Local Extension

Below is the test dialplan context I am using to generate 183 response code.

[nbound]

exten => 200,1,NoOp(Dialing ${EXTEN} via Local user)
same => n,Progress(183)
same => n,Playback(hello-world,noanswer)
same => n,Hangup()

Sure, I will let you once worked for me.

That is for when Asterisk RECEIVES a 183 Session Progress. It is not when Asterisk SENDS a 183 Session Progress. That code is elsewhere in the file.

1 Like

Hi jcolp,

I have added ast_sip_add_header() function in below section, please check whether the syntax and location is correct as I am still not able to write required header in 183 response.

I appreciate any guidance on this.

This code is handling connected line updates, which is not, I think, the case, in your scenario. Also, I’m not really sure what a SIP response code means on a channel that is in a RING state, as that would be an outgoing channel, so one would be expecting responses to come from it, rather than go to it; maybe it something to do with using UPDATE.

Also, you might want to note that the Sangoma staff need a clean room environment, so shouldn’t be looking at code changes without a contributor licence in place. I’m not Sangoma, and am extremely unlikely to submit a change in this area, and in that case, I would still expect them to require them to submitted as gitbub changes.

1 Like

The function is ultimately indicate, but you have to add a response_code check to see if it is 183 and then add the header in it.

1 Like

I have added required function in indicate but asterisk seems to crash when try to execute that function, see below screenshot I have added log line just before function execution.

Please suggest correct syntax.

“packet” is NULL, it hasn’t been created yet. The pjsip_inv_answer function creates it. You can only add a header after it has been created.

1 Like

Thank you, Jcolp, for your support!

I have successfully modified the indicate() function to write to the 183 Session Progress response only if the header is not already present in the packet. Below is the working implementation.

static int indicate(void *data)
{
        pjsip_tx_data *packet = NULL;

        struct indicate_data *ind_data = data;
        struct ast_sip_session *session = ind_data->session;
        int response_code = ind_data->response_code;


        if ((session->inv_session->state != PJSIP_INV_STATE_DISCONNECTED) &&
                (pjsip_inv_answer(session->inv_session, response_code, NULL, NULL, &packet) == PJ_SUCCESS)) {
                if (response_code == 183) {
        ast_verb(3,"IN 183 RESPONSE");

        pjsip_generic_string_hdr *early_media;
        const pj_str_t EARLY_MEDIA = { "P-Early-Media", 13 };

        early_media = pjsip_msg_find_hdr_by_name(packet->msg, &EARLY_MEDIA, NULL);


         if (!early_media) {
       ast_verb(3, "No P-Early-Media header present, adding it...\n");
       ast_sip_add_header(packet, "P-Early-Media", "supported");
   } else {
       ast_verb(3, "P-Early-Media header already present:\n");
   }

            }
                ast_sip_session_send_response(session, packet);
        }

        ao2_ref(ind_data, -1);

        return 0;
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.