Change of CALLERID(number) have no effect on SIP INVITE after atxfer feature transfer

I want to set CALLERID(number) to number allocated from SIP trunk provider for external calls after transfer. For some reason this is not respected after attended transfer initiated by atxfer feature code.

I believe this is rather configuration issue and not a bug.

Minimum dialplan is:

CLI> dialplan show incoming
[ Context 'incoming' created by 'pbx_ael' ]
  '_x.' =>          1. Dial(PJSIP/phone,120,tT)                [pbx_ael]
                    2. Hangup()                                   [pbx_ael]

CLI> dialplan show custom-transfer
[ Context 'custom-transfer' created by 'pbx_ael' ]
  '_[+*#0-9].' =>   1. NoOp(cidn: ${CALLERID(number)})            [pbx_ael]
                    2. Set(CALLERID(number)=123456789)            [pbx_ael]
                    3. NoOp(cidn: ${CALLERID(number)})            [pbx_ael]
                    4. Dial(PJSIP/${EXTEN}@trunk,120,tT)      [pbx_ael]
                    5. Hangup()                                   [pbx_ael]

Features settings:

CLI> features show 
Builtin Feature           Default Current
---------------           ------- -------
Pickup                    *8      *88    
Blind Transfer            #       *1     
Attended Transfer                 *2     

Endpoint configuration involved in the example:

CLI> pjsip show endpoint phone

 Endpoint:  <Endpoint/CID.....................................>  <State.....>  <Channels.>
    I/OAuth:  <AuthId/UserName...........................................................>
        Aor:  <Aor............................................>  <MaxContact>
      Contact:  <Aor/ContactUri..........................> <Hash....> <Status> <RTT(ms)..>
  Transport:  <TransportId........>  <Type>  <cos>  <tos>  <BindAddress..................>
   Identify:  <Identify/Endpoint.........................................................>
        Match:  <criteria.........................>
    Channel:  <ChannelId......................................>  <State.....>  <Time.....>
        Exten: <DialedExten...........>  CLCID: <ConnectedLineCID.......>
==========================================================================================

 Endpoint:  phone/354                                         Not in use    0 of inf
    OutAuth:  phone/phone
     InAuth:  phone/phone
        Aor:  phone                                           4
      Contact:  phone/sip:phone@192.168.1.10:5060;ob de82d3dd7e Avail        20.918
  Transport:  transport-udp             udp      0    184  0.0.0.0:5060


 ParameterName                      : ParameterValue
 ===================================================================================================
 100rel                             : yes
 accept_multiple_sdp_answers        : false
 accountcode                        : 
 acl                                : 
 aggregate_mwi                      : true
 allow                              : (g722|alaw)
 allow_overlap                      : true
 allow_subscribe                    : true
 allow_transfer                     : true
 allow_unauthenticated_options      : false
 aors                               : phone
 asymmetric_rtp_codec               : false
 auth                               : phone
 bind_rtp_to_media_address          : false
 bundle                             : false
 call_group                         : 
 callerid                           : "psi" <354>
 callerid_privacy                   : allowed_not_screened
 callerid_tag                       : 
 codec_prefs_incoming_answer        : prefer:pending, operation:intersect, keep:all, transcode:allow
 codec_prefs_incoming_offer         : prefer:pending, operation:intersect, keep:all, transcode:allow
 codec_prefs_outgoing_answer        : prefer:pending, operation:intersect, keep:all, transcode:allow
 codec_prefs_outgoing_offer         : prefer:pending, operation:union, keep:all, transcode:allow
 connected_line_method              : invite
 contact_acl                        : 
 context                            : internal
 cos_audio                          : 0
 cos_video                          : 0
 device_state_busy_at               : 0
 direct_media                       : false
 direct_media_glare_mitigation      : none
 direct_media_method                : invite
 disable_direct_media_on_nat        : false
 dtls_auto_generate_cert            : No
 dtls_ca_file                       : 
 dtls_ca_path                       : 
 dtls_cert_file                     : 
 dtls_cipher                        : 
 dtls_fingerprint                   : SHA-256
 dtls_private_key                   : 
 dtls_rekey                         : 0
 dtls_setup                         : active
 dtls_verify                        : No
 dtmf_mode                          : rfc4733
 fax_detect                         : false
 fax_detect_timeout                 : 0
 follow_early_media_fork            : true
 force_avp                          : false
 force_rport                        : true
 from_domain                        : 
 from_user                          : 
 g726_non_standard                  : false
 geoloc_incoming_call_profile       : 
 geoloc_outgoing_call_profile       : 
 ice_support                        : false
 identify_by                        : username,ip
 ignore_183_without_sdp             : false
 inband_progress                    : false
 incoming_call_offer_pref           : local
 incoming_mwi_mailbox               : 
 language                           : 
 log_subscription_error             : true
 mailboxes                          : 
 max_audio_streams                  : 1
 max_video_streams                  : 1
 media_address                      : 
 media_encryption                   : no
 media_encryption_optimistic        : false
 media_use_received_transport       : false
 message_context                    : 
 moh_passthrough                    : false
 moh_suggest                        : default
 mwi_from_user                      : 
 mwi_subscribe_replaces_unsolicited : no
 named_call_group                   : 1083
 named_pickup_group                 : 1083
 notify_early_inuse_ringing         : false
 one_touch_recording                : false
 outbound_auth                      : phone
 outbound_proxy                     : 
 outgoing_call_offer_pref           : remote_merge
 overlap_context                    : 
 pickup_group                       : 
 preferred_codec_only               : false
 record_off_feature                 : automixmon
 record_on_feature                  : automixmon
 refer_blind_progress               : true
 rewrite_contact                    : false
 rpid_immediate                     : false
 rtcp_mux                           : false
 rtp_engine                         : asterisk
 rtp_ipv6                           : false
 rtp_keepalive                      : 0
 rtp_symmetric                      : false
 rtp_timeout                        : 60
 rtp_timeout_hold                   : 1800
 sdp_owner                          : -
 sdp_session                        : Asterisk
 security_mechanisms                : 
 security_negotiation               : no
 send_aoc                           : false
 send_connected_line                : yes
 send_diversion                     : true
 send_history_info                  : false
 send_pai                           : false
 send_rpid                          : true
 set_var                            : 
 srtp_tag_32                        : false
 stir_shaken                        : off
 stir_shaken_profile                : 
 sub_min_expiry                     : 0
 subscribe_context                  : subscriptions
 suppress_q850_reason_headers       : true
 t38_bind_udptl_to_media_address    : false
 t38_udptl                          : false
 t38_udptl_ec                       : none
 t38_udptl_ipv6                     : false
 t38_udptl_maxdatagram              : 0
 t38_udptl_nat                      : false
 timers                             : yes
 timers_min_se                      : 90
 timers_sess_expires                : 1800
 tone_zone                          : 
 tos_audio                          : 0
 tos_video                          : 0
 transport                          : transport-udp
 trust_connected_line               : yes
 trust_id_inbound                   : false
 trust_id_outbound                  : false
 use_avpf                           : false
 use_ptime                          : false
 user_eq_phone                      : false
 voicemail_extension                : 
 webrtc                             : no

CLI> pjsip show endpoint trunk

 Endpoint:  <Endpoint/CID.....................................>  <State.....>  <Channels.>
    I/OAuth:  <AuthId/UserName...........................................................>
        Aor:  <Aor............................................>  <MaxContact>
      Contact:  <Aor/ContactUri..........................> <Hash....> <Status> <RTT(ms)..>
  Transport:  <TransportId........>  <Type>  <cos>  <tos>  <BindAddress..................>
   Identify:  <Identify/Endpoint.........................................................>
        Match:  <criteria.........................>
    Channel:  <ChannelId......................................>  <State.....>  <Time.....>
        Exten: <DialedExten...........>  CLCID: <ConnectedLineCID.......>
==========================================================================================

 Endpoint:  trunk                                            Not in use    0 of inf
    OutAuth:  trunk-oauth/pbx
     InAuth:  trunk-iauth/trunk
        Aor:  trunk                                          1
      Contact:  trunk/sip:trunk.server.com        4de3f20c21 Avail        30.332
  Transport:  transport-tls             tls      0    184  0.0.0.0:5061
   Identify:  trunk-identify/trunk
        Match: 1.2.3.4/32


 ParameterName                      : ParameterValue
 ===================================================================================================
 100rel                             : yes
 accept_multiple_sdp_answers        : false
 accountcode                        : 
 acl                                : 
 aggregate_mwi                      : true
 allow                              : (g722|alaw)
 allow_overlap                      : true
 allow_subscribe                    : true
 allow_transfer                     : false
 allow_unauthenticated_options      : false
 aors                               : trunk
 asymmetric_rtp_codec               : false
 auth                               : trunk-iauth
 bind_rtp_to_media_address          : true
 bundle                             : false
 call_group                         : 
 callerid                           : <unknown>
 callerid_privacy                   : allowed_not_screened
 callerid_tag                       : 
 codec_prefs_incoming_answer        : prefer:pending, operation:intersect, keep:all, transcode:allow
 codec_prefs_incoming_offer         : prefer:pending, operation:intersect, keep:all, transcode:allow
 codec_prefs_outgoing_answer        : prefer:pending, operation:intersect, keep:all, transcode:allow
 codec_prefs_outgoing_offer         : prefer:pending, operation:union, keep:all, transcode:allow
 connected_line_method              : invite
 contact_acl                        : 
 context                            : incoming
 cos_audio                          : 5
 cos_video                          : 0
 device_state_busy_at               : 0
 direct_media                       : false
 direct_media_glare_mitigation      : none
 direct_media_method                : invite
 disable_direct_media_on_nat        : false
 dtls_auto_generate_cert            : No
 dtls_ca_file                       : 
 dtls_ca_path                       : 
 dtls_cert_file                     : 
 dtls_cipher                        : 
 dtls_fingerprint                   : SHA-256
 dtls_private_key                   : 
 dtls_rekey                         : 0
 dtls_setup                         : active
 dtls_verify                        : No
 dtmf_mode                          : rfc4733
 fax_detect                         : false
 fax_detect_timeout                 : 0
 follow_early_media_fork            : true
 force_avp                          : false
 force_rport                        : true
 from_domain                        : 
 from_user                          : 
 g726_non_standard                  : false
 geoloc_incoming_call_profile       : 
 geoloc_outgoing_call_profile       : 
 ice_support                        : false
 identify_by                        : auth_username,ip
 ignore_183_without_sdp             : false
 inband_progress                    : false
 incoming_call_offer_pref           : local
 incoming_mwi_mailbox               : 
 language                           : 
 log_subscription_error             : true
 mailboxes                          : 
 max_audio_streams                  : 1
 max_video_streams                  : 1
 media_address                      : 
 media_encryption                   : sdes
 media_encryption_optimistic        : false
 media_use_received_transport       : false
 message_context                    : 
 moh_passthrough                    : false
 moh_suggest                        : default
 mwi_from_user                      : 
 mwi_subscribe_replaces_unsolicited : no
 named_call_group                   : 
 named_pickup_group                 : 
 notify_early_inuse_ringing         : false
 one_touch_recording                : false
 outbound_auth                      : trunk-oauth
 outbound_proxy                     : 
 outgoing_call_offer_pref           : remote_merge
 overlap_context                    : 
 pickup_group                       : 
 preferred_codec_only               : false
 record_off_feature                 : automixmon
 record_on_feature                  : automixmon
 refer_blind_progress               : true
 rewrite_contact                    : false
 rpid_immediate                     : false
 rtcp_mux                           : false
 rtp_engine                         : asterisk
 rtp_ipv6                           : false
 rtp_keepalive                      : 10
 rtp_symmetric                      : false
 rtp_timeout                        : 60
 rtp_timeout_hold                   : 1800
 sdp_owner                          : -
 sdp_session                        : Asterisk
 security_mechanisms                : 
 security_negotiation               : no
 send_aoc                           : false
 send_connected_line                : yes
 send_diversion                     : true
 send_history_info                  : false
 send_pai                           : false
 send_rpid                          : false
 set_var                            : 
 srtp_tag_32                        : false
 stir_shaken                        : off
 stir_shaken_profile                : 
 sub_min_expiry                     : 0
 subscribe_context                  : 
 suppress_q850_reason_headers       : false
 t38_bind_udptl_to_media_address    : false
 t38_udptl                          : true
 t38_udptl_ec                       : redundancy
 t38_udptl_ipv6                     : false
 t38_udptl_maxdatagram              : 0
 t38_udptl_nat                      : false
 timers                             : yes
 timers_min_se                      : 90
 timers_sess_expires                : 1800
 tone_zone                          : 
 tos_audio                          : 184
 tos_video                          : 0
 transport                          : transport-tls
 trust_connected_line               : yes
 trust_id_inbound                   : false
 trust_id_outbound                  : false
 use_avpf                           : false
 use_ptime                          : false
 user_eq_phone                      : false
 voicemail_extension                : 
 webrtc                             : no

Test of dialplan - transfer of incoming call to EXTEN 987654321 and setting of CALLERID(number) to 123456789:

Sep  7 13:31:28 pbx asterisk[1099899]: VERBOSE[1120017][C-00000005]: pbx.c:2941 in pbx_extension_helper: Executing [123456789@incoming:1] Dial("PJSIP/trunk-0000000c", "PJSIP/phone,120,tT") in new stack
Sep  7 13:31:28 pbx asterisk[1099899]: VERBOSE[1120017][C-00000005]: app_dial.c:2914 in dial_exec_full: Called PJSIP/phone
Sep  7 13:31:28 pbx asterisk[1099899]: VERBOSE[1120017][C-00000005]: app_dial.c:1546 in wait_for_answer: PJSIP/phone-0000000d is ringing
Sep  7 13:31:30 pbx asterisk[1099899]: VERBOSE[1119830]: res_rtp_asterisk.c:8949 in ast_rtp_remote_address_set: 0x7f6fdc07a180 -- Strict RTP learning after remote address set to: 192.168.1.10:4008
Sep  7 13:31:30 pbx asterisk[1099899]: VERBOSE[1120017][C-00000005]: app_dial.c:1438 in wait_for_answer: PJSIP/phone-0000000d answered PJSIP/trunk-0000000c
Sep  7 13:31:30 pbx asterisk[1099899]: VERBOSE[1119830]: res_rtp_asterisk.c:8949 in ast_rtp_remote_address_set: 0x7f6fdc08b680 -- Strict RTP learning after remote address set to: 1.2.3.4:10794
Sep  7 13:31:30 pbx asterisk[1099899]: VERBOSE[1120025][C-00000005]: bridge_channel.c:2226 in bridge_channel_internal_push_full: Channel PJSIP/phone-0000000d joined 'simple_bridge' basic-bridge <4bbc63ef-e003-4853-ae12-c8cb382b64ed>
Sep  7 13:31:30 pbx asterisk[1099899]: VERBOSE[1120017][C-00000005]: bridge_channel.c:2226 in bridge_channel_internal_push_full: Channel PJSIP/trunk-0000000c joined 'simple_bridge' basic-bridge <4bbc63ef-e003-4853-ae12-c8cb382b64ed>
Sep  7 13:31:30 pbx asterisk[1099899]: VERBOSE[1120025][C-00000005]: res_rtp_asterisk.c:8230 in ast_rtp_read: 0x7f6fdc07a180 -- Strict RTP switching to RTP target address 192.168.1.10:4008 as source
Sep  7 13:31:31 pbx asterisk[1099899]: VERBOSE[1120017][C-00000005]: res_rtp_asterisk.c:8230 in ast_rtp_read: 0x7f6fdc08b680 -- Strict RTP switching to RTP target address 1.2.3.4:10794 as source
Sep  7 13:31:31 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '*' received on PJSIP/phone-0000000d
Sep  7 13:31:31 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4012 in __ast_read: DTMF begin passthrough '*' on PJSIP/phone-0000000d
Sep  7 13:31:31 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '*' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:31 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3938 in __ast_read: DTMF end accepted with begin '*' on PJSIP/phone-0000000d
Sep  7 13:31:31 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '*' on PJSIP/phone-0000000d
Sep  7 13:31:32 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '2' received on PJSIP/phone-0000000d
Sep  7 13:31:32 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4012 in __ast_read: DTMF begin passthrough '2' on PJSIP/phone-0000000d
Sep  7 13:31:32 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '2' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:32 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3938 in __ast_read: DTMF end accepted with begin '2' on PJSIP/phone-0000000d
Sep  7 13:31:32 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '2' on PJSIP/phone-0000000d
Sep  7 13:31:32 pbx asterisk[1099899]: VERBOSE[1120025][C-00000005]: bridge_basic.c:3344 in feature_attended_transfer: Channel PJSIP/phone-0000000d: Started DTMF attended transfer.
Sep  7 13:31:32 pbx asterisk[1099899]: VERBOSE[1120017][C-00000005]: res_musiconhold.c:246 in moh_post_start: Started music on hold, class 'default', on channel 'PJSIP/trunk-0000000c'
Sep  7 13:31:32 pbx asterisk[1099899]: VERBOSE[1120025][C-00000005]: file.c:1343 in ast_streamfile: <PJSIP/phone-0000000d> Playing 'pbx-transfer.slin16' (language 'cz')
Sep  7 13:31:34 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '7' received on PJSIP/phone-0000000d
Sep  7 13:31:34 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4005 in __ast_read: DTMF begin ignored '7' on PJSIP/phone-0000000d
Sep  7 13:31:34 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '7' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:34 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '7' on PJSIP/phone-0000000d
Sep  7 13:31:35 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '3' received on PJSIP/phone-0000000d
Sep  7 13:31:35 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4005 in __ast_read: DTMF begin ignored '3' on PJSIP/phone-0000000d
Sep  7 13:31:35 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '3' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:35 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '3' on PJSIP/phone-0000000d
Sep  7 13:31:35 pbx asterisk[1099899]: VERBOSE[1120025][C-00000005]: res_rtp_asterisk.c:8201 in ast_rtp_read: 0x7f6fdc07a180 -- Strict RTP learning complete - Locking on source address 192.168.1.10:4008
Sep  7 13:31:35 pbx asterisk[1099899]: VERBOSE[1120017][C-00000005]: res_rtp_asterisk.c:8201 in ast_rtp_read: 0x7f6fdc08b680 -- Strict RTP learning complete - Locking on source address 1.2.3.4:10794
Sep  7 13:31:35 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '7' received on PJSIP/phone-0000000d
Sep  7 13:31:35 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4005 in __ast_read: DTMF begin ignored '7' on PJSIP/phone-0000000d
Sep  7 13:31:36 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '7' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:36 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '7' on PJSIP/phone-0000000d
Sep  7 13:31:36 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '2' received on PJSIP/phone-0000000d
Sep  7 13:31:36 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4005 in __ast_read: DTMF begin ignored '2' on PJSIP/phone-0000000d
Sep  7 13:31:36 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '2' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:36 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '2' on PJSIP/phone-0000000d
Sep  7 13:31:36 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '3' received on PJSIP/phone-0000000d
Sep  7 13:31:36 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4005 in __ast_read: DTMF begin ignored '3' on PJSIP/phone-0000000d
Sep  7 13:31:36 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '3' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:36 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '3' on PJSIP/phone-0000000d
Sep  7 13:31:37 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '8' received on PJSIP/phone-0000000d
Sep  7 13:31:37 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4005 in __ast_read: DTMF begin ignored '8' on PJSIP/phone-0000000d
Sep  7 13:31:37 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '8' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:37 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '8' on PJSIP/phone-0000000d
Sep  7 13:31:37 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '3' received on PJSIP/phone-0000000d
Sep  7 13:31:37 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4005 in __ast_read: DTMF begin ignored '3' on PJSIP/phone-0000000d
Sep  7 13:31:37 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '3' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:37 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '3' on PJSIP/phone-0000000d
Sep  7 13:31:37 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '3' received on PJSIP/phone-0000000d
Sep  7 13:31:37 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4005 in __ast_read: DTMF begin ignored '3' on PJSIP/phone-0000000d
Sep  7 13:31:38 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '3' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:38 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '3' on PJSIP/phone-0000000d
Sep  7 13:31:38 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '4' received on PJSIP/phone-0000000d
Sep  7 13:31:38 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4005 in __ast_read: DTMF begin ignored '4' on PJSIP/phone-0000000d
Sep  7 13:31:38 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '4' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:38 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '4' on PJSIP/phone-0000000d
Sep  7 13:31:39 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4001 in __ast_read: DTMF begin '#' received on PJSIP/phone-0000000d
Sep  7 13:31:39 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:4005 in __ast_read: DTMF begin ignored '#' on PJSIP/phone-0000000d
Sep  7 13:31:39 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3887 in __ast_read: DTMF end '#' received on PJSIP/phone-0000000d, duration 200 ms
Sep  7 13:31:39 pbx asterisk[1099899]: DTMF[1120025][C-00000005]: channel.c:3976 in __ast_read: DTMF end passthrough '#' on PJSIP/phone-0000000d
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120026][C-00000005]: pbx.c:2941 in pbx_extension_helper: Executing [987654321@custom-transfer:1] NoOp("Local/987654321@custom-transfer-00000004;2", "cidn: 354") in new stack
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120027][C-00000005]: bridge_channel.c:2226 in bridge_channel_internal_push_full: Channel Local/987654321@custom-transfer-00000004;1 joined 'simple_bridge' basic-bridge <c629300f-8828-4236-b6af-182037cfa9e4>
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120026][C-00000005]: pbx.c:2941 in pbx_extension_helper: Executing [987654321@custom-transfer:2] Set("Local/987654321@custom-transfer-00000004;2", "CALLERID(number)=123456789") in new stack
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120026][C-00000005]: pbx.c:2941 in pbx_extension_helper: Executing [987654321@custom-transfer:3] NoOp("Local/987654321@custom-transfer-00000004;2", "cidn: 123456789") in new stack
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120026][C-00000005]: pbx.c:2941 in pbx_extension_helper: Executing [987654321@custom-transfer:4] Dial("Local/987654321@custom-transfer-00000004;2", "PJSIP/987654321@trunk,120,tT") in new stack
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120028][C-00000005]: bridge_channel.c:2124 in bridge_channel_internal_pull: Channel PJSIP/phone-0000000d left 'simple_bridge' basic-bridge <4bbc63ef-e003-4853-ae12-c8cb382b64ed>
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120028][C-00000005]: bridge_channel.c:2226 in bridge_channel_internal_push_full: Channel PJSIP/phone-0000000d joined 'simple_bridge' basic-bridge <c629300f-8828-4236-b6af-182037cfa9e4>
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120026][C-00000005]: app_dial.c:2914 in dial_exec_full: Called PJSIP/987654321@trunk
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120026][C-00000005]: app_dial.c:1913 in wait_for_answer: Local/987654321@custom-transfer-00000004;2 requested media update control 26, passing it to PJSIP/trunk-0000000e
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1119830]: netsock2.c:639 in ast_set_qos: Using SIP RTP Audio TOS bits 184
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1119830]: netsock2.c:661 in ast_set_qos: Using SIP RTP Audio CoS mark 5
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120026][C-00000005]: app_dial.c:1314 in wait_for_answer: Everyone is busy/congested at this time (1:0/0/1)
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120026][C-00000005]: pbx.c:2941 in pbx_extension_helper: Executing [987654321@custom-transfer:5] Hangup("Local/987654321@custom-transfer-00000004;2", "") in new stack
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120026][C-00000005]: pbx.c:4439 in __ast_pbx_run: Spawn extension (custom-transfer, 987654321, 5) exited non-zero on 'Local/987654321@custom-transfer-00000004;2'
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120027][C-00000005]: bridge_channel.c:2124 in bridge_channel_internal_pull: Channel Local/987654321@custom-transfer-00000004;1 left 'simple_bridge' basic-bridge <c629300f-8828-4236-b6af-182037cfa9e4>
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120028][C-00000005]: bridge_channel.c:2124 in bridge_channel_internal_pull: Channel PJSIP/phone-0000000d left 'simple_bridge' basic-bridge <c629300f-8828-4236-b6af-182037cfa9e4>
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120028][C-00000005]: bridge_channel.c:2226 in bridge_channel_internal_push_full: Channel PJSIP/phone-0000000d joined 'simple_bridge' basic-bridge <4bbc63ef-e003-4853-ae12-c8cb382b64ed>
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120028][C-00000005]: res_musiconhold.c:270 in moh_post_stop: Stopped music on hold on PJSIP/trunk-0000000c
Sep  7 13:31:39 pbx asterisk[1099899]: VERBOSE[1120025][C-00000005]: file.c:1343 in ast_streamfile: <PJSIP/phone-0000000d> Playing 'beeperr.slin16' (language 'cz')

Resulting SIP INVITE:

INVITE sip:987654321@trunk.server.com SIP/2.0
Via: SIP/2.0/TLS 192.168.10.10:5061;rport;branch=z9hG4bKPja04ec818-85bc-4df6-9944-2a5d21146a94;alias
From: "psi" <sip:354@192.168.10.10>;tag=488dd8fe-1999-4e06-9ac7-ae15aece4fc5
To: <sip:987654321@trunk.server.com>
Contact: <sip:asterisk@192.168.10.10:5061;transport=TLS>
Call-ID: c6f47d6f-27a2-4c37-a0c5-347a1c6130de
CSeq: 18276 INVITE
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub, histinfo
Session-Expires: 1800
Min-SE: 90
Max-Forwards: 70
User-Agent: Asterisk PBX 18.18.1
Content-Type: application/sdp
Content-Length:   342

So setting of CALLERID(number) have no effect on From header. It remains set 354 instead of 123456789.

Can someone point me out what’s missing in my configuration?

I’ve had no luck changing the caller ID prior to calling Dial(), you need to make the change on the outgoing channel, before the invite is sent out. You can do that using the b option to the dial application.

You simply make a context like this:

[set-callerid]
exten => s,1,Set(CALLERID(number)=123456789)
 same => n,Return()

I’m not sure return is even required, but I’ve added it for good measure.

Using the b option for the Dial() application, use run this dialplan after Asterisk created the outgoing channel, but before generating the outbound INVITE, allowing you to modify the headers like the caller ID, or other headers you might require.

Your transfer context would then look like this

[custom-transfer]
exten => _[+*#0-9],1,NoOp(cidn: ${CALLERID(number)})
 same => n,Set(CALLERID(number)=123456789)
 same => n,NoOp(cidn: ${CALLERID(number)})
 same => n,Dial(PJSIP/${EXTEN}@trunk,120,tTb(set-callerid^s^1))
 same => n,Hangup()

I did notice you’re using AEL, I don’t and will leave it up to you, to convert the above into AEL.

Thank you for this hint. I did suggested change but it did not affect number in From header of SIP INVITE:

Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121453][C-0000000b]: pbx.c:2941 in pbx_extension_helper: Executing [987654321@custom-transfer:4] Dial("Local/987654321@custom-transfer-00000009;2", "PJSIP/987654321@trunk,120,tTb(SetCID^~~s~~^1(123456789))") in new stack
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121454][C-0000000b]: bridge_channel.c:2226 in bridge_channel_internal_push_full: Channel Local/987654321@custom-transfer-00000009;1 joined 'simple_bridge' basic-bridge <45a9c862-4abd-4fb8-b151-7170fd5c1bba>
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121455][C-0000000b]: bridge_channel.c:2124 in bridge_channel_internal_pull: Channel PJSIP/phone-0000001e left 'simple_bridge' basic-bridge <40499b46-6a7a-4291-a0d6-b6cd964ad019>
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121455][C-0000000b]: bridge_channel.c:2226 in bridge_channel_internal_push_full: Channel PJSIP/phone-0000001e joined 'simple_bridge' basic-bridge <45a9c862-4abd-4fb8-b151-7170fd5c1bba>
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121453][C-0000000b]: app_stack.c:1009 in gosub_run: PJSIP/trunk-0000001f Internal Gosub(SetCID,~~s~~,1(123456789)) start
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121453][C-0000000b]: pbx.c:2941 in pbx_extension_helper: Executing [~~s~~@SetCID:1] MSet("PJSIP/trunk-0000001f", "LOCAL(cid)=123456789") in new stack
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121453][C-0000000b]: pbx.c:2941 in pbx_extension_helper: Executing [~~s~~@SetCID:2] Set("PJSIP/trunk-0000001f", "CALLERID(number)=123456789") in new stack
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121453][C-0000000b]: pbx.c:2941 in pbx_extension_helper: Executing [~~s~~@SetCID:3] Return("PJSIP/trunk-0000001f", "") in new stack
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121453][C-0000000b]: app_stack.c:1095 in gosub_run: Spawn extension (SetCID, ~~s~~, 3) exited non-zero on 'PJSIP/trunk-0000001f'
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121453][C-0000000b]: app_stack.c:1107 in gosub_run: PJSIP/trunk-0000001f Internal Gosub(SetCID,~~s~~,1(123456789)) complete GOSUB_RETVAL=
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121453][C-0000000b]: app_dial.c:2914 in dial_exec_full: Called PJSIP/987654321@trunk
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121453][C-0000000b]: app_dial.c:1913 in wait_for_answer: Local/987654321@custom-transfer-00000009;2 requested media update control 26, passing it to PJSIP/trunk-0000001f
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1119830]: netsock2.c:639 in ast_set_qos: Using SIP RTP Audio TOS bits 184
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1119830]: netsock2.c:661 in ast_set_qos: Using SIP RTP Audio CoS mark 5
Sep  7 16:45:39 pbx asterisk[1099899]: VERBOSE[1121447]: res_pjsip_logger.c:322 in logging_on_tx_msg: <--- Transmitting SIP request (1045 bytes) to TLS:192.168.1.2:5061 --->
INVITE sip:987654321@trunk.server.com SIP/2.0
Via: SIP/2.0/TLS 192.168.10.10:5061;rport;branch=z9hG4bKPj0a723618-3bc4-4853-ae98-e484895614ed;alias
From: "psi" <sip:354@192.168.10.10>;tag=787e3bc4-fbe6-473b-aefd-1a9a92eb89ca
To: <sip:987654321@trunk.server.com>
Contact: <sip:asterisk@192.168.10.10:5061;transport=TLS>
Call-ID: 4c7809a8-5531-45cf-867b-5b8298a694ff
CSeq: 10014 INVITE
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub, histinfo
Session-Expires: 1800
Min-SE: 90
Max-Forwards: 70
User-Agent: Asterisk PBX 18.18.1
Content-Type: application/sdp
Content-Length:   342

I tried to add DumpChan app into predial handler. CALLERID(number) and CONNECTEDLINE(num) is reversed (this makes sense because this is called channel):

Dumping Info For Channel: PJSIP/trunk-00000025:
================================================================================
Info:
Name=               PJSIP/trunk-00000025
Type=               PJSIP
UniqueID=           1694098704.452
LinkedID=           1694098696.435
CallerIDNum=        987654321
CallerIDName=       (N/A)
ConnectedLineIDNum= 354
ConnectedLineIDName=psi
DNIDDigits=         (N/A)
RDNIS=              (N/A)
Parkinglot=         
Language=           cz
State=              Down (0)
Rings=              0
NativeFormat=       (g722|alaw)
WriteFormat=        g722
ReadFormat=         g722
RawWriteFormat=     g722
RawReadFormat=      g722
WriteTranscode=     No 
ReadTranscode=      No 
1stFileDescriptor=  -1
Framesin=           0 
Framesout=          0 
TimetoHangup=       0
ElapsedTime=        0h0m0s
BridgeID=           (Not bridged)
Context=            SetCID
Extension=          ~~s~~
Priority=           2
CallGroup=          
PickupGroup=        
Application=        DumpChan
Data=               (Empty)
Blocking_in=        (Not Blocking)

Variables:
cid=123456789
ARGC=1
ARG1=123456789
DIALEDPEERNUMBER=987654321@trunk
================================================================================

So I tried to set CONNECTEDLINE(num) in predial handler (instead of CALLERID(number)). From number in SIP INVITE is still unchanged.

Any other ideas how to alter From number in SIP INVITE for this call scenario?

When I try to use older chan_sip instead of PJSIP, setting of CALLERID prior to Dial works. So even predial handler is not necessary. What can cause that it is not working for PJSIP endpoint (and only for this feature attended transfer scenario)?

chan_pjsip and chan_sip are two different modules with different internals. They work differently.

In my case I set both CALLERID(num) and CALLERID(name) to be the number, when making external calls. This seems to work for me.

But I just checked my dialplan, and it seems like I just set them prior to running the Dial() application, not in an handler, the handler sets some SIP headers, but not the caller ID.

If you always need to send the SAME number as outbound caller ID you can configure it in the PJSIP endpoint instead, that should override whatever is set on the channel.

Based on my experiences…the FROM sip header is not modified by the CallerID field. I have seen things that mention this but I believe the information is no longer valid. For example…when I make a call out on my SIP trunk my Asterisk sends my userID@serverIP to my provider.

CallerID is somewhere in the header; but it’s not in the from field. I’ve had softphones like MicroSIP completely over-ride any callerID setting in my dialplan.

I would verify the callerID isn’t being passed rather than relying on looking at the SIP headers. I can tell you for sure my caller ID works on my outbound and my sip headers do not show anything that looks like my phone number.

SIP is less a standard and more a state of mind. :scream:

Caller ID could be pulled by your telco from any of these SIP headers, depending on their switch, although this is a fairly sane priority order of preference in case you decide to try/set them all and walk away (not recommended):

  1. P-Asserted-Identity (newer)
  2. From (could be buggy, see below)
  3. Remote-Party-ID (older)

With some providers, if you set “From” to something besides your account number, then the call might get blocked; in that case, try “P-Asserted-Identity”, in the dialplan Gosub()'d to by way of the b() option to Dial(). Another caveat is that other parts of your configuration can have an impact, best to run full SIP debug and please post back what works for you.

from_user takes precedence over caller ID, for the From header, but, if you don’t set from_user, you should see the caller ID. The OP seems to be claiming that the From user being sent is that from the original incoming call, but that can only be the case if it was the value of the CALLERID(num), and that could only happen if that gets overwritten after it is explicitly set

In my first post I list the configuration of the both participating endpoints. from_user is empty.

A direct call without atxfer works fine and the CALLERID(number) setting is respected in From header of SIP INVITE. I tried to set context option of phone endpoint to ‘custom-transfer’ and dialer the same number used to test of atxfer. CID is set correctly:

    -- Executing [987654321@custom-transfer:1] NoOp("PJSIP/phone-00000002", "cidn: 354") in new stack
    -- Executing [987654321@custom-transfer:2] Set("PJSIP/phone-00000002", "CALLERID(number)=123456789") in new stack
    -- Executing [987654321@custom-transfer:3] NoOp("PJSIP/phone-00000002", "cidn: 123456789") in new stack
    -- Executing [987654321@custom-transfer:4] Dial("PJSIP/phone-00000002", "PJSIP/987654321@trunk,120,tT") in new stack
    -- Called PJSIP/987654321@trunk
  == Using SIP RTP Audio TOS bits 184
  == Using SIP RTP Audio CoS mark 5
<--- Transmitting SIP request (1135 bytes) to TLS:192.168.1.2:5061 --->
INVITE sip:987654321@trunk.server.com SIP/2.0
Via: SIP/2.0/TLS 192.168.10.10:5061;rport;branch=z9hG4bKPja6e93612-4e77-4d6b-899c-3eab7d1fc6fa;alias
From: "psi" <sip:123456789@192.168.10.10>;tag=85860ab7-749b-4c97-824d-57f4dfef7fff
To: <sip:987654321@trunk.server.com>
Contact: <sip:asterisk@192.168.10.10:5061;transport=TLS>

For atxfer initiated using feature code, CALLERID(number) is from callerid setting of ‘phone’ endpoint and cannot be changed. Settings of this endpoint is listed in my first post.

If this is a bug in Asterisk, for a function as common as atxfer via feature code, this forum would be full of users lamenting. That’s why I still believe it’s a configuration issue.

It might not be that common any more. Most phones connected to Asterisk are probably SIP-based and most of those have a Transfer button that does not rely on DTMF signaling but instead uses separate SIP signaling eg. INVITE message.

This could be an issue of Local channel (sub)optimization. You might try adding a /n at the end of the dial part to keep the magic happening eg. Dial(Local/987654321@custom-transfer/n). Or in your predial handler try some variable inheritance eg. Set(_CALLERID(num)=555).

I’m aware that atxfer feature code routes call to Local channel. But as far as in know this is done outside of dialplan control. Call of Local/XXX@custom-transfer is based only on setting of TRANSFER_CONTEXT variable to ‘custom-transfer’ this is my target context for this use case. There is no way how to alter Dial of target after this type of transfer.

Maybe sandwich in another Local channel activation ? Eg. change TRANSFER_CONTEXT to a new ‘custom-transfer-wrapper’ and inside of that context add a one-line Dial(Local/123@custom-transfer/n) ?

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