Asterisk - The Open Source Telephony Project  GIT-master-4a4f1a5
chan_pjsip.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2013, Digium, Inc.
5  *
6  * Joshua Colp <jcolp@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \author Joshua Colp <jcolp@digium.com>
22  *
23  * \brief PSJIP SIP Channel Driver
24  *
25  * \ingroup channel_drivers
26  */
27 
28 /*** MODULEINFO
29  <depend>pjproject</depend>
30  <depend>res_pjsip</depend>
31  <depend>res_pjsip_pubsub</depend>
32  <depend>res_pjsip_session</depend>
33  <support_level>core</support_level>
34  ***/
35 
36 #include "asterisk.h"
37 
38 #include <pjsip.h>
39 #include <pjsip_ua.h>
40 #include <pjlib.h>
41 
42 #include "asterisk/lock.h"
43 #include "asterisk/channel.h"
44 #include "asterisk/module.h"
45 #include "asterisk/pbx.h"
46 #include "asterisk/rtp_engine.h"
47 #include "asterisk/acl.h"
48 #include "asterisk/callerid.h"
49 #include "asterisk/file.h"
50 #include "asterisk/cli.h"
51 #include "asterisk/app.h"
52 #include "asterisk/musiconhold.h"
53 #include "asterisk/causes.h"
54 #include "asterisk/taskprocessor.h"
55 #include "asterisk/dsp.h"
58 #include "asterisk/indications.h"
59 #include "asterisk/format_cache.h"
60 #include "asterisk/translate.h"
61 #include "asterisk/threadstorage.h"
63 #include "asterisk/pickup.h"
64 #include "asterisk/test.h"
65 #include "asterisk/message.h"
66 
67 #include "asterisk/res_pjsip.h"
69 #include "asterisk/stream.h"
70 
74 
76 #define UNIQUEID_BUFSIZE 256
77 
78 static const char channel_type[] = "PJSIP";
79 
80 static unsigned int chan_idx;
81 
82 static void chan_pjsip_pvt_dtor(void *obj)
83 {
84 }
85 
86 /*! \brief Asterisk core interaction functions */
87 static struct ast_channel *chan_pjsip_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause);
89  struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids,
90  const struct ast_channel *requestor, const char *data, int *cause);
91 static int chan_pjsip_sendtext_data(struct ast_channel *ast, struct ast_msg_data *msg);
92 static int chan_pjsip_sendtext(struct ast_channel *ast, const char *text);
93 static int chan_pjsip_digit_begin(struct ast_channel *ast, char digit);
94 static int chan_pjsip_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
95 static int chan_pjsip_call(struct ast_channel *ast, const char *dest, int timeout);
96 static int chan_pjsip_hangup(struct ast_channel *ast);
97 static int chan_pjsip_answer(struct ast_channel *ast);
98 static struct ast_frame *chan_pjsip_read_stream(struct ast_channel *ast);
99 static int chan_pjsip_write(struct ast_channel *ast, struct ast_frame *f);
100 static int chan_pjsip_write_stream(struct ast_channel *ast, int stream_num, struct ast_frame *f);
101 static int chan_pjsip_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
102 static int chan_pjsip_transfer(struct ast_channel *ast, const char *target);
103 static int chan_pjsip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
104 static int chan_pjsip_devicestate(const char *data);
105 static int chan_pjsip_queryoption(struct ast_channel *ast, int option, void *data, int *datalen);
106 static const char *chan_pjsip_get_uniqueid(struct ast_channel *ast);
107 
108 /*! \brief PBX interface structure for channel registration */
110  .type = channel_type,
111  .description = "PJSIP Channel Driver",
112  .requester = chan_pjsip_request,
113  .requester_with_stream_topology = chan_pjsip_request_with_stream_topology,
114  .send_text = chan_pjsip_sendtext,
115  .send_text_data = chan_pjsip_sendtext_data,
116  .send_digit_begin = chan_pjsip_digit_begin,
117  .send_digit_end = chan_pjsip_digit_end,
118  .call = chan_pjsip_call,
119  .hangup = chan_pjsip_hangup,
120  .answer = chan_pjsip_answer,
121  .read_stream = chan_pjsip_read_stream,
122  .write = chan_pjsip_write,
123  .write_stream = chan_pjsip_write_stream,
124  .exception = chan_pjsip_read_stream,
125  .indicate = chan_pjsip_indicate,
126  .transfer = chan_pjsip_transfer,
127  .fixup = chan_pjsip_fixup,
128  .devicestate = chan_pjsip_devicestate,
129  .queryoption = chan_pjsip_queryoption,
130  .func_channel_read = pjsip_acf_channel_read,
131  .get_pvt_uniqueid = chan_pjsip_get_uniqueid,
133 };
134 
135 /*! \brief SIP session interaction functions */
137 static void chan_pjsip_session_end(struct ast_sip_session *session);
138 static int chan_pjsip_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata);
139 static void chan_pjsip_incoming_response(struct ast_sip_session *session, struct pjsip_rx_data *rdata);
140 static void chan_pjsip_incoming_response_update_cause(struct ast_sip_session *session, struct pjsip_rx_data *rdata);
141 
142 /*! \brief SIP session supplement structure */
144  .method = "INVITE",
146  .session_begin = chan_pjsip_session_begin,
147  .session_end = chan_pjsip_session_end,
148  .incoming_request = chan_pjsip_incoming_request,
149  .incoming_response = chan_pjsip_incoming_response,
150  /* It is important that this supplement runs after media has been negotiated */
151  .response_priority = AST_SIP_SESSION_AFTER_MEDIA,
152 };
153 
154 /*! \brief SIP session supplement structure just for responses */
156  .method = "INVITE",
158  .incoming_response = chan_pjsip_incoming_response_update_cause,
160 };
161 
162 static int chan_pjsip_incoming_ack(struct ast_sip_session *session, struct pjsip_rx_data *rdata);
163 
165  .method = "ACK",
167  .incoming_request = chan_pjsip_incoming_ack,
168 };
169 
170 /*! \brief Function called by RTP engine to get local audio RTP peer */
171 static enum ast_rtp_glue_result chan_pjsip_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
172 {
173  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);
174  struct ast_sip_endpoint *endpoint;
175  struct ast_datastore *datastore;
176  struct ast_sip_session_media *media;
177 
178  if (!channel || !channel->session) {
180  }
181 
182  /* XXX Getting the first RTP instance for direct media related stuff seems just
183  * absolutely wrong. But the native RTP bridge knows no other method than single-stream
184  * for direct media. So this is the best we can do.
185  */
187  if (!media || !media->rtp) {
189  }
190 
191  datastore = ast_sip_session_get_datastore(channel->session, "t38");
192  if (datastore) {
193  ao2_ref(datastore, -1);
195  }
196 
197  endpoint = channel->session->endpoint;
198 
199  *instance = media->rtp;
200  ao2_ref(*instance, +1);
201 
202  ast_assert(endpoint != NULL);
203  if (endpoint->media.rtp.encryption != AST_SIP_MEDIA_ENCRYPT_NONE) {
205  }
206 
207  if (endpoint->media.direct_media.enabled) {
209  }
210 
212 }
213 
214 /*! \brief Function called by RTP engine to get local video RTP peer */
215 static enum ast_rtp_glue_result chan_pjsip_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
216 {
217  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);
218  struct ast_sip_endpoint *endpoint;
219  struct ast_sip_session_media *media;
220 
221  if (!channel || !channel->session) {
223  }
224 
226  if (!media || !media->rtp) {
228  }
229 
230  endpoint = channel->session->endpoint;
231 
232  *instance = media->rtp;
233  ao2_ref(*instance, +1);
234 
235  ast_assert(endpoint != NULL);
236  if (endpoint->media.rtp.encryption != AST_SIP_MEDIA_ENCRYPT_NONE) {
238  }
239 
241 }
242 
243 /*! \brief Function called by RTP engine to get peer capabilities */
244 static void chan_pjsip_get_codec(struct ast_channel *chan, struct ast_format_cap *result)
245 {
246  SCOPE_ENTER(1, "%s Native formats %s\n", ast_channel_name(chan),
249  SCOPE_EXIT_RTN();
250 }
251 
252 /*! \brief Destructor function for \ref transport_info_data */
253 static void transport_info_destroy(void *obj)
254 {
255  struct transport_info_data *data = obj;
256  ast_free(data);
257 }
258 
259 /*! \brief Datastore used to store local/remote addresses for the
260  * INVITE request that created the PJSIP channel */
261 static struct ast_datastore_info transport_info = {
262  .type = "chan_pjsip_transport_info",
263  .destroy = transport_info_destroy,
264 };
265 
267 
269 {
270  RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
271 
272  if (session->endpoint->media.direct_media.glare_mitigation ==
274  return 0;
275  }
276 
277  datastore = ast_sip_session_get_datastore(session, "direct_media_glare_mitigation");
278  if (!datastore) {
279  return 0;
280  }
281 
282  /* Removing the datastore ensures we won't try to mitigate glare on subsequent reinvites */
283  ast_sip_session_remove_datastore(session, "direct_media_glare_mitigation");
284 
285  if ((session->endpoint->media.direct_media.glare_mitigation ==
287  session->inv_session->role == PJSIP_ROLE_UAC) ||
288  (session->endpoint->media.direct_media.glare_mitigation ==
290  session->inv_session->role == PJSIP_ROLE_UAS)) {
291  return 1;
292  }
293 
294  return 0;
295 }
296 
297 /*! \brief Helper function to find the position for RTCP */
299 {
300  int index;
301 
302  for (index = 0; index < AST_VECTOR_SIZE(&session->active_media_state->read_callbacks); ++index) {
303  struct ast_sip_session_media_read_callback_state *callback_state =
304  AST_VECTOR_GET_ADDR(&session->active_media_state->read_callbacks, index);
305 
306  if (callback_state->fd != ast_rtp_instance_fd(rtp, 1)) {
307  continue;
308  }
309 
310  return index;
311  }
312 
313  return -1;
314 }
315 
316 /*!
317  * \pre chan is locked
318  */
319 static int check_for_rtp_changes(struct ast_channel *chan, struct ast_rtp_instance *rtp,
320  struct ast_sip_session_media *media, struct ast_sip_session *session)
321 {
322  int changed = 0, position = -1;
323 
324  if (media->rtp) {
325  position = rtp_find_rtcp_fd_position(session, media->rtp);
326  }
327 
328  if (rtp) {
330  if (media->rtp) {
331  if (position != -1) {
332  ast_channel_set_fd(chan, position + AST_EXTENDED_FDS, -1);
333  }
335  }
336  } else if (!ast_sockaddr_isnull(&media->direct_media_addr)){
338  changed = 1;
339  if (media->rtp) {
340  /* Direct media has ended - reset time of last received RTP packet
341  * to avoid premature RTP timeout. Synchronisation between the
342  * modification of direct_mdedia_addr+last_rx here and reading the
343  * values in res_pjsip_sdp_rtp.c:rtp_check_timeout() is provided
344  * by the channel's lock (which is held while this function is
345  * executed).
346  */
347  ast_rtp_instance_set_last_rx(media->rtp, time(NULL));
349  if (position != -1) {
350  ast_channel_set_fd(chan, position + AST_EXTENDED_FDS, ast_rtp_instance_fd(media->rtp, 1));
351  }
352  }
353  }
354 
355  return changed;
356 }
357 
359  struct ast_channel *chan;
364 };
365 
366 static void rtp_direct_media_data_destroy(void *data)
367 {
368  struct rtp_direct_media_data *cdata = data;
369 
370  ao2_cleanup(cdata->session);
371  ao2_cleanup(cdata->cap);
372  ao2_cleanup(cdata->vrtp);
373  ao2_cleanup(cdata->rtp);
374  ao2_cleanup(cdata->chan);
375 }
376 
378  struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp,
379  const struct ast_format_cap *cap, struct ast_sip_session *session)
380 {
382 
383  if (!cdata) {
384  return NULL;
385  }
386 
387  cdata->chan = ao2_bump(chan);
388  cdata->rtp = ao2_bump(rtp);
389  cdata->vrtp = ao2_bump(vrtp);
390  cdata->cap = ao2_bump((struct ast_format_cap *)cap);
391  cdata->session = ao2_bump(session);
392 
393  return cdata;
394 }
395 
396 static int send_direct_media_request(void *data)
397 {
398  struct rtp_direct_media_data *cdata = data;
399  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(cdata->chan);
400  struct ast_sip_session *session;
401  int changed = 0;
402  int res = 0;
403 
404  /* XXX In an ideal world each media stream would be direct, but for now preserve behavior
405  * and connect only the default media sessions for audio and video.
406  */
407 
408  /* The channel needs to be locked when checking for RTP changes.
409  * Otherwise, we could end up destroying an underlying RTCP structure
410  * at the same time that the channel thread is attempting to read RTCP
411  */
412  ast_channel_lock(cdata->chan);
413  session = channel->session;
414  if (session->active_media_state->default_session[AST_MEDIA_TYPE_AUDIO]) {
415  changed |= check_for_rtp_changes(
416  cdata->chan, cdata->rtp, session->active_media_state->default_session[AST_MEDIA_TYPE_AUDIO], session);
417  }
418  if (session->active_media_state->default_session[AST_MEDIA_TYPE_VIDEO]) {
419  changed |= check_for_rtp_changes(
420  cdata->chan, cdata->vrtp, session->active_media_state->default_session[AST_MEDIA_TYPE_VIDEO], session);
421  }
422  ast_channel_unlock(cdata->chan);
423 
424  if (direct_media_mitigate_glare(cdata->session)) {
425  ast_debug(4, "Disregarding setting RTP on %s: mitigating re-INVITE glare\n", ast_channel_name(cdata->chan));
426  ao2_ref(cdata, -1);
427  return 0;
428  }
429 
430  if (cdata->cap && ast_format_cap_count(cdata->cap) &&
431  !ast_format_cap_identical(cdata->session->direct_media_cap, cdata->cap)) {
432  ast_format_cap_remove_by_type(cdata->session->direct_media_cap, AST_MEDIA_TYPE_UNKNOWN);
433  ast_format_cap_append_from_cap(cdata->session->direct_media_cap, cdata->cap, AST_MEDIA_TYPE_UNKNOWN);
434  changed = 1;
435  }
436 
437  if (changed) {
438  ast_debug(4, "RTP changed on %s; initiating direct media update\n", ast_channel_name(cdata->chan));
439  res = ast_sip_session_refresh(cdata->session, NULL, NULL, NULL,
440  cdata->session->endpoint->media.direct_media.method, 1, NULL);
441  }
442 
443  ao2_ref(cdata, -1);
444  return res;
445 }
446 
447 /*! \brief Function called by RTP engine to change where the remote party should send media */
448 static int chan_pjsip_set_rtp_peer(struct ast_channel *chan,
449  struct ast_rtp_instance *rtp,
450  struct ast_rtp_instance *vrtp,
451  struct ast_rtp_instance *tpeer,
452  const struct ast_format_cap *cap,
453  int nat_active)
454 {
455  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);
456  struct ast_sip_session *session = channel->session;
458  SCOPE_ENTER(1, "%s %s\n", ast_channel_name(chan),
460 
461  /* Don't try to do any direct media shenanigans on early bridges */
462  if ((rtp || vrtp || tpeer) && !ast_channel_is_bridged(chan)) {
463  ast_debug(4, "Disregarding setting RTP on %s: channel is not bridged\n", ast_channel_name(chan));
464  SCOPE_EXIT_RTN_VALUE(0, "Channel not bridged\n");
465  }
466 
467  if (nat_active && session->endpoint->media.direct_media.disable_on_nat) {
468  ast_debug(4, "Disregarding setting RTP on %s: NAT is active\n", ast_channel_name(chan));
469  SCOPE_EXIT_RTN_VALUE(0, "NAT is active\n");
470  }
471 
473  if (!cdata) {
475  }
476 
478  ast_log(LOG_ERROR, "Unable to send direct media request for channel %s\n", ast_channel_name(chan));
479  ao2_ref(cdata, -1);
480  }
481 
483 }
484 
485 /*! \brief Local glue for interacting with the RTP engine core */
486 static struct ast_rtp_glue chan_pjsip_rtp_glue = {
487  .type = "PJSIP",
488  .get_rtp_info = chan_pjsip_get_rtp_peer,
489  .get_vrtp_info = chan_pjsip_get_vrtp_peer,
490  .get_codec = chan_pjsip_get_codec,
491  .update_peer = chan_pjsip_set_rtp_peer,
492 };
493 
495  const char *channel_id)
496 {
497  int i;
498 
499  for (i = 0; i < AST_VECTOR_SIZE(&session->active_media_state->sessions); ++i) {
500  struct ast_sip_session_media *session_media;
501 
502  session_media = AST_VECTOR_GET(&session->active_media_state->sessions, i);
503  if (!session_media || !session_media->rtp) {
504  continue;
505  }
506 
507  ast_rtp_instance_set_channel_id(session_media->rtp, channel_id);
508  }
509 }
510 
511 /*!
512  * \brief Determine if a topology is compatible with format capabilities
513  *
514  * This will return true if ANY formats in the topology are compatible with the format
515  * capabilities.
516  *
517  * XXX When supporting true multistream, we will need to be sure to mark which streams from
518  * top1 are compatible with which streams from top2. Then the ones that are not compatible
519  * will need to be marked as "removed" so that they are negotiated as expected.
520  *
521  * \param top Topology
522  * \param cap Format capabilities
523  * \retval 1 The topology has at least one compatible format
524  * \retval 0 The topology has no compatible formats or an error occurred.
525  */
526 static int compatible_formats_exist(struct ast_stream_topology *top, struct ast_format_cap *cap)
527 {
528  struct ast_format_cap *cap_from_top;
529  int res;
530  SCOPE_ENTER(1, "Topology: %s Formats: %s\n",
533 
534  cap_from_top = ast_stream_topology_get_formats(top);
535 
536  if (!cap_from_top) {
537  SCOPE_EXIT_RTN_VALUE(0, "Topology had no formats\n");
538  }
539 
540  res = ast_format_cap_iscompatible(cap_from_top, cap);
541  ao2_ref(cap_from_top, -1);
542 
543  SCOPE_EXIT_RTN_VALUE(res, "Compatible? %s\n", res ? "yes" : "no");
544 }
545 
546 /*! \brief Function called to create a new PJSIP Asterisk channel */
547 static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int state, const char *exten, const char *title, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *cid_name)
548 {
549  struct ast_channel *chan;
550  struct ast_format_cap *caps;
551  RAII_VAR(struct chan_pjsip_pvt *, pvt, NULL, ao2_cleanup);
552  struct ast_sip_channel_pvt *channel;
553  struct ast_variable *var;
554  struct ast_stream_topology *topology;
556 
557  if (!(pvt = ao2_alloc_options(sizeof(*pvt), chan_pjsip_pvt_dtor, AO2_ALLOC_OPT_LOCK_NOLOCK))) {
558  SCOPE_EXIT_RTN_VALUE(NULL, "Couldn't create pvt\n");
559  }
560 
562  S_COR(session->id.number.valid, session->id.number.str, ""),
563  S_COR(session->id.name.valid, session->id.name.str, ""),
564  session->endpoint->accountcode,
565  exten, session->endpoint->context,
566  assignedids, requestor, 0,
567  session->endpoint->persistent, "PJSIP/%s-%08x",
569  (unsigned) ast_atomic_fetchadd_int((int *) &chan_idx, +1));
570  if (!chan) {
571  SCOPE_EXIT_RTN_VALUE(NULL, "Couldn't create channel\n");
572  }
573 
575 
576  if (!(channel = ast_sip_channel_pvt_alloc(pvt, session))) {
577  ast_channel_unlock(chan);
578  ast_hangup(chan);
579  SCOPE_EXIT_RTN_VALUE(NULL, "Couldn't create pvt channel\n");
580  }
581 
582  ast_channel_tech_pvt_set(chan, channel);
583 
584  if (!ast_stream_topology_get_count(session->pending_media_state->topology) ||
585  !compatible_formats_exist(session->pending_media_state->topology, session->endpoint->media.codecs)) {
587  if (!caps) {
588  ast_channel_unlock(chan);
589  ast_hangup(chan);
590  SCOPE_EXIT_RTN_VALUE(NULL, "Couldn't create caps\n");
591  }
592  ast_format_cap_append_from_cap(caps, session->endpoint->media.codecs, AST_MEDIA_TYPE_UNKNOWN);
593  topology = ast_stream_topology_clone(session->endpoint->media.topology);
594  } else {
595  caps = ast_stream_topology_get_formats(session->pending_media_state->topology);
596  topology = ast_stream_topology_clone(session->pending_media_state->topology);
597  }
598 
599  if (!topology || !caps) {
600  ao2_cleanup(caps);
601  ast_stream_topology_free(topology);
602  ast_channel_unlock(chan);
603  ast_hangup(chan);
604  SCOPE_EXIT_RTN_VALUE(NULL, "Couldn't get caps or clone topology\n");
605  }
606 
608 
609  ast_channel_nativeformats_set(chan, caps);
610  ast_channel_set_stream_topology(chan, topology);
611 
612  if (!ast_format_cap_empty(caps)) {
613  struct ast_format *fmt;
614 
616  if (!fmt) {
617  /* Since our capabilities aren't empty, this will succeed */
618  fmt = ast_format_cap_get_format(caps, 0);
619  }
620  ast_channel_set_writeformat(chan, fmt);
622  ast_channel_set_readformat(chan, fmt);
624  ao2_ref(fmt, -1);
625  }
626 
627  ao2_ref(caps, -1);
628 
629  if (state == AST_STATE_RING) {
630  ast_channel_rings_set(chan, 1);
631  }
632 
634 
635  ast_party_id_copy(&ast_channel_caller(chan)->id, &session->id);
636  ast_party_id_copy(&ast_channel_caller(chan)->ani, &session->id);
637  ast_channel_caller(chan)->ani2 = session->ani2;
638 
639  if (!ast_strlen_zero(exten)) {
640  /* Set provided DNID on the new channel. */
642  }
643 
644  ast_channel_priority_set(chan, 1);
645 
646  ast_channel_callgroup_set(chan, session->endpoint->pickup.callgroup);
647  ast_channel_pickupgroup_set(chan, session->endpoint->pickup.pickupgroup);
648 
649  ast_channel_named_callgroups_set(chan, session->endpoint->pickup.named_callgroups);
650  ast_channel_named_pickupgroups_set(chan, session->endpoint->pickup.named_pickupgroups);
651 
652  if (!ast_strlen_zero(session->endpoint->language)) {
653  ast_channel_language_set(chan, session->endpoint->language);
654  }
655 
656  if (!ast_strlen_zero(session->endpoint->zone)) {
657  struct ast_tone_zone *zone = ast_get_indication_zone(session->endpoint->zone);
658  if (!zone) {
659  ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", session->endpoint->zone);
660  }
661  ast_channel_zone_set(chan, zone);
662  }
663 
664  for (var = session->endpoint->channel_vars; var; var = var->next) {
665  char buf[512];
667  var->value, buf, sizeof(buf)));
668  }
669 
671  ast_channel_unlock(chan);
672 
674 
675  SCOPE_EXIT_RTN_VALUE(chan);
676 }
677 
678 struct answer_data {
680  unsigned long indent;
681 };
682 
683 static int answer(void *data)
684 {
685  struct answer_data *ans_data = data;
686  pj_status_t status = PJ_SUCCESS;
687  pjsip_tx_data *packet = NULL;
688  struct ast_sip_session *session = ans_data->session;
690 
691  if (session->inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
692  ast_log(LOG_ERROR, "Session already DISCONNECTED [reason=%d (%s)]\n",
693  session->inv_session->cause,
694  pjsip_get_status_text(session->inv_session->cause)->ptr);
695  SCOPE_EXIT_RTN_VALUE(0, "Disconnected\n");
696  }
697 
698  pjsip_dlg_inc_lock(session->inv_session->dlg);
699  if (session->inv_session->invite_tsx) {
700  status = pjsip_inv_answer(session->inv_session, 200, NULL, NULL, &packet);
701  } else {
702  ast_log(LOG_ERROR,"Cannot answer '%s' because there is no associated SIP transaction\n",
703  ast_channel_name(session->channel));
704  }
705  pjsip_dlg_dec_lock(session->inv_session->dlg);
706 
707  if (status == PJ_SUCCESS && packet) {
709  }
710 
711  if (status != PJ_SUCCESS) {
712  char err[PJ_ERR_MSG_SIZE];
713 
714  pj_strerror(status, err, sizeof(err));
715  ast_log(LOG_WARNING,"Cannot answer '%s': %s\n",
716  ast_channel_name(session->channel), err);
717  /*
718  * Return this value so we can distinguish between this
719  * failure and the threadpool synchronous push failing.
720  */
721  SCOPE_EXIT_RTN_VALUE(-2, "pjproject failure\n");
722  }
724 }
725 
726 /*! \brief Function called by core when we should answer a PJSIP session */
727 static int chan_pjsip_answer(struct ast_channel *ast)
728 {
729  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
730  struct ast_sip_session *session;
731  struct answer_data ans_data = { 0, };
732  int res;
733  SCOPE_ENTER(1, "%s\n", ast_channel_name(ast));
734 
735  if (ast_channel_state(ast) == AST_STATE_UP) {
736  SCOPE_EXIT_RTN_VALUE(0, "Already up\n");
737  return 0;
738  }
739 
741  session = ao2_bump(channel->session);
742 
743  /* the answer task needs to be pushed synchronously otherwise a race condition
744  can occur between this thread and bridging (specifically when native bridging
745  attempts to do direct media) */
746  ast_channel_unlock(ast);
747  ans_data.session = session;
748  ans_data.indent = ast_trace_get_indent();
749  res = ast_sip_push_task_wait_serializer(session->serializer, answer, &ans_data);
750  if (res) {
751  if (res == -1) {
752  ast_log(LOG_ERROR,"Cannot answer '%s': Unable to push answer task to the threadpool.\n",
753  ast_channel_name(session->channel));
754  }
755  ao2_ref(session, -1);
756  ast_channel_lock(ast);
757  SCOPE_EXIT_RTN_VALUE(-1, "Couldn't push task\n");
758  }
759  ao2_ref(session, -1);
760  ast_channel_lock(ast);
761 
763 }
764 
765 /*! \brief Internal helper function called when CNG tone is detected */
767  struct ast_frame *f)
768 {
769  const char *target_context;
770  int exists;
771  int dsp_features;
772 
773  dsp_features = ast_dsp_get_features(session->dsp);
774  dsp_features &= ~DSP_FEATURE_FAX_DETECT;
775  if (dsp_features) {
776  ast_dsp_set_features(session->dsp, dsp_features);
777  } else {
778  ast_dsp_free(session->dsp);
779  session->dsp = NULL;
780  }
781 
782  /* If already executing in the fax extension don't do anything */
783  if (!strcmp(ast_channel_exten(ast), "fax")) {
784  return f;
785  }
786 
787  target_context = S_OR(ast_channel_macrocontext(ast), ast_channel_context(ast));
788 
789  /*
790  * We need to unlock the channel here because ast_exists_extension has the
791  * potential to start and stop an autoservice on the channel. Such action
792  * is prone to deadlock if the channel is locked.
793  *
794  * ast_async_goto() has its own restriction on not holding the channel lock.
795  */
796  ast_channel_unlock(ast);
797  ast_frfree(f);
798  f = &ast_null_frame;
799  exists = ast_exists_extension(ast, target_context, "fax", 1,
800  S_COR(ast_channel_caller(ast)->id.number.valid,
801  ast_channel_caller(ast)->id.number.str, NULL));
802  if (exists) {
803  ast_verb(2, "Redirecting '%s' to fax extension due to CNG detection\n",
804  ast_channel_name(ast));
805  pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast_channel_exten(ast));
806  if (ast_async_goto(ast, target_context, "fax", 1)) {
807  ast_log(LOG_ERROR, "Failed to async goto '%s' into fax extension in '%s'\n",
808  ast_channel_name(ast), target_context);
809  }
810  } else {
811  ast_log(LOG_NOTICE, "FAX CNG detected on '%s' but no fax extension in '%s'\n",
812  ast_channel_name(ast), target_context);
813  }
814 
815  /* It's possible for a masquerade to have occurred when doing the ast_async_goto resulting in
816  * the channel on the session having changed. Since we need to return with the original channel
817  * locked we lock the channel that was passed in and not session->channel.
818  */
819  ast_channel_lock(ast);
820 
821  return f;
822 }
823 
824 /*! \brief Determine if the given frame is in a format we've negotiated */
826 {
827  struct ast_stream_topology *topology = session->active_media_state->topology;
828  struct ast_stream *stream = ast_stream_topology_get_stream(topology, f->stream_num);
829  const struct ast_format_cap *cap = ast_stream_get_formats(stream);
830 
832 }
833 
834 /*!
835  * \brief Function called by core to read any waiting frames
836  *
837  * \note The channel is already locked.
838  */
839 static struct ast_frame *chan_pjsip_read_stream(struct ast_channel *ast)
840 {
841  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
842  struct ast_sip_session *session = channel->session;
843  struct ast_sip_session_media_read_callback_state *callback_state;
844  struct ast_frame *f;
845  int fdno = ast_channel_fdno(ast) - AST_EXTENDED_FDS;
846  struct ast_frame *cur;
847 
848  if (fdno >= AST_VECTOR_SIZE(&session->active_media_state->read_callbacks)) {
849  return &ast_null_frame;
850  }
851 
852  callback_state = AST_VECTOR_GET_ADDR(&session->active_media_state->read_callbacks, fdno);
853  f = callback_state->read_callback(session, callback_state->session);
854 
855  if (!f) {
856  return f;
857  }
858 
859  for (cur = f; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
860  if (cur->frametype == AST_FRAME_VOICE) {
861  break;
862  }
863  }
864 
865  if (!cur || callback_state->session != session->active_media_state->default_session[callback_state->session->type]) {
866  return f;
867  }
868 
869  session = channel->session;
870 
871  /*
872  * Asymmetric RTP only has one native format set at a time.
873  * Therefore we need to update the native format to the current
874  * raw read format BEFORE the native format check
875  */
876  if (!session->endpoint->asymmetric_rtp_codec &&
879  struct ast_format_cap *caps;
880 
881  /* For maximum compatibility we ensure that the formats match that of the received media */
882  ast_debug(1, "Oooh, got a frame with format of %s on channel '%s' when we're sending '%s', switching to match\n",
885 
887  if (caps) {
890  ast_format_cap_append(caps, cur->subclass.format, 0);
892  ao2_ref(caps, -1);
893  }
894 
897 
898  if (ast_channel_is_bridged(ast)) {
900  }
901  }
902 
905  ast_debug(1, "Oooh, got a frame with format of %s on channel '%s' when it has not been negotiated\n",
907  ast_frfree(f);
908  return &ast_null_frame;
909  }
910 
911  if (session->dsp) {
912  int dsp_features;
913 
914  dsp_features = ast_dsp_get_features(session->dsp);
915  if ((dsp_features & DSP_FEATURE_FAX_DETECT)
916  && session->endpoint->faxdetect_timeout
917  && session->endpoint->faxdetect_timeout <= ast_channel_get_up_time(ast)) {
918  dsp_features &= ~DSP_FEATURE_FAX_DETECT;
919  if (dsp_features) {
920  ast_dsp_set_features(session->dsp, dsp_features);
921  } else {
922  ast_dsp_free(session->dsp);
923  session->dsp = NULL;
924  }
925  ast_debug(3, "Channel driver fax CNG detection timeout on %s\n",
926  ast_channel_name(ast));
927  }
928  }
929  if (session->dsp) {
930  f = ast_dsp_process(ast, session->dsp, f);
931  if (f && (f->frametype == AST_FRAME_DTMF)) {
932  if (f->subclass.integer == 'f') {
933  ast_debug(3, "Channel driver fax CNG detected on %s\n",
934  ast_channel_name(ast));
936  /* When chan_pjsip_cng_tone_detected returns it is possible for the
937  * channel pointed to by ast and by session->channel to differ due to a
938  * masquerade. It's best not to touch things after this.
939  */
940  } else {
941  ast_debug(3, "* Detected inband DTMF '%c' on '%s'\n", f->subclass.integer,
942  ast_channel_name(ast));
943  }
944  }
945  }
946 
947  return f;
948 }
949 
950 static int chan_pjsip_write_stream(struct ast_channel *ast, int stream_num, struct ast_frame *frame)
951 {
952  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
953  struct ast_sip_session *session = channel->session;
954  struct ast_sip_session_media *media = NULL;
955  int res = 0;
956 
957  /* The core provides a guarantee that the stream will exist when we are called if stream_num is provided */
958  if (stream_num >= 0) {
959  /* What is not guaranteed is that a media session will exist */
960  if (stream_num < AST_VECTOR_SIZE(&channel->session->active_media_state->sessions)) {
961  media = AST_VECTOR_GET(&channel->session->active_media_state->sessions, stream_num);
962  }
963  }
964 
965  switch (frame->frametype) {
966  case AST_FRAME_VOICE:
967  if (!media) {
968  return 0;
969  } else if (media->type != AST_MEDIA_TYPE_AUDIO) {
970  ast_debug(3, "Channel %s stream %d is of type '%s', not audio!\n",
972  return 0;
973  } else if (media == channel->session->active_media_state->default_session[AST_MEDIA_TYPE_AUDIO] &&
976  struct ast_str *write_transpath = ast_str_alloca(256);
977  struct ast_str *read_transpath = ast_str_alloca(256);
978 
980  "Channel %s asked to send %s frame when native formats are %s (rd:%s->%s;%s wr:%s->%s;%s)\n",
981  ast_channel_name(ast),
986  ast_translate_path_to_str(ast_channel_readtrans(ast), &read_transpath),
989  ast_translate_path_to_str(ast_channel_writetrans(ast), &write_transpath));
990  return 0;
991  } else if (media->write_callback) {
992  res = media->write_callback(session, media, frame);
993 
994  }
995  break;
996  case AST_FRAME_VIDEO:
997  if (!media) {
998  return 0;
999  } else if (media->type != AST_MEDIA_TYPE_VIDEO) {
1000  ast_debug(3, "Channel %s stream %d is of type '%s', not video!\n",
1001  ast_channel_name(ast), stream_num, ast_codec_media_type2str(media->type));
1002  return 0;
1003  } else if (media->write_callback) {
1004  res = media->write_callback(session, media, frame);
1005  }
1006  break;
1007  case AST_FRAME_MODEM:
1008  if (!media) {
1009  return 0;
1010  } else if (media->type != AST_MEDIA_TYPE_IMAGE) {
1011  ast_debug(3, "Channel %s stream %d is of type '%s', not image!\n",
1012  ast_channel_name(ast), stream_num, ast_codec_media_type2str(media->type));
1013  return 0;
1014  } else if (media->write_callback) {
1015  res = media->write_callback(session, media, frame);
1016  }
1017  break;
1018  case AST_FRAME_CNG:
1019  break;
1020  case AST_FRAME_RTCP:
1021  /* We only support writing out feedback */
1022  if (frame->subclass.integer != AST_RTP_RTCP_PSFB || !media) {
1023  return 0;
1024  } else if (media->type != AST_MEDIA_TYPE_VIDEO) {
1025  ast_debug(3, "Channel %s stream %d is of type '%s', not video! Unable to write RTCP feedback.\n",
1026  ast_channel_name(ast), stream_num, ast_codec_media_type2str(media->type));
1027  return 0;
1028  } else if (media->write_callback) {
1029  res = media->write_callback(session, media, frame);
1030  }
1031  break;
1032  default:
1033  ast_log(LOG_WARNING, "Can't send %u type frames with PJSIP\n", frame->frametype);
1034  break;
1035  }
1036 
1037  return res;
1038 }
1039 
1040 static int chan_pjsip_write(struct ast_channel *ast, struct ast_frame *frame)
1041 {
1042  return chan_pjsip_write_stream(ast, -1, frame);
1043 }
1044 
1045 /*! \brief Function called by core to change the underlying owner channel */
1046 static int chan_pjsip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
1047 {
1048  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(newchan);
1049 
1050  if (channel->session->channel != oldchan) {
1051  return -1;
1052  }
1053 
1054  /*
1055  * The masquerade has suspended the channel's session
1056  * serializer so we can safely change it outside of
1057  * the serializer thread.
1058  */
1059  channel->session->channel = newchan;
1060 
1062 
1063  return 0;
1064 }
1065 
1066 /*! AO2 hash function for on hold UIDs */
1067 static int uid_hold_hash_fn(const void *obj, const int flags)
1068 {
1069  const char *key = obj;
1070 
1071  switch (flags & OBJ_SEARCH_MASK) {
1072  case OBJ_SEARCH_KEY:
1073  break;
1074  case OBJ_SEARCH_OBJECT:
1075  break;
1076  default:
1077  /* Hash can only work on something with a full key. */
1078  ast_assert(0);
1079  return 0;
1080  }
1081  return ast_str_hash(key);
1082 }
1083 
1084 /*! AO2 sort function for on hold UIDs */
1085 static int uid_hold_sort_fn(const void *obj_left, const void *obj_right, const int flags)
1086 {
1087  const char *left = obj_left;
1088  const char *right = obj_right;
1089  int cmp;
1090 
1091  switch (flags & OBJ_SEARCH_MASK) {
1092  case OBJ_SEARCH_OBJECT:
1093  case OBJ_SEARCH_KEY:
1094  cmp = strcmp(left, right);
1095  break;
1097  cmp = strncmp(left, right, strlen(right));
1098  break;
1099  default:
1100  /* Sort can only work on something with a full or partial key. */
1101  ast_assert(0);
1102  cmp = 0;
1103  break;
1104  }
1105  return cmp;
1106 }
1107 
1109 
1110 /*!
1111  * \brief Add a channel ID to the list of PJSIP channels on hold
1112  *
1113  * \param chan_uid - Unique ID of the channel being put into the hold list
1114  *
1115  * \retval 0 Channel has been added to or was already in the hold list
1116  * \retval -1 Failed to add channel to the hold list
1117  */
1118 static int chan_pjsip_add_hold(const char *chan_uid)
1119 {
1120  RAII_VAR(char *, hold_uid, NULL, ao2_cleanup);
1121 
1122  hold_uid = ao2_find(pjsip_uids_onhold, chan_uid, OBJ_SEARCH_KEY);
1123  if (hold_uid) {
1124  /* Device is already on hold. Nothing to do. */
1125  return 0;
1126  }
1127 
1128  /* Device wasn't in hold list already. Create a new one. */
1129  hold_uid = ao2_alloc_options(strlen(chan_uid) + 1, NULL,
1131  if (!hold_uid) {
1132  return -1;
1133  }
1134 
1135  ast_copy_string(hold_uid, chan_uid, strlen(chan_uid) + 1);
1136 
1137  if (ao2_link(pjsip_uids_onhold, hold_uid) == 0) {
1138  return -1;
1139  }
1140 
1141  return 0;
1142 }
1143 
1144 /*!
1145  * \brief Remove a channel ID from the list of PJSIP channels on hold
1146  *
1147  * \param chan_uid - Unique ID of the channel being taken out of the hold list
1148  */
1149 static void chan_pjsip_remove_hold(const char *chan_uid)
1150 {
1152 }
1153 
1154 /*!
1155  * \brief Determine whether a channel ID is in the list of PJSIP channels on hold
1156  *
1157  * \param chan_uid - Channel being checked
1158  *
1159  * \retval 0 The channel is not in the hold list
1160  * \retval 1 The channel is in the hold list
1161  */
1162 static int chan_pjsip_get_hold(const char *chan_uid)
1163 {
1164  RAII_VAR(char *, hold_uid, NULL, ao2_cleanup);
1165 
1166  hold_uid = ao2_find(pjsip_uids_onhold, chan_uid, OBJ_SEARCH_KEY);
1167  if (!hold_uid) {
1168  return 0;
1169  }
1170 
1171  return 1;
1172 }
1173 
1174 /*! \brief Function called to get the device state of an endpoint */
1175 static int chan_pjsip_devicestate(const char *data)
1176 {
1177  RAII_VAR(struct ast_sip_endpoint *, endpoint, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", data), ao2_cleanup);
1179  RAII_VAR(struct ast_endpoint_snapshot *, endpoint_snapshot, NULL, ao2_cleanup);
1180  struct ast_devstate_aggregate aggregate;
1181  int num, inuse = 0;
1182 
1183  if (!endpoint) {
1184  return AST_DEVICE_INVALID;
1185  }
1186 
1187  endpoint_snapshot = ast_endpoint_latest_snapshot(ast_endpoint_get_tech(endpoint->persistent),
1189 
1190  if (!endpoint_snapshot) {
1191  return AST_DEVICE_INVALID;
1192  }
1193 
1194  if (endpoint_snapshot->state == AST_ENDPOINT_OFFLINE) {
1196  } else if (endpoint_snapshot->state == AST_ENDPOINT_ONLINE) {
1198  }
1199 
1200  if (!endpoint_snapshot->num_channels) {
1201  return state;
1202  }
1203 
1204  ast_devstate_aggregate_init(&aggregate);
1205 
1206  for (num = 0; num < endpoint_snapshot->num_channels; num++) {
1207  struct ast_channel_snapshot *snapshot;
1208 
1209  snapshot = ast_channel_snapshot_get_latest(endpoint_snapshot->channel_ids[num]);
1210  if (!snapshot) {
1211  continue;
1212  }
1213 
1214  if (chan_pjsip_get_hold(snapshot->base->uniqueid)) {
1216  } else {
1217  ast_devstate_aggregate_add(&aggregate, ast_state_chan2dev(snapshot->state));
1218  }
1219 
1220  if ((snapshot->state == AST_STATE_UP) || (snapshot->state == AST_STATE_RING) ||
1221  (snapshot->state == AST_STATE_BUSY)) {
1222  inuse++;
1223  }
1224 
1225  ao2_ref(snapshot, -1);
1226  }
1227 
1228  if (endpoint->devicestate_busy_at && (inuse == endpoint->devicestate_busy_at)) {
1230  } else if (ast_devstate_aggregate_result(&aggregate) != AST_DEVICE_INVALID) {
1231  state = ast_devstate_aggregate_result(&aggregate);
1232  }
1233 
1234  return state;
1235 }
1236 
1237 /*! \brief Function called to query options on a channel */
1238 static int chan_pjsip_queryoption(struct ast_channel *ast, int option, void *data, int *datalen)
1239 {
1240  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
1241  int res = -1;
1243 
1244  if (!channel) {
1245  return -1;
1246  }
1247 
1248  switch (option) {
1249  case AST_OPTION_T38_STATE:
1250  if (channel->session->endpoint->media.t38.enabled) {
1251  switch (channel->session->t38state) {
1252  case T38_LOCAL_REINVITE:
1253  case T38_PEER_REINVITE:
1255  break;
1256  case T38_ENABLED:
1258  break;
1259  case T38_REJECTED:
1261  break;
1262  default:
1264  break;
1265  }
1266  }
1267 
1268  *((enum ast_t38_state *) data) = state;
1269  res = 0;
1270 
1271  break;
1272  default:
1273  break;
1274  }
1275 
1276  return res;
1277 }
1278 
1279 static const char *chan_pjsip_get_uniqueid(struct ast_channel *ast)
1280 {
1281  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
1283 
1284  if (!uniqueid) {
1285  return "";
1286  }
1287 
1288  ast_copy_pj_str(uniqueid, &channel->session->inv_session->dlg->call_id->id, UNIQUEID_BUFSIZE);
1289 
1290  return uniqueid;
1291 }
1292 
1297  void *frame_data;
1298  size_t datalen;
1299 };
1300 
1301 static void indicate_data_destroy(void *obj)
1302 {
1303  struct indicate_data *ind_data = obj;
1304 
1305  ast_free(ind_data->frame_data);
1306  ao2_ref(ind_data->session, -1);
1307 }
1308 
1310  int condition, int response_code, const void *frame_data, size_t datalen)
1311 {
1312  struct indicate_data *ind_data = ao2_alloc(sizeof(*ind_data), indicate_data_destroy);
1313 
1314  if (!ind_data) {
1315  return NULL;
1316  }
1317 
1318  ind_data->frame_data = ast_malloc(datalen);
1319  if (!ind_data->frame_data) {
1320  ao2_ref(ind_data, -1);
1321  return NULL;
1322  }
1323 
1324  memcpy(ind_data->frame_data, frame_data, datalen);
1325  ind_data->datalen = datalen;
1326  ind_data->condition = condition;
1327  ind_data->response_code = response_code;
1328  ao2_ref(session, +1);
1329  ind_data->session = session;
1330 
1331  return ind_data;
1332 }
1333 
1334 static int indicate(void *data)
1335 {
1336  pjsip_tx_data *packet = NULL;
1337  struct indicate_data *ind_data = data;
1338  struct ast_sip_session *session = ind_data->session;
1339  int response_code = ind_data->response_code;
1340 
1341  if ((session->inv_session->state != PJSIP_INV_STATE_DISCONNECTED) &&
1342  (pjsip_inv_answer(session->inv_session, response_code, NULL, NULL, &packet) == PJ_SUCCESS)) {
1344  }
1345 
1346  ao2_ref(ind_data, -1);
1347 
1348  return 0;
1349 }
1350 
1351 /*! \brief Send SIP INFO with video update request */
1352 static int transmit_info_with_vidupdate(void *data)
1353 {
1354  const char * xml =
1355  "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n"
1356  " <media_control>\r\n"
1357  " <vc_primitive>\r\n"
1358  " <to_encoder>\r\n"
1359  " <picture_fast_update/>\r\n"
1360  " </to_encoder>\r\n"
1361  " </vc_primitive>\r\n"
1362  " </media_control>\r\n";
1363 
1364  const struct ast_sip_body body = {
1365  .type = "application",
1366  .subtype = "media_control+xml",
1367  .body_text = xml
1368  };
1369 
1370  RAII_VAR(struct ast_sip_session *, session, data, ao2_cleanup);
1371  struct pjsip_tx_data *tdata;
1372 
1373  if (session->inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
1374  ast_log(LOG_ERROR, "Session already DISCONNECTED [reason=%d (%s)]\n",
1375  session->inv_session->cause,
1376  pjsip_get_status_text(session->inv_session->cause)->ptr);
1377  return -1;
1378  }
1379 
1380  if (ast_sip_create_request("INFO", session->inv_session->dlg, session->endpoint, NULL, NULL, &tdata)) {
1381  ast_log(LOG_ERROR, "Could not create text video update INFO request\n");
1382  return -1;
1383  }
1384  if (ast_sip_add_body(tdata, &body)) {
1385  ast_log(LOG_ERROR, "Could not add body to text video update INFO request\n");
1386  return -1;
1387  }
1389 
1390  return 0;
1391 }
1392 
1393 /*!
1394  * \internal
1395  * \brief TRUE if a COLP update can be sent to the peer.
1396  * \since 13.3.0
1397  *
1398  * \param session The session to see if the COLP update is allowed.
1399  *
1400  * \retval 0 Update is not allowed.
1401  * \retval 1 Update is allowed.
1402  */
1404 {
1405  struct ast_party_id connected_id;
1406  int update_allowed = 0;
1407 
1408  if (!session->endpoint->id.send_connected_line
1409  || (!session->endpoint->id.send_pai && !session->endpoint->id.send_rpid)) {
1410  return 0;
1411  }
1412 
1413  /*
1414  * Check if privacy allows the update. Check while the channel
1415  * is locked so we can work with the shallow connected_id copy.
1416  */
1417  ast_channel_lock(session->channel);
1418  connected_id = ast_channel_connected_effective_id(session->channel);
1419  if (connected_id.number.valid
1420  && (session->endpoint->id.trust_outbound
1422  update_allowed = 1;
1423  }
1424  ast_channel_unlock(session->channel);
1425 
1426  return update_allowed;
1427 }
1428 
1429 /*! \brief Update connected line information */
1431 {
1432  struct ast_sip_session *session = data;
1433 
1434  if (session->inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
1435  ast_log(LOG_ERROR, "Session already DISCONNECTED [reason=%d (%s)]\n",
1436  session->inv_session->cause,
1437  pjsip_get_status_text(session->inv_session->cause)->ptr);
1438  ao2_ref(session, -1);
1439  return -1;
1440  }
1441 
1442  if (ast_channel_state(session->channel) == AST_STATE_UP
1443  || session->inv_session->role == PJSIP_ROLE_UAC) {
1446  int generate_new_sdp;
1447 
1448  method = session->endpoint->id.refresh_method;
1449  if (session->inv_session->options & PJSIP_INV_SUPPORT_UPDATE) {
1451  }
1452 
1453  /* Only the INVITE method actually needs SDP, UPDATE can do without */
1454  generate_new_sdp = (method == AST_SIP_SESSION_REFRESH_METHOD_INVITE);
1455 
1456  ast_sip_session_refresh(session, NULL, NULL, NULL, method, generate_new_sdp, NULL);
1457  }
1458  } else if (session->endpoint->id.rpid_immediate
1459  && session->inv_session->state != PJSIP_INV_STATE_DISCONNECTED
1461  int response_code = 0;
1462 
1463  if (ast_channel_state(session->channel) == AST_STATE_RING) {
1464  response_code = !session->endpoint->inband_progress ? 180 : 183;
1465  } else if (ast_channel_state(session->channel) == AST_STATE_RINGING) {
1466  response_code = 183;
1467  }
1468 
1469  if (response_code) {
1470  struct pjsip_tx_data *packet = NULL;
1471 
1472  if (pjsip_inv_answer(session->inv_session, response_code, NULL, NULL, &packet) == PJ_SUCCESS) {
1474  }
1475  }
1476  }
1477 
1478  ao2_ref(session, -1);
1479  return 0;
1480 }
1481 
1482 /*! \brief Callback which changes the value of locally held on the media stream */
1483 static void local_hold_set_state(struct ast_sip_session_media *session_media, unsigned int held)
1484 {
1485  if (session_media) {
1486  session_media->locally_held = held;
1487  }
1488 }
1489 
1490 /*! \brief Update local hold state and send a re-INVITE with the new SDP */
1491 static int remote_send_hold_refresh(struct ast_sip_session *session, unsigned int held)
1492 {
1493  AST_VECTOR_CALLBACK_VOID(&session->active_media_state->sessions, local_hold_set_state, held);
1495  ao2_ref(session, -1);
1496 
1497  return 0;
1498 }
1499 
1500 /*! \brief Update local hold state to be held */
1501 static int remote_send_hold(void *data)
1502 {
1503  return remote_send_hold_refresh(data, 1);
1504 }
1505 
1506 /*! \brief Update local hold state to be unheld */
1507 static int remote_send_unhold(void *data)
1508 {
1509  return remote_send_hold_refresh(data, 0);
1510 }
1511 
1515 };
1516 
1518 {
1520 
1523 }
1524 
1526  struct ast_sip_session *session, const struct ast_stream_topology *topology)
1527 {
1529 
1530  refresh_data = ast_calloc(1, sizeof(*refresh_data));
1531  if (!refresh_data) {
1532  return NULL;
1533  }
1534 
1537  if (!refresh_data->media_state) {
1539  return NULL;
1540  }
1541  refresh_data->media_state->topology = ast_stream_topology_clone(topology);
1542  if (!refresh_data->media_state->topology) {
1544  return NULL;
1545  }
1546 
1547  return refresh_data;
1548 }
1549 
1550 static int on_topology_change_response(struct ast_sip_session *session, pjsip_rx_data *rdata)
1551 {
1552  SCOPE_ENTER(3, "%s: Received response code %d. PT: %s AT: %s\n", ast_sip_session_get_name(session),
1553  rdata->msg_info.msg->line.status.code,
1554  ast_str_tmp(256, ast_stream_topology_to_str(session->pending_media_state->topology, &STR_TMP)),
1555  ast_str_tmp(256, ast_stream_topology_to_str(session->active_media_state->topology, &STR_TMP)));
1556 
1557 
1558  if (PJSIP_IS_STATUS_IN_CLASS(rdata->msg_info.msg->line.status.code, 200)) {
1559  /* The topology was changed to something new so give notice to what requested
1560  * it so it queries the channel and updates accordingly.
1561  */
1562  if (session->channel) {
1564  SCOPE_EXIT_RTN_VALUE(0, "%s: Queued topology change frame\n", ast_sip_session_get_name(session));
1565  }
1566  SCOPE_EXIT_RTN_VALUE(0, "%s: No channel? Can't queue topology change frame\n", ast_sip_session_get_name(session));
1567  } else if (300 <= rdata->msg_info.msg->line.status.code) {
1568  /* The topology change failed, so drop the current pending media state */
1569  ast_sip_session_media_state_reset(session->pending_media_state);
1570  SCOPE_EXIT_RTN_VALUE(0, "%s: response code > 300. Resetting pending media state\n", ast_sip_session_get_name(session));
1571  }
1572 
1573  SCOPE_EXIT_RTN_VALUE(0, "%s: Nothing to do\n", ast_sip_session_get_name(session));
1574 }
1575 
1576 static int send_topology_change_refresh(void *data)
1577 {
1580  int ret;
1582  ast_str_tmp(256, ast_stream_topology_to_str(refresh_data->media_state->topology, &STR_TMP)));
1583 
1584 
1587  refresh_data->media_state = NULL;
1589 
1591 }
1592 
1594  const struct ast_stream_topology *proposed)
1595 {
1597  int res;
1598  SCOPE_ENTER(1);
1599 
1601  if (!refresh_data) {
1602  SCOPE_EXIT_RTN_VALUE(-1, "Couldn't create refresh_data\n");
1603  }
1604 
1606  if (res) {
1608  }
1609  SCOPE_EXIT_RTN_VALUE(res, "RC: %d\n", res);
1610 }
1611 
1612 /*! \brief Function called by core to ask the channel to indicate some sort of condition */
1613 static int chan_pjsip_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
1614 {
1615  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
1616  struct ast_sip_session_media *media;
1617  int response_code = 0;
1618  int res = 0;
1619  char *device_buf;
1620  size_t device_buf_size;
1621  int i;
1622  const struct ast_stream_topology *topology;
1623  struct ast_frame f = {
1625  .subclass = {
1626  .integer = condition
1627  },
1628  .datalen = datalen,
1629  .data.ptr = (void *)data,
1630  };
1631  char condition_name[256];
1632  SCOPE_ENTER(3, "%s: Indicated %s\n", ast_channel_name(ast),
1633  ast_frame_subclass2str(&f, condition_name, sizeof(condition_name), NULL, 0));
1634 
1635  switch (condition) {
1636  case AST_CONTROL_RINGING:
1637  if (ast_channel_state(ast) == AST_STATE_RING) {
1638  if (channel->session->endpoint->inband_progress ||
1639  (channel->session->inv_session && channel->session->inv_session->neg &&
1640  pjmedia_sdp_neg_get_state(channel->session->inv_session->neg) == PJMEDIA_SDP_NEG_STATE_DONE)) {
1641  response_code = 183;
1642  res = -1;
1643  } else {
1644  response_code = 180;
1645  }
1646  } else {
1647  res = -1;
1648  }
1650  break;
1651  case AST_CONTROL_BUSY:
1652  if (ast_channel_state(ast) != AST_STATE_UP) {
1653  response_code = 486;
1654  } else {
1655  res = -1;
1656  }
1657  break;
1659  if (ast_channel_state(ast) != AST_STATE_UP) {
1660  response_code = 503;
1661  } else {
1662  res = -1;
1663  }
1664  break;
1666  if (ast_channel_state(ast) != AST_STATE_UP) {
1667  response_code = 484;
1668  } else {
1669  res = -1;
1670  }
1671  break;
1673  if (ast_channel_state(ast) != AST_STATE_UP) {
1674  response_code = 100;
1675  } else {
1676  res = -1;
1677  }
1678  break;
1679  case AST_CONTROL_PROGRESS:
1680  if (ast_channel_state(ast) != AST_STATE_UP) {
1681  response_code = 183;
1682  } else {
1683  res = -1;
1684  }
1686  break;
1687  case AST_CONTROL_VIDUPDATE:
1688  for (i = 0; i < AST_VECTOR_SIZE(&channel->session->active_media_state->sessions); ++i) {
1689  media = AST_VECTOR_GET(&channel->session->active_media_state->sessions, i);
1690  if (!media || media->type != AST_MEDIA_TYPE_VIDEO) {
1691  continue;
1692  }
1693  if (media->rtp) {
1694  /* FIXME: Only use this for VP8. Additional work would have to be done to
1695  * fully support other video codecs */
1696 
1700  (channel->session->endpoint->media.webrtc &&
1702  /* FIXME Fake RTP write, this will be sent as an RTCP packet. Ideally the
1703  * RTP engine would provide a way to externally write/schedule RTCP
1704  * packets */
1705  struct ast_frame fr;
1708  res = ast_rtp_instance_write(media->rtp, &fr);
1709  } else {
1710  ao2_ref(channel->session, +1);
1712  ao2_cleanup(channel->session);
1713  }
1714  }
1715  ast_test_suite_event_notify("AST_CONTROL_VIDUPDATE", "Result: Success");
1716  } else {
1717  ast_test_suite_event_notify("AST_CONTROL_VIDUPDATE", "Result: Failure");
1718  res = -1;
1719  }
1720  }
1721  /* XXX If there were no video streams, then this should set
1722  * res to -1
1723  */
1724  break;
1726  ao2_ref(channel->session, +1);
1728  ao2_cleanup(channel->session);
1729  }
1730  break;
1732  break;
1734  res = -1;
1735  break;
1737  ast_assert(datalen == sizeof(int));
1738  if (*(int *) data) {
1739  /*
1740  * Masquerade is beginning:
1741  * Wait for session serializer to get suspended.
1742  */
1743  ast_channel_unlock(ast);
1744  ast_sip_session_suspend(channel->session);
1745  ast_channel_lock(ast);
1746  } else {
1747  /*
1748  * Masquerade is complete:
1749  * Unsuspend the session serializer.
1750  */
1752  }
1753  break;
1754  case AST_CONTROL_HOLD:
1756  device_buf_size = strlen(ast_channel_name(ast)) + 1;
1757  device_buf = alloca(device_buf_size);
1758  ast_channel_get_device_name(ast, device_buf, device_buf_size);
1760  if (!channel->session->moh_passthrough) {
1761  ast_moh_start(ast, data, NULL);
1762  } else {
1764  ast_log(LOG_WARNING, "Could not queue task to remotely put session '%s' on hold with endpoint '%s'\n",
1766  ao2_ref(channel->session, -1);
1767  }
1768  }
1769  break;
1770  case AST_CONTROL_UNHOLD:
1772  device_buf_size = strlen(ast_channel_name(ast)) + 1;
1773  device_buf = alloca(device_buf_size);
1774  ast_channel_get_device_name(ast, device_buf, device_buf_size);
1776  if (!channel->session->moh_passthrough) {
1777  ast_moh_stop(ast);
1778  } else {
1780  ast_log(LOG_WARNING, "Could not queue task to remotely take session '%s' off hold with endpoint '%s'\n",
1782  ao2_ref(channel->session, -1);
1783  }
1784  }
1785  break;
1786  case AST_CONTROL_SRCUPDATE:
1787  break;
1788  case AST_CONTROL_SRCCHANGE:
1789  break;
1791  if (ast_channel_state(ast) != AST_STATE_UP) {
1792  response_code = 181;
1793  } else {
1794  res = -1;
1795  }
1796  break;
1798  res = 0;
1799 
1800  if (channel->session->t38state == T38_PEER_REINVITE) {
1801  const struct ast_control_t38_parameters *parameters = data;
1802 
1803  if (parameters->request_response == AST_T38_REQUEST_PARMS) {
1804  res = AST_T38_REQUEST_PARMS;
1805  }
1806  }
1807 
1808  break;
1810  topology = data;
1811  ast_trace(-1, "%s: New topology: %s\n", ast_channel_name(ast),
1812  ast_str_tmp(256, ast_stream_topology_to_str(topology, &STR_TMP)));
1813  res = handle_topology_request_change(channel->session, topology);
1814  break;
1816  break;
1818  break;
1819  case -1:
1820  res = -1;
1821  break;
1822  default:
1823  ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", condition);
1824  res = -1;
1825  break;
1826  }
1827 
1828  if (response_code) {
1829  struct indicate_data *ind_data = indicate_data_alloc(channel->session, condition, response_code, data, datalen);
1830 
1831  if (!ind_data) {
1832  SCOPE_EXIT_LOG_RTN_VALUE(-1, LOG_ERROR, "%s: Couldn't alloc indicate data\n", ast_channel_name(ast));
1833  }
1834 
1835  if (ast_sip_push_task(channel->session->serializer, indicate, ind_data)) {
1836  ast_log(LOG_ERROR, "%s: Cannot send response code %d to endpoint %s. Could not queue task properly\n",
1838  ao2_cleanup(ind_data);
1839  res = -1;
1840  }
1841  }
1842 
1843  SCOPE_EXIT_RTN_VALUE(res, "%s\n", ast_channel_name(ast));
1844 }
1845 
1848  char *target;
1849 };
1850 
1851 static void transfer_data_destroy(void *obj)
1852 {
1853  struct transfer_data *trnf_data = obj;
1854 
1855  ast_free(trnf_data->target);
1856  ao2_cleanup(trnf_data->session);
1857 }
1858 
1860 {
1861  struct transfer_data *trnf_data = ao2_alloc(sizeof(*trnf_data), transfer_data_destroy);
1862 
1863  if (!trnf_data) {
1864  return NULL;
1865  }
1866 
1867  if (!(trnf_data->target = ast_strdup(target))) {
1868  ao2_ref(trnf_data, -1);
1869  return NULL;
1870  }
1871 
1872  ao2_ref(session, +1);
1873  trnf_data->session = session;
1874 
1875  return trnf_data;
1876 }
1877 
1878 static void transfer_redirect(struct ast_sip_session *session, const char *target)
1879 {
1880  pjsip_tx_data *packet;
1882  pjsip_contact_hdr *contact;
1883  pj_str_t tmp;
1884 
1885  if (pjsip_inv_end_session(session->inv_session, 302, NULL, &packet) != PJ_SUCCESS
1886  || !packet) {
1887  ast_log(LOG_WARNING, "Failed to redirect PJSIP session for channel %s\n",
1888  ast_channel_name(session->channel));
1891 
1892  return;
1893  }
1894 
1895  if (!(contact = pjsip_msg_find_hdr(packet->msg, PJSIP_H_CONTACT, NULL))) {
1896  contact = pjsip_contact_hdr_create(packet->pool);
1897  }
1898 
1899  pj_strdup2_with_null(packet->pool, &tmp, target);
1900  if (!(contact->uri = pjsip_parse_uri(packet->pool, tmp.ptr, tmp.slen, PJSIP_PARSE_URI_AS_NAMEADDR))) {
1901  ast_log(LOG_WARNING, "Failed to parse destination URI '%s' for channel %s\n",
1902  target, ast_channel_name(session->channel));
1905  pjsip_tx_data_dec_ref(packet);
1906 
1907  return;
1908  }
1909  pjsip_msg_add_hdr(packet->msg, (pjsip_hdr *) contact);
1910 
1913 }
1914 
1915 /*! \brief REFER Callback module, used to attach session data structure to subscription */
1916 static pjsip_module refer_callback_module = {
1917  .name = { "REFER Callback", 14 },
1918  .id = -1,
1919 };
1920 
1921 /*!
1922  * \brief Callback function to report status of implicit REFER-NOTIFY subscription.
1923  *
1924  * This function will be called on any state change in the REFER-NOTIFY subscription.
1925  * Its primary purpose is to report SUCCESS/FAILURE of a transfer initiated via
1926  * \ref transfer_refer as well as to terminate the subscription, if necessary.
1927  */
1928 static void xfer_client_on_evsub_state(pjsip_evsub *sub, pjsip_event *event)
1929 {
1930  struct ast_channel *chan;
1932  int res = 0;
1933 
1934  if (!event) {
1935  return;
1936  }
1937 
1938  chan = pjsip_evsub_get_mod_data(sub, refer_callback_module.id);
1939  if (!chan) {
1940  return;
1941  }
1942 
1943  if (pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_ACCEPTED) {
1944  /* Check if subscription is suppressed and terminate and send completion code, if so. */
1945  pjsip_rx_data *rdata;
1946  pjsip_generic_string_hdr *refer_sub;
1947  const pj_str_t REFER_SUB = { "Refer-Sub", 9 };
1948 
1949  ast_debug(3, "Transfer accepted on channel %s\n", ast_channel_name(chan));
1950 
1951  /* Check if response message */
1952  if (event->type == PJSIP_EVENT_TSX_STATE && event->body.tsx_state.type == PJSIP_EVENT_RX_MSG) {
1953  rdata = event->body.tsx_state.src.rdata;
1954 
1955  /* Find Refer-Sub header */
1956  refer_sub = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &REFER_SUB, NULL);
1957 
1958  /* Check if subscription is suppressed. If it is, the far end will not terminate it,
1959  * and the subscription will remain active until it times out. Terminating it here
1960  * eliminates the unnecessary timeout.
1961  */
1962  if (refer_sub && !pj_stricmp2(&refer_sub->hvalue, "false")) {
1963  /* Since no subscription is desired, assume that call has been transferred successfully. */
1964  /* Channel reference will be released at end of function */
1965  /* Terminate subscription. */
1966  pjsip_evsub_set_mod_data(sub, refer_callback_module.id, NULL);
1967  pjsip_evsub_terminate(sub, PJ_TRUE);
1968  res = -1;
1969  }
1970  }
1971  } else if (pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_ACTIVE ||
1972  pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_TERMINATED) {
1973  /* Check for NOTIFY complete or error. */
1974  pjsip_msg *msg;
1975  pjsip_msg_body *body;
1976  pjsip_status_line status_line = { .code = 0 };
1977  pj_bool_t is_last;
1978  pj_status_t status;
1979 
1980  if (event->type == PJSIP_EVENT_TSX_STATE && event->body.tsx_state.type == PJSIP_EVENT_RX_MSG) {
1981  pjsip_rx_data *rdata;
1982 
1983  rdata = event->body.tsx_state.src.rdata;
1984  msg = rdata->msg_info.msg;
1985 
1986  if (msg->type == PJSIP_REQUEST_MSG) {
1987  if (!pjsip_method_cmp(&msg->line.req.method, pjsip_get_notify_method())) {
1988  body = msg->body;
1989  if (body && !pj_stricmp2(&body->content_type.type, "message")
1990  && !pj_stricmp2(&body->content_type.subtype, "sipfrag")) {
1991  pjsip_parse_status_line((char *)body->data, body->len, &status_line);
1992  }
1993  }
1994  } else {
1995  status_line.code = msg->line.status.code;
1996  status_line.reason = msg->line.status.reason;
1997  }
1998  } else {
1999  status_line.code = 500;
2000  status_line.reason = *pjsip_get_status_text(500);
2001  }
2002 
2003  is_last = (pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_TERMINATED);
2004  /* If the status code is >= 200, the subscription is finished. */
2005  if (status_line.code >= 200 || is_last) {
2006  res = -1;
2007 
2008  /* If the subscription has terminated, return AST_TRANSFER_SUCCESS for 2XX.
2009  * Return AST_TRANSFER_FAILED for any code < 200.
2010  * Otherwise, return the status code.
2011  * The subscription should not terminate for any code < 200,
2012  * but if it does, that constitutes a failure. */
2013  if (status_line.code < 200) {
2015  } else if (status_line.code >= 300) {
2016  message = status_line.code;
2017  }
2018 
2019  /* If subscription not terminated and subscription is finished (status code >= 200)
2020  * terminate it */
2021  if (!is_last) {
2022  pjsip_tx_data *tdata;
2023 
2024  status = pjsip_evsub_initiate(sub, pjsip_get_subscribe_method(), 0, &tdata);
2025  if (status == PJ_SUCCESS) {
2026  pjsip_evsub_send_request(sub, tdata);
2027  }
2028  }
2029  /* Finished. Remove session from subscription */
2030  pjsip_evsub_set_mod_data(sub, refer_callback_module.id, NULL);
2031  ast_debug(3, "Transfer channel %s completed: %d %.*s (%s)\n",
2032  ast_channel_name(chan),
2033  status_line.code,
2034  (int)status_line.reason.slen, status_line.reason.ptr,
2035  (message == AST_TRANSFER_SUCCESS) ? "Success" : "Failure");
2036  }
2037  }
2038 
2039  if (res) {
2041  ao2_ref(chan, -1);
2042  }
2043 }
2044 
2045 static void transfer_refer(struct ast_sip_session *session, const char *target)
2046 {
2047  pjsip_evsub *sub;
2049  pj_str_t tmp;
2050  pjsip_tx_data *packet;
2051  const char *ref_by_val;
2052  char local_info[pj_strlen(&session->inv_session->dlg->local.info_str) + 1];
2053  struct pjsip_evsub_user xfer_cb;
2054  struct ast_channel *chan = session->channel;
2055 
2056  pj_bzero(&xfer_cb, sizeof(xfer_cb));
2057  xfer_cb.on_evsub_state = &xfer_client_on_evsub_state;
2058 
2059  if (pjsip_xfer_create_uac(session->inv_session->dlg, &xfer_cb, &sub) != PJ_SUCCESS) {
2062 
2063  return;
2064  }
2065 
2066  /* refer_callback_module requires a reference to chan
2067  * which will be released in xfer_client_on_evsub_state()
2068  * when the implicit REFER subscription terminates */
2069  pjsip_evsub_set_mod_data(sub, refer_callback_module.id, chan);
2070  ao2_ref(chan, +1);
2071 
2072  if (pjsip_xfer_initiate(sub, pj_cstr(&tmp, target), &packet) != PJ_SUCCESS) {
2073  goto failure;
2074  }
2075 
2076  ref_by_val = pbx_builtin_getvar_helper(chan, "SIPREFERREDBYHDR");
2077  if (!ast_strlen_zero(ref_by_val)) {
2078  ast_sip_add_header(packet, "Referred-By", ref_by_val);
2079  } else {
2080  ast_copy_pj_str(local_info, &session->inv_session->dlg->local.info_str, sizeof(local_info));
2081  ast_sip_add_header(packet, "Referred-By", local_info);
2082  }
2083 
2084  if (pjsip_xfer_send_request(sub, packet) == PJ_SUCCESS) {
2085  return;
2086  }
2087 
2088 failure:
2091  pjsip_evsub_set_mod_data(sub, refer_callback_module.id, NULL);
2092  pjsip_evsub_terminate(sub, PJ_FALSE);
2093 
2094  ao2_ref(chan, -1);
2095 }
2096 
2097 static int transfer(void *data)
2098 {
2099  struct transfer_data *trnf_data = data;
2100  struct ast_sip_endpoint *endpoint = NULL;
2101  struct ast_sip_contact *contact = NULL;
2102  const char *target = trnf_data->target;
2103 
2104  if (trnf_data->session->inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
2105  ast_log(LOG_ERROR, "Session already DISCONNECTED [reason=%d (%s)]\n",
2106  trnf_data->session->inv_session->cause,
2107  pjsip_get_status_text(trnf_data->session->inv_session->cause)->ptr);
2108  } else {
2109  /* See if we have an endpoint; if so, use its contact */
2110  endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", target);
2111  if (endpoint) {
2113  if (contact && !ast_strlen_zero(contact->uri)) {
2114  target = contact->uri;
2115  }
2116  }
2117 
2118  if (ast_channel_state(trnf_data->session->channel) == AST_STATE_RING) {
2119  transfer_redirect(trnf_data->session, target);
2120  } else {
2121  transfer_refer(trnf_data->session, target);
2122  }
2123  }
2124 
2125  ao2_ref(trnf_data, -1);
2128  return 0;
2129 }
2130 
2131 /*! \brief Function called by core for Asterisk initiated transfer */
2132 static int chan_pjsip_transfer(struct ast_channel *chan, const char *target)
2133 {
2134  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);
2135  struct transfer_data *trnf_data = transfer_data_alloc(channel->session, target);
2136 
2137  if (!trnf_data) {
2138  return -1;
2139  }
2140 
2141  if (ast_sip_push_task(channel->session->serializer, transfer, trnf_data)) {
2142  ast_log(LOG_WARNING, "Error requesting transfer\n");
2143  ao2_cleanup(trnf_data);
2144  return -1;
2145  }
2146 
2147  return 0;
2148 }
2149 
2150 /*! \brief Function called by core to start a DTMF digit */
2151 static int chan_pjsip_digit_begin(struct ast_channel *chan, char digit)
2152 {
2153  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);
2154  struct ast_sip_session_media *media;
2155 
2157 
2158  switch (channel->session->dtmf) {
2159  case AST_SIP_DTMF_RFC_4733:
2160  if (!media || !media->rtp) {
2161  return 0;
2162  }
2163 
2165  break;
2166  case AST_SIP_DTMF_AUTO:
2167  if (!media || !media->rtp) {
2168  return 0;
2169  }
2170 
2172  return -1;
2173  }
2174 
2176  break;
2178  if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_NONE)) {
2179  return 0;
2180  }
2182  break;
2183  case AST_SIP_DTMF_NONE:
2184  break;
2185  case AST_SIP_DTMF_INBAND:
2186  return -1;
2187  default:
2188  break;
2189  }
2190 
2191  return 0;
2192 }
2193 
2196  char digit;
2197  unsigned int duration;
2198 };
2199 
2200 static void info_dtmf_data_destroy(void *obj)
2201 {
2202  struct info_dtmf_data *dtmf_data = obj;
2203  ao2_ref(dtmf_data->session, -1);
2204 }
2205 
2206 static struct info_dtmf_data *info_dtmf_data_alloc(struct ast_sip_session *session, char digit, unsigned int duration)
2207 {
2208  struct info_dtmf_data *dtmf_data = ao2_alloc(sizeof(*dtmf_data), info_dtmf_data_destroy);
2209  if (!dtmf_data) {
2210  return NULL;
2211  }
2212  ao2_ref(session, +1);
2213  dtmf_data->session = session;
2214  dtmf_data->digit = digit;
2215  dtmf_data->duration = duration;
2216  return dtmf_data;
2217 }
2218 
2219 static int transmit_info_dtmf(void *data)
2220 {
2221  RAII_VAR(struct info_dtmf_data *, dtmf_data, data, ao2_cleanup);
2222 
2223  struct ast_sip_session *session = dtmf_data->session;
2224  struct pjsip_tx_data *tdata;
2225 
2226  RAII_VAR(struct ast_str *, body_text, NULL, ast_free_ptr);
2227 
2228  struct ast_sip_body body = {
2229  .type = "application",
2230  .subtype = "dtmf-relay",
2231  };
2232 
2233  if (session->inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
2234  ast_log(LOG_ERROR, "Session already DISCONNECTED [reason=%d (%s)]\n",
2235  session->inv_session->cause,
2236  pjsip_get_status_text(session->inv_session->cause)->ptr);
2237  return -1;
2238  }
2239 
2240  if (!(body_text = ast_str_create(32))) {
2241  ast_log(LOG_ERROR, "Could not allocate buffer for INFO DTMF.\n");
2242  return -1;
2243  }
2244  ast_str_set(&body_text, 0, "Signal=%c\r\nDuration=%u\r\n", dtmf_data->digit, dtmf_data->duration);
2245 
2247 
2248  if (ast_sip_create_request("INFO", session->inv_session->dlg, session->endpoint, NULL, NULL, &tdata)) {
2249  ast_log(LOG_ERROR, "Could not create DTMF INFO request\n");
2250  return -1;
2251  }
2252  if (ast_sip_add_body(tdata, &body)) {
2253  ast_log(LOG_ERROR, "Could not add body to DTMF INFO request\n");
2254  pjsip_tx_data_dec_ref(tdata);
2255  return -1;
2256  }
2258 
2259  return 0;
2260 }
2261 
2262 /*! \brief Function called by core to stop a DTMF digit */
2263 static int chan_pjsip_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
2264 {
2265  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
2266  struct ast_sip_session_media *media;
2267 
2268  if (!channel || !channel->session) {
2269  /* This happens when the channel is hungup while a DTMF digit is playing. See ASTERISK-28086 */
2270  ast_debug(3, "Channel %s disappeared while calling digit_end\n", ast_channel_name(ast));
2271  return -1;
2272  }
2273 
2275 
2276  switch (channel->session->dtmf) {
2278  {
2279  if (!media || !media->rtp) {
2280  return 0;
2281  }
2282 
2284  ast_debug(3, "Told to send end of digit on Auto-Info channel %s RFC4733 negotiated so using it.\n", ast_channel_name(ast));
2286  break;
2287  }
2288  /* If RFC_4733 was not negotiated, fail through to the DTMF_INFO processing */
2289  ast_debug(3, "Told to send end of digit on Auto-Info channel %s RFC4733 NOT negotiated using INFO instead.\n", ast_channel_name(ast));
2290  }
2291 
2292  case AST_SIP_DTMF_INFO:
2293  {
2294  struct info_dtmf_data *dtmf_data = info_dtmf_data_alloc(channel->session, digit, duration);
2295 
2296  if (!dtmf_data) {
2297  return -1;
2298  }
2299 
2300  if (ast_sip_push_task(channel->session->serializer, transmit_info_dtmf, dtmf_data)) {
2301  ast_log(LOG_WARNING, "Error sending DTMF via INFO.\n");
2302  ao2_cleanup(dtmf_data);
2303  return -1;
2304  }
2305  break;
2306  }
2307  case AST_SIP_DTMF_RFC_4733:
2308  if (!media || !media->rtp) {
2309  return 0;
2310  }
2311 
2313  break;
2314  case AST_SIP_DTMF_AUTO:
2315  if (!media || !media->rtp) {
2316  return 0;
2317  }
2318 
2320  return -1;
2321  }
2322 
2324  break;
2325  case AST_SIP_DTMF_NONE:
2326  break;
2327  case AST_SIP_DTMF_INBAND:
2328  return -1;
2329  }
2330 
2331  return 0;
2332 }
2333 
2335 {
2337 
2338  /*
2339  * Use the channel CALLERID() as the initial connected line data.
2340  * The core or a predial handler may have supplied missing values
2341  * from the session->endpoint->id.self about who we are calling.
2342  */
2343  ast_channel_lock(session->channel);
2345  ast_channel_unlock(session->channel);
2346 
2347  /* Supply initial connected line information if available. */
2348  if (!session->id.number.valid && !session->id.name.valid) {
2349  return;
2350  }
2351 
2353  connected.id = session->id;
2355 
2357 }
2358 
2359 static int call(void *data)
2360 {
2361  struct ast_sip_channel_pvt *channel = data;
2362  struct ast_sip_session *session = channel->session;
2363  pjsip_tx_data *tdata;
2364  int res = 0;
2365  SCOPE_ENTER(1, "%s Topology: %s\n",
2367  ast_str_tmp(256, ast_stream_topology_to_str(channel->session->pending_media_state->topology, &STR_TMP))
2368  );
2369 
2370 
2371  res = ast_sip_session_create_invite(session, &tdata);
2372 
2373  if (res) {
2374  ast_set_hangupsource(session->channel, ast_channel_name(session->channel), 0);
2375  ast_queue_hangup(session->channel);
2376  } else {
2380  }
2381  ao2_ref(channel, -1);
2382  SCOPE_EXIT_RTN_VALUE(res, "RC: %d\n", res);
2383 }
2384 
2385 /*! \brief Function called by core to actually start calling a remote party */
2386 static int chan_pjsip_call(struct ast_channel *ast, const char *dest, int timeout)
2387 {
2388  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
2389  SCOPE_ENTER(1, "%s Topology: %s\n", ast_sip_session_get_name(channel->session),
2391 
2392  ao2_ref(channel, +1);
2393  if (ast_sip_push_task(channel->session->serializer, call, channel)) {
2394  ast_log(LOG_WARNING, "Error attempting to place outbound call to '%s'\n", dest);
2395  ao2_cleanup(channel);
2396  SCOPE_EXIT_RTN_VALUE(-1, "Couldn't push task\n");
2397  }
2398 
2399  SCOPE_EXIT_RTN_VALUE(0, "'call' task pushed\n");
2400 }
2401 
2402 /*! \brief Internal function which translates from Asterisk cause codes to SIP response codes */
2403 static int hangup_cause2sip(int cause)
2404 {
2405  switch (cause) {
2406  case AST_CAUSE_UNALLOCATED: /* 1 */
2407  case AST_CAUSE_NO_ROUTE_DESTINATION: /* 3 IAX2: Can't find extension in context */
2408  case AST_CAUSE_NO_ROUTE_TRANSIT_NET: /* 2 */
2409  return 404;
2410  case AST_CAUSE_CONGESTION: /* 34 */
2411  case AST_CAUSE_SWITCH_CONGESTION: /* 42 */
2412  return 503;
2413  case AST_CAUSE_NO_USER_RESPONSE: /* 18 */
2414  return 408;
2415  case AST_CAUSE_NO_ANSWER: /* 19 */
2416  case AST_CAUSE_UNREGISTERED: /* 20 */
2417  return 480;
2418  case AST_CAUSE_CALL_REJECTED: /* 21 */
2419  return 403;
2420  case AST_CAUSE_NUMBER_CHANGED: /* 22 */
2421  return 410;
2422  case AST_CAUSE_NORMAL_UNSPECIFIED: /* 31 */
2423  return 480;
2425  return 484;
2426  case AST_CAUSE_USER_BUSY:
2427  return 486;
2428  case AST_CAUSE_FAILURE:
2429  return 500;
2430  case AST_CAUSE_FACILITY_REJECTED: /* 29 */
2431  return 501;
2433  return 503;
2435  return 502;
2436  case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL: /* Can't find codec to connect to host */
2437  return 488;
2438  case AST_CAUSE_INTERWORKING: /* Unspecified Interworking issues */
2439  return 500;
2440  case AST_CAUSE_NOTDEFINED:
2441  default:
2442  ast_debug(1, "AST hangup cause %d (no match found in PJSIP)\n", cause);
2443  return 0;
2444  }
2445 
2446  /* Never reached */
2447  return 0;
2448 }
2449 
2450 struct hangup_data {
2451  int cause;
2453 };
2454 
2455 static void hangup_data_destroy(void *obj)
2456 {
2457  struct hangup_data *h_data = obj;
2458 
2459  h_data->chan = ast_channel_unref(h_data->chan);
2460 }
2461 
2463 {
2464  struct hangup_data *h_data = ao2_alloc(sizeof(*h_data), hangup_data_destroy);
2465 
2466  if (!h_data) {
2467  return NULL;
2468  }
2469 
2470  h_data->cause = cause;
2471  h_data->chan = ast_channel_ref(chan);
2472 
2473  return h_data;
2474 }
2475 
2476 /*! \brief Clear a channel from a session along with its PVT */
2478 {
2479  session->channel = NULL;
2482 }
2483 
2484 static int hangup(void *data)
2485 {
2486  struct hangup_data *h_data = data;
2487  struct ast_channel *ast = h_data->chan;
2488  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
2489  SCOPE_ENTER(1, "%s\n", ast_channel_name(ast));
2490 
2491  /*
2492  * Before cleaning we have to ensure that channel or its session is not NULL
2493  * we have seen rare case when taskprocessor calls hangup but channel is NULL
2494  * due to SIP session timeout and answer happening at the same time
2495  */
2496  if (channel) {
2497  struct ast_sip_session *session = channel->session;
2498  if (session) {
2499  int cause = h_data->cause;
2500 
2501  /*
2502  * It's possible that session_terminate might cause the session to be destroyed
2503  * immediately so we need to keep a reference to it so we can NULL session->channel
2504  * afterwards.
2505  */
2509  }
2511  }
2512  ao2_cleanup(h_data);
2514 }
2515 
2516 /*! \brief Function called by core to hang up a PJSIP session */
2517 static int chan_pjsip_hangup(struct ast_channel *ast)
2518 {
2519  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
2520  int cause;
2521  struct hangup_data *h_data;
2522  SCOPE_ENTER(1, "%s\n", ast_channel_name(ast));
2523 
2524  if (!channel || !channel->session) {
2525  SCOPE_EXIT_RTN_VALUE(-1, "No channel or session\n");
2526  }
2527 
2529  h_data = hangup_data_alloc(cause, ast);
2530 
2531  if (!h_data) {
2532  goto failure;
2533  }
2534 
2535  if (ast_sip_push_task(channel->session->serializer, hangup, h_data)) {
2536  ast_log(LOG_WARNING, "Unable to push hangup task to the threadpool. Expect bad things\n");
2537  goto failure;
2538  }
2539 
2540  SCOPE_EXIT_RTN_VALUE(0, "Cause: %d\n", cause);
2541 
2542 failure:
2543  /* Go ahead and do our cleanup of the session and channel even if we're not going
2544  * to be able to send our SIP request/response
2545  */
2546  clear_session_and_channel(channel->session, ast);
2547  ao2_cleanup(channel);
2548  ao2_cleanup(h_data);
2549 
2550  SCOPE_EXIT_RTN_VALUE(-1, "Cause: %d\n", cause);
2551 }
2552 
2556  const char *dest;
2557  int cause;
2558 };
2559 
2560 static int request(void *obj)
2561 {
2562  struct request_data *req_data = obj;
2563  struct ast_sip_session *session = NULL;
2564  char *tmp = ast_strdupa(req_data->dest), *endpoint_name = NULL, *request_user = NULL;
2565  struct ast_sip_endpoint *endpoint;
2566 
2568  AST_APP_ARG(endpoint);
2569  AST_APP_ARG(aor);
2570  );
2571  SCOPE_ENTER(1, "%s\n",tmp);
2572 
2573  if (ast_strlen_zero(tmp)) {
2574  ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty destination\n");
2576  SCOPE_EXIT_RTN_VALUE(-1, "Empty destination\n");
2577  }
2578 
2580 
2582  /* If a request user has been specified extract it from the endpoint name portion */
2583  if ((endpoint_name = strchr(args.endpoint, '@'))) {
2584  request_user = args.endpoint;
2585  *endpoint_name++ = '\0';
2586  } else {
2587  endpoint_name = args.endpoint;
2588  }
2589 
2590  if (ast_strlen_zero(endpoint_name)) {
2591  if (request_user) {
2592  ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name: %s@<endpoint-name>\n",
2593  request_user);
2594  } else {
2595  ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name\n");
2596  }
2598  SCOPE_EXIT_RTN_VALUE(-1, "Empty endpoint name\n");
2599  }
2600  endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
2601  endpoint_name);
2602  if (!endpoint) {
2603  ast_log(LOG_ERROR, "Unable to create PJSIP channel - endpoint '%s' was not found\n", endpoint_name);
2605  SCOPE_EXIT_RTN_VALUE(-1, "Endpoint not found\n");
2606  }
2607  } else {
2608  /* First try to find an exact endpoint match, for single (user) or multi-domain (user@domain) */
2609  endpoint_name = args.endpoint;
2610  if (ast_strlen_zero(endpoint_name)) {
2611  ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name\n");
2613  SCOPE_EXIT_RTN_VALUE(-1, "Empty endpoint name\n");
2614  }
2615  endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
2616  endpoint_name);
2617  if (!endpoint) {
2618  /* It seems it's not a multi-domain endpoint or single endpoint exact match,
2619  * it's possible that it's a SIP trunk with a specified user (user@trunkname),
2620  * so extract the user before @ sign.
2621  */
2622  endpoint_name = strchr(args.endpoint, '@');
2623  if (!endpoint_name) {
2624  /*
2625  * Couldn't find an '@' so it had to be an endpoint
2626  * name that doesn't exist.
2627  */
2628  ast_log(LOG_ERROR, "Unable to create PJSIP channel - endpoint '%s' was not found\n",
2629  args.endpoint);
2631  SCOPE_EXIT_RTN_VALUE(-1, "Endpoint not found\n");
2632  }
2633  request_user = args.endpoint;
2634  *endpoint_name++ = '\0';
2635 
2636  if (ast_strlen_zero(endpoint_name)) {
2637  ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name: %s@<endpoint-name>\n",
2638  request_user);
2640  SCOPE_EXIT_RTN_VALUE(-1, "Empty endpoint name\n");
2641  }
2642 
2643  endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
2644  endpoint_name);
2645  if (!endpoint) {
2646  ast_log(LOG_ERROR, "Unable to create PJSIP channel - endpoint '%s' was not found\n", endpoint_name);
2648  SCOPE_EXIT_RTN_VALUE(-1, "Endpoint not found\n");
2649  }
2650  }
2651  }
2652 
2653  session = ast_sip_session_create_outgoing(endpoint, NULL, args.aor, request_user,
2654  req_data->topology);
2655  ao2_ref(endpoint, -1);
2656  if (!session) {
2657  ast_log(LOG_ERROR, "Failed to create outgoing session to endpoint '%s'\n", endpoint_name);
2659  SCOPE_EXIT_RTN_VALUE(-1, "Couldn't create session\n");
2660  }
2661 
2662  req_data->session = session;
2663 
2665 }
2666 
2667 /*! \brief Function called by core to create a new outgoing PJSIP session */
2668 static struct ast_channel *chan_pjsip_request_with_stream_topology(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
2669 {
2670  struct request_data req_data;
2672  SCOPE_ENTER(1, "%s Topology: %s\n", data,
2674 
2675  req_data.topology = topology;
2676  req_data.dest = data;
2677  /* Default failure value in case ast_sip_push_task_wait_servant() itself fails. */
2678  req_data.cause = AST_CAUSE_FAILURE;
2679 
2680  if (ast_sip_push_task_wait_servant(NULL, request, &req_data)) {
2681  *cause = req_data.cause;
2682  SCOPE_EXIT_RTN_VALUE(NULL, "Couldn't push task\n");
2683  }
2684 
2685  session = req_data.session;
2686 
2687  if (!(session->channel = chan_pjsip_new(session, AST_STATE_DOWN, NULL, NULL, assignedids, requestor, NULL))) {
2688  /* Session needs to be terminated prematurely */
2689  SCOPE_EXIT_RTN_VALUE(NULL, "Couldn't create channel\n");
2690  }
2691 
2692  SCOPE_EXIT_RTN_VALUE(session->channel, "Channel: %s\n", ast_channel_name(session->channel));
2693 }
2694 
2695 static struct ast_channel *chan_pjsip_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
2696 {
2697  struct ast_stream_topology *topology;
2698  struct ast_channel *chan;
2699 
2701  if (!topology) {
2702  return NULL;
2703  }
2704 
2705  chan = chan_pjsip_request_with_stream_topology(type, topology, assignedids, requestor, data, cause);
2706 
2707  ast_stream_topology_free(topology);
2708 
2709  return chan;
2710 }
2711 
2715 };
2716 
2717 static void sendtext_data_destroy(void *obj)
2718 {
2719  struct sendtext_data *data = obj;
2720  ao2_cleanup(data->session);
2721  ast_free(data->msg);
2722 }
2723 
2724 static struct sendtext_data* sendtext_data_create(struct ast_channel *chan,
2725  struct ast_msg_data *msg)
2726 {
2727  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(chan);
2728  struct sendtext_data *data = ao2_alloc(sizeof(*data), sendtext_data_destroy);
2729 
2730  if (!data) {
2731  return NULL;
2732  }
2733 
2734  data->msg = ast_msg_data_dup(msg);
2735  if (!data->msg) {
2736  ao2_cleanup(data);
2737  return NULL;
2738  }
2739  data->session = channel->session;
2740  ao2_ref(data->session, +1);
2741 
2742  return data;
2743 }
2744 
2745 static int sendtext(void *obj)
2746 {
2747  struct sendtext_data *data = obj;
2748  pjsip_tx_data *tdata;
2749  const char *body_text = ast_msg_data_get_attribute(data->msg, AST_MSG_DATA_ATTR_BODY);
2750  const char *content_type = ast_msg_data_get_attribute(data->msg, AST_MSG_DATA_ATTR_CONTENT_TYPE);
2751  char *sep;
2752  struct ast_sip_body body = {
2753  .type = "text",
2754  .subtype = "plain",
2755  .body_text = body_text,
2756  };
2757 
2758  if (!ast_strlen_zero(content_type)) {
2759  sep = strchr(content_type, '/');
2760  if (sep) {
2761  *sep = '\0';
2762  body.type = content_type;
2763  body.subtype = ++sep;
2764  }
2765  }
2766 
2767  if (data->session->inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
2768  ast_log(LOG_ERROR, "Session already DISCONNECTED [reason=%d (%s)]\n",
2769  data->session->inv_session->cause,
2770  pjsip_get_status_text(data->session->inv_session->cause)->ptr);
2771  } else {
2772  pjsip_from_hdr *hdr;
2773  pjsip_name_addr *name_addr;
2774  const char *from = ast_msg_data_get_attribute(data->msg, AST_MSG_DATA_ATTR_FROM);
2775  const char *to = ast_msg_data_get_attribute(data->msg, AST_MSG_DATA_ATTR_TO);
2776  int invalidate_tdata = 0;
2777 
2778  ast_sip_create_request("MESSAGE", data->session->inv_session->dlg, data->session->endpoint, NULL, NULL, &tdata);
2779  ast_sip_add_body(tdata, &body);
2780 
2781  /*
2782  * If we have a 'from' in the msg, set the display name in the From
2783  * header to it.
2784  */
2785  if (!ast_strlen_zero(from)) {
2786  hdr = PJSIP_MSG_FROM_HDR(tdata->msg);
2787  name_addr = (pjsip_name_addr *) hdr->uri;
2788  pj_strdup2(tdata->pool, &name_addr->display, from);
2789  invalidate_tdata = 1;
2790  }
2791 
2792  /*
2793  * If we have a 'to' in the msg, set the display name in the To
2794  * header to it.
2795  */
2796  if (!ast_strlen_zero(to)) {
2797  hdr = PJSIP_MSG_TO_HDR(tdata->msg);
2798  name_addr = (pjsip_name_addr *) hdr->uri;
2799  pj_strdup2(tdata->pool, &name_addr->display, to);
2800  invalidate_tdata = 1;
2801  }
2802 
2803  if (invalidate_tdata) {
2804  pjsip_tx_data_invalidate_msg(tdata);
2805  }
2806 
2807  ast_sip_send_request(tdata, data->session->inv_session->dlg, data->session->endpoint, NULL, NULL);
2808  }
2809 
2810  ao2_cleanup(data);
2811 
2812  return 0;
2813 }
2814 
2815 /*! \brief Function called by core to send text on PJSIP session */
2816 static int chan_pjsip_sendtext_data(struct ast_channel *ast, struct ast_msg_data *msg)
2817 {
2818  struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
2819  struct sendtext_data *data = sendtext_data_create(ast, msg);
2820 
2821  ast_debug(1, "Sending MESSAGE from '%s' to '%s:%s': %s\n",
2824  ast_channel_name(ast),
2826 
2827  if (!data) {
2828  return -1;
2829  }
2830 
2831  if (ast_sip_push_task(channel->session->serializer, sendtext, data)) {
2832  ao2_ref(data, -1);
2833  return -1;
2834  }
2835  return 0;
2836 }
2837 
2838 static int chan_pjsip_sendtext(struct ast_channel *ast, const char *text)
2839 {
2840  struct ast_msg_data *msg;
2841  int rc;
2842  struct ast_msg_data_attribute attrs[] =
2843  {
2844  {
2846  .value = (char *)text,
2847  }
2848  };
2849 
2851  if (!msg) {
2852  return -1;
2853  }
2854  rc = chan_pjsip_sendtext_data(ast, msg);
2855  ast_free(msg);
2856 
2857  return rc;
2858 }
2859 
2860 /*! \brief Convert SIP hangup causes to Asterisk hangup causes */
2861 static int hangup_sip2cause(int cause)
2862 {
2863  /* Possible values taken from causes.h */
2864 
2865  switch(cause) {
2866  case 401: /* Unauthorized */
2867  return AST_CAUSE_CALL_REJECTED;
2868  case 403: /* Not found */
2869  return AST_CAUSE_CALL_REJECTED;
2870  case 404: /* Not found */
2871  return AST_CAUSE_UNALLOCATED;
2872  case 405: /* Method not allowed */
2873  return AST_CAUSE_INTERWORKING;
2874  case 407: /* Proxy authentication required */
2875  return AST_CAUSE_CALL_REJECTED;
2876  case 408: /* No reaction */
2878  case 409: /* Conflict */
2880  case 410: /* Gone */
2881  return AST_CAUSE_NUMBER_CHANGED;
2882  case 411: /* Length required */
2883  return AST_CAUSE_INTERWORKING;
2884  case 413: /* Request entity too large */
2885  return AST_CAUSE_INTERWORKING;
2886  case 414: /* Request URI too large */
2887  return AST_CAUSE_INTERWORKING;
2888  case 415: /* Unsupported media type */
2889  return AST_CAUSE_INTERWORKING;
2890  case 420: /* Bad extension */
2892  case 480: /* No answer */
2893  return AST_CAUSE_NO_ANSWER;
2894  case 481: /* No answer */
2895  return AST_CAUSE_INTERWORKING;
2896  case 482: /* Loop detected */
2897  return AST_CAUSE_INTERWORKING;
2898  case 483: /* Too many hops */
2899  return AST_CAUSE_NO_ANSWER;
2900  case 484: /* Address incomplete */
2902  case 485: /* Ambiguous */
2903  return AST_CAUSE_UNALLOCATED;
2904  case 486: /* Busy everywhere */
2905  return AST_CAUSE_BUSY;
2906  case 487: /* Request terminated */
2907  return AST_CAUSE_INTERWORKING;
2908  case 488: /* No codecs approved */
2910  case 491: /* Request pending */
2911  return AST_CAUSE_INTERWORKING;
2912  case 493: /* Undecipherable */
2913  return AST_CAUSE_INTERWORKING;
2914  case 500: /* Server internal failure */
2915  return AST_CAUSE_FAILURE;
2916  case 501: /* Call rejected */
2918  case 502:
2920  case 503: /* Service unavailable */
2921  return AST_CAUSE_CONGESTION;
2922  case 504: /* Gateway timeout */
2924  case 505: /* SIP version not supported */
2925  return AST_CAUSE_INTERWORKING;
2926  case 600: /* Busy everywhere */
2927  return AST_CAUSE_USER_BUSY;
2928  case 603: /* Decline */
2929  return AST_CAUSE_CALL_REJECTED;
2930  case 604: /* Does not exist anywhere */
2931  return AST_CAUSE_UNALLOCATED;
2932  case 606: /* Not acceptable */
2934  default:
2935  if (cause < 500 && cause >= 400) {
2936  /* 4xx class error that is unknown - someting wrong with our request */
2937  return AST_CAUSE_INTERWORKING;
2938  } else if (cause < 600 && cause >= 500) {
2939  /* 5xx class error - problem in the remote end */
2940  return AST_CAUSE_CONGESTION;
2941  } else if (cause < 700 && cause >= 600) {
2942  /* 6xx - global errors in the 4xx class */
2943  return AST_CAUSE_INTERWORKING;
2944  }
2945  return AST_CAUSE_NORMAL;
2946  }
2947  /* Never reached */
2948  return 0;
2949 }
2950 
2952 {
2953  RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
2955 
2956  if (session->endpoint->media.direct_media.glare_mitigation ==
2958  SCOPE_EXIT_RTN("Direct media no glare mitigation\n");
2959  }
2960 
2962  "direct_media_glare_mitigation");
2963 
2964  if (!datastore) {
2965  SCOPE_EXIT_RTN("Couldn't create datastore\n");
2966  }
2967 
2969  SCOPE_EXIT_RTN();
2970 }
2971 
2972 /*! \brief Function called when the session ends */
2974 {
2976 
2977  if (!session->channel) {
2978  SCOPE_EXIT_RTN("No channel\n");
2979  }
2980 
2982 
2983  ast_set_hangupsource(session->channel, ast_channel_name(session->channel), 0);
2984  if (!ast_channel_hangupcause(session->channel) && session->inv_session) {
2985  int cause = hangup_sip2cause(session->inv_session->cause);
2986 
2987  ast_queue_hangup_with_cause(session->channel, cause);
2988  } else {
2989  ast_queue_hangup(session->channel);
2990  }
2991 
2992  SCOPE_EXIT_RTN();
2993 }
2994 
2996 {
2997  pjsip_sip_uri *sip_ruri = pjsip_uri_get_uri(session->request_uri);
2998  size_t size = pj_strlen(&sip_ruri->host) + 1;
2999  char *domain = ast_alloca(size);
3000 
3001  ast_copy_pj_str(domain, &sip_ruri->host, size);
3002 
3003  pbx_builtin_setvar_helper(session->channel, "SIPDOMAIN", domain);
3004  return;
3005 }
3006 
3007 /*! \brief Function called when a request is received on the session */
3008 static int chan_pjsip_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
3009 {
3010  RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
3011  struct transport_info_data *transport_data;
3012  pjsip_tx_data *packet = NULL;
3014 
3015  if (session->channel) {
3016  SCOPE_EXIT_RTN_VALUE(0, "%s: No channel\n", ast_sip_session_get_name(session));
3017  }
3018 
3019  /* Check for a to-tag to determine if this is a reinvite */
3020  if (rdata->msg_info.to->tag.slen) {
3021  /* Weird case. We've received a reinvite but we don't have a channel. The most
3022  * typical case for this happening is that a blind transfer fails, and so the
3023  * transferer attempts to reinvite himself back into the call. We already got
3024  * rid of that channel, and the other side of the call is unrecoverable.
3025  *
3026  * We treat this as a failure, so our best bet is to just hang this call
3027  * up and not create a new channel. Clearing defer_terminate here ensures that
3028  * calling ast_sip_session_terminate() can result in a BYE being sent ASAP.
3029  */
3030  session->defer_terminate = 0;
3032  SCOPE_EXIT_RTN_VALUE(-1, "%s: We have a To tag but no channel. Terminating session\n", ast_sip_session_get_name(session));
3033  }
3034 
3035  datastore = ast_sip_session_alloc_datastore(&transport_info, "transport_info");
3036  if (!datastore) {
3037  SCOPE_EXIT_LOG_RTN_VALUE(-1, LOG_ERROR, "%s: Couldn't alloc transport_info datastore\n", ast_sip_session_get_name(session));
3038  }
3039 
3040  transport_data = ast_calloc(1, sizeof(*transport_data));
3041  if (!transport_data) {
3042  SCOPE_EXIT_LOG_RTN_VALUE(-1, LOG_ERROR, "%s: Couldn't alloc transport_info\n", ast_sip_session_get_name(session));
3043  }
3044  pj_sockaddr_cp(&transport_data->local_addr, &rdata->tp_info.transport->local_addr);
3045  pj_sockaddr_cp(&transport_data->remote_addr, &rdata->pkt_info.src_addr);
3046  datastore->data = transport_data;
3048 
3049  if (!(session->channel = chan_pjsip_new(session, AST_STATE_RING, session->exten, NULL, NULL, NULL, NULL))) {
3050  if (pjsip_inv_end_session(session->inv_session, 503, NULL, &packet) == PJ_SUCCESS
3051  && packet) {
3053  }
3054 
3055  SCOPE_EXIT_LOG_RTN_VALUE(-1, LOG_ERROR, "%s: Failed to allocate new PJSIP channel on incoming SIP INVITE\n",
3057  }
3058 
3060 
3061  /* channel gets created on incoming request, but we wait to call start
3062  so other supplements have a chance to run */
3064 }
3065 
3066 static int call_pickup_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
3067 {
3068  struct ast_features_pickup_config *pickup_cfg;
3069  struct ast_channel *chan;
3070 
3071  /* Check for a to-tag to determine if this is a reinvite */
3072  if (rdata->msg_info.to->tag.slen) {
3073  /* We don't care about reinvites */
3074  return 0;
3075  }
3076 
3077  pickup_cfg = ast_get_chan_features_pickup_config(session->channel);
3078  if (!pickup_cfg) {
3079  ast_log(LOG_ERROR, "Unable to retrieve pickup configuration options. Unable to detect call pickup extension.\n");
3080  return 0;
3081  }
3082 
3083  if (strcmp(session->exten, pickup_cfg->pickupexten)) {
3084  ao2_ref(pickup_cfg, -1);
3085  return 0;
3086  }
3087  ao2_ref(pickup_cfg, -1);
3088 
3089  /* We can't directly use session->channel because the pickup operation will cause a masquerade to occur,
3090  * changing the channel pointer in session to a different channel. To ensure we work on the right channel
3091  * we store a pointer locally before we begin and keep a reference so it remains valid no matter what.
3092  */
3093  chan = ast_channel_ref(session->channel);
3094  if (ast_pickup_call(chan)) {
3096  } else {
3098  }
3099  /* A hangup always occurs because the pickup operation will have either failed resulting in the call
3100  * needing to be hung up OR the pickup operation was a success and the channel we now have is actually
3101  * the channel that was replaced, which should be hung up since it is literally in limbo not connected
3102  * to anything at all.
3103  */
3104  ast_hangup(chan);
3105  ast_channel_unref(chan);
3106 
3107  return 1;
3108 }
3109 
3111  .method = "INVITE",
3112  .priority = AST_SIP_SUPPLEMENT_PRIORITY_LAST - 1,
3113  .incoming_request = call_pickup_incoming_request,
3114 };
3115 
3116 static int pbx_start_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
3117 {
3118  int res;
3120 
3121  /* Check for a to-tag to determine if this is a reinvite */
3122  if (rdata->msg_info.to->tag.slen) {
3123  /* We don't care about reinvites */
3124  SCOPE_EXIT_RTN_VALUE(0, "Reinvite\n");
3125  }
3126 
3127  res = ast_pbx_start(session->channel);
3128 
3129  switch (res) {
3130  case AST_PBX_FAILED:
3131  ast_log(LOG_WARNING, "Failed to start PBX ;(\n");
3133  ast_hangup(session->channel);
3134  break;
3135  case AST_PBX_CALL_LIMIT:
3136  ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n");
3138  ast_hangup(session->channel);
3139  break;
3140  case AST_PBX_SUCCESS:
3141  default:
3142  break;
3143  }
3144 
3145  ast_debug(3, "Started PBX on new PJSIP channel %s\n", ast_channel_name(session->channel));
3146 
3147  SCOPE_EXIT_RTN_VALUE((res == AST_PBX_SUCCESS) ? 0 : -1, "RC: %d\n", res);
3148 }
3149 
3151  .method = "INVITE",
3153  .incoming_request = pbx_start_incoming_request,
3154 };
3155 
3156 /*! \brief Function called when a response is received on the session */
3157 static void chan_pjsip_incoming_response_update_cause(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
3158 {
3159  struct pjsip_status_line status = rdata->msg_info.msg->line.status;
3160  struct ast_control_pvt_cause_code *cause_code;
3161  int data_size = sizeof(*cause_code);
3162  SCOPE_ENTER(3, "%s: Status: %d\n", ast_sip_session_get_name(session), status.code);
3163 
3164  if (!session->channel) {
3165  SCOPE_EXIT_RTN("%s: No channel\n", ast_sip_session_get_name(session));
3166  }
3167 
3168  /* Build and send the tech-specific cause information */
3169  /* size of the string making up the cause code is "SIP " number + " " + reason length */
3170  data_size += 4 + 4 + pj_strlen(&status.reason);
3171  cause_code = ast_alloca(data_size);
3172  memset(cause_code, 0, data_size);
3173 
3175 
3176  snprintf(cause_code->code, data_size - sizeof(*cause_code) + 1, "SIP %d %.*s", status.code,
3177  (int) pj_strlen(&status.reason), pj_strbuf(&status.reason));
3178 
3179  cause_code->ast_cause = hangup_sip2cause(status.code);
3180  ast_queue_control_data(session->channel, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
3181  ast_channel_hangupcause_hash_set(session->channel, cause_code, data_size);
3182 
3184 }
3185 
3186 /*! \brief Function called when a response is received on the session */
3187 static void chan_pjsip_incoming_response(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
3188 {
3189  struct pjsip_status_line status = rdata->msg_info.msg->line.status;
3190  SCOPE_ENTER(3, "%s: Status: %d\n", ast_sip_session_get_name(session), status.code);
3191 
3192  if (!session->channel) {
3193  SCOPE_EXIT_RTN("%s: No channel\n", ast_sip_session_get_name(session));
3194  }
3195 
3196  switch (status.code) {
3197  case 180: {
3198  pjsip_rdata_sdp_info *sdp = pjsip_rdata_get_sdp_info(rdata);
3199  if (sdp && sdp->body.ptr) {
3200  ast_trace(-1, "%s: Queueing PROGRESS\n", ast_sip_session_get_name(session));
3202  } else {
3203  ast_trace(-1, "%s: Queueing RINGING\n", ast_sip_session_get_name(session));
3205  }
3206 
3207  ast_channel_lock(session->channel);
3208  if (ast_channel_state(session->channel) != AST_STATE_UP) {
3210  }
3211  ast_channel_unlock(session->channel);
3212  break;
3213  }
3214  case 183:
3215  if (session->endpoint->ignore_183_without_sdp) {
3216  pjsip_rdata_sdp_info *sdp = pjsip_rdata_get_sdp_info(rdata);
3217  if (sdp && sdp->body.ptr) {
3218  ast_trace(-1, "%s: Queueing PROGRESS\n", ast_sip_session_get_name(session));
3219  ast_trace(1, "%s Method: %.*s Status: %d Queueing PROGRESS with SDP\n", ast_sip_session_get_name(session),
3220  (int)rdata->msg_info.cseq->method.name.slen, rdata->msg_info.cseq->method.name.ptr, status.code);
3222  }
3223  } else {
3224  ast_trace(-1, "%s: Queueing PROGRESS\n", ast_sip_session_get_name(session));
3225  ast_trace(1, "%s Method: %.*s Status: %d Queueing PROGRESS without SDP\n", ast_sip_session_get_name(session),
3226  (int)rdata->msg_info.cseq->method.name.slen, rdata->msg_info.cseq->method.name.ptr, status.code);
3228  }
3229  break;
3230  case 200:
3231  ast_trace(-1, "%s: Queueing ANSWER\n", ast_sip_session_get_name(session));
3233  break;
3234  default:
3235  ast_trace(-1, "%s: Not queueing anything\n", ast_sip_session_get_name(session));
3236  break;
3237  }
3238 
3240 }
3241 
3242 static int chan_pjsip_incoming_ack(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
3243 {
3245 
3246  if (rdata->msg_info.msg->line.req.method.id == PJSIP_ACK_METHOD) {
3247  if (session->endpoint->media.direct_media.enabled && session->channel) {
3248  ast_trace(-1, "%s: Queueing SRCCHANGE\n", ast_sip_session_get_name(session));
3250  }
3251  }
3253 }
3254 
3255 static int update_devstate(void *obj, void *arg, int flags)
3256 {
3258  "PJSIP/%s", ast_sorcery_object_get_id(obj));
3259  return 0;
3260 }
3261 
3263  .name = "PJSIP_DIAL_CONTACTS",
3265 };
3266 
3268  .name = "PJSIP_PARSE_URI",
3269  .read = pjsip_acf_parse_uri_read,
3270 };
3271 
3272 static struct ast_custom_function media_offer_function = {
3273  .name = "PJSIP_MEDIA_OFFER",
3276 };
3277 
3278 static struct ast_custom_function dtmf_mode_function = {
3279  .name = "PJSIP_DTMF_MODE",
3280  .read = pjsip_acf_dtmf_mode_read,
3281  .write = pjsip_acf_dtmf_mode_write
3282 };
3283 
3285  .name = "PJSIP_MOH_PASSTHROUGH",
3288 };
3289 
3291  .name = "PJSIP_SEND_SESSION_REFRESH",
3293 };
3294 
3295 /*!
3296  * \brief Load the module
3297  *
3298  * Module loading including tests for configuration or dependencies.
3299  * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
3300  * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
3301  * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
3302  * configuration file or other non-critical problem return
3303  * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
3304  */
3305 static int load_module(void)
3306 {
3307  struct ao2_container *endpoints;
3308 
3310  return AST_MODULE_LOAD_DECLINE;
3311  }
3312 
3314 
3316 
3318  ast_log(LOG_ERROR, "Unable to register channel class %s\n", channel_type);
3319  goto end;
3320  }
3321 
3323  ast_log(LOG_ERROR, "Unable to register PJSIP_DIAL_CONTACTS dialplan function\n");
3324  goto end;
3325  }
3326 
3328  ast_log(LOG_ERROR, "Unable to register PJSIP_PARSE_URI dialplan function\n");
3329  goto end;
3330  }
3331 
3333  ast_log(LOG_WARNING, "Unable to register PJSIP_MEDIA_OFFER dialplan function\n");
3334  goto end;
3335  }
3336 
3338  ast_log(LOG_WARNING, "Unable to register PJSIP_DTMF_MODE dialplan function\n");
3339  goto end;
3340  }
3341 
3343  ast_log(LOG_WARNING, "Unable to register PJSIP_MOH_PASSTHROUGH dialplan function\n");
3344  goto end;
3345  }
3346 
3348  ast_log(LOG_WARNING, "Unable to register PJSIP_SEND_SESSION_REFRESH dialplan function\n");
3349  goto end;
3350  }
3351 
3353 
3356 
3359  uid_hold_sort_fn, NULL))) {
3360  ast_log(LOG_ERROR, "Unable to create held channels container\n");
3361  goto end;
3362  }
3363 
3367 
3369  ast_log(LOG_ERROR, "Unable to register PJSIP Channel CLI\n");
3370  goto end;
3371  }
3372 
3373  /* since endpoints are loaded before the channel driver their device
3374  states get set to 'invalid', so they need to be updated */
3375  if ((endpoints = ast_sip_get_endpoints())) {
3377  ao2_ref(endpoints, -1);
3378  }
3379 
3380  return 0;
3381 
3382 end:
3399 
3400  return AST_MODULE_LOAD_DECLINE;
3401 }
3402 
3403 /*! \brief Unload the PJSIP channel from Asterisk */
3404 static int unload_module(void)
3405 {
3408 
3410 
3416 
3418 
3425 
3429 
3430  return 0;
3431 }
3432 
3434  .support_level = AST_MODULE_SUPPORT_CORE,
3435  .load = load_module,
3436  .unload = unload_module,
3437  .load_pri = AST_MODPRI_CHANNEL_DRIVER,
3438  .requires = "res_pjsip,res_pjsip_session,res_pjsip_pubsub",
3439 );
Access Control of various sorts.
char digit
jack_status_t status
Definition: app_jack.c:146
char * text
Definition: app_queue.c:1517
#define var
Definition: ast_expr2f.c:614
Asterisk main include file. File version handling, generic pbx functions.
static struct ast_mansession session
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
#define ast_free(a)
Definition: astmm.h:182
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define ast_log
Definition: astobj2.c:42
#define ao2_link(container, obj)
Definition: astobj2.h:1549
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:369
@ AO2_ALLOC_OPT_LOCK_RWLOCK
Definition: astobj2.h:367
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define ao2_bump(obj)
Definition: astobj2.h:491
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
@ OBJ_NODATA
Definition: astobj2.h:1048
@ OBJ_SEARCH_MASK
Search option field mask.
Definition: astobj2.h:1076
@ OBJ_UNLINK
Definition: astobj2.h:1043
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
@ AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT
Reject objects with duplicate keys in container.
Definition: astobj2.h:1192
static int tmp()
Definition: bt_open.c:389
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
#define AST_PRES_ALLOWED
Definition: callerid.h:324
@ AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER
Definition: callerid.h:446
#define AST_PRES_RESTRICTION
Definition: callerid.h:323
Internal Asterisk hangup causes.
#define AST_CAUSE_SWITCH_CONGESTION
Definition: causes.h:122
#define AST_CAUSE_CONGESTION
Definition: causes.h:152
#define AST_CAUSE_UNALLOCATED
Definition: causes.h:97
#define AST_CAUSE_INTERWORKING
Definition: causes.h:145
#define AST_CAUSE_NUMBER_CHANGED
Definition: causes.h:111
#define AST_CAUSE_BEARERCAPABILITY_NOTAVAIL
Definition: causes.h:129
#define AST_CAUSE_INVALID_NUMBER_FORMAT
Definition: causes.h:115
#define AST_CAUSE_CHAN_NOT_IMPLEMENTED
Definition: causes.h:131
#define AST_CAUSE_FAILURE
Definition: causes.h:149
#define AST_CAUSE_DESTINATION_OUT_OF_ORDER
Definition: causes.h:114
#define AST_CAUSE_NO_USER_RESPONSE
Definition: causes.h:107
#define AST_CAUSE_NORMAL_TEMPORARY_FAILURE
Definition: causes.h:121
#define AST_CAUSE_NORMAL
Definition: causes.h:150
#define AST_CAUSE_CHANNEL_UNACCEPTABLE
Definition: causes.h:101
#define AST_CAUSE_NOTDEFINED
Definition: causes.h:154
#define AST_CAUSE_CALL_REJECTED
Definition: causes.h:110
#define AST_CAUSE_FACILITY_REJECTED
Definition: causes.h:116
#define AST_CAUSE_NORMAL_UNSPECIFIED
Definition: causes.h:118
#define AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE
Definition: causes.h:142
#define AST_CAUSE_NO_ROUTE_TRANSIT_NET
Definition: causes.h:98
#define AST_CAUSE_NO_ROUTE_DESTINATION
Definition: causes.h:99
#define AST_CAUSE_UNREGISTERED
Definition: causes.h:153
#define AST_CAUSE_BUSY
Definition: causes.h:148
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:108
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
#define AST_CAUSE_USER_BUSY
Definition: causes.h:106
static PGresult * result
Definition: cel_pgsql.c:88
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:122
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:168
static const char type[]
Definition: chan_ooh323.c:109
#define T38_ENABLED
Definition: chan_ooh323.c:102
static void transfer_data_destroy(void *obj)
Definition: chan_pjsip.c:1851
static int chan_pjsip_incoming_ack(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
Definition: chan_pjsip.c:3242
static struct ast_datastore_info direct_media_mitigation_info
Definition: chan_pjsip.c:266
static void chan_pjsip_get_codec(struct ast_channel *chan, struct ast_format_cap *result)
Function called by RTP engine to get peer capabilities.
Definition: chan_pjsip.c:244
static struct ast_datastore_info transport_info
Datastore used to store local/remote addresses for the INVITE request that created the PJSIP channel.
Definition: chan_pjsip.c:261
static void xfer_client_on_evsub_state(pjsip_evsub *sub, pjsip_event *event)
Callback function to report status of implicit REFER-NOTIFY subscription.
Definition: chan_pjsip.c:1928
static int hangup_cause2sip(int cause)
Internal function which translates from Asterisk cause codes to SIP response codes.
Definition: chan_pjsip.c:2403
static int remote_send_hold_refresh(struct ast_sip_session *session, unsigned int held)
Update local hold state and send a re-INVITE with the new SDP.
Definition: chan_pjsip.c:1491
static int check_for_rtp_changes(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_sip_session_media *media, struct ast_sip_session *session)
Definition: chan_pjsip.c:319
static struct ast_channel * chan_pjsip_new(struct ast_sip_session *session, int state, const char *exten, const char *title, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *cid_name)
Function called to create a new PJSIP Asterisk channel.
Definition: chan_pjsip.c:547
static int chan_pjsip_devicestate(const char *data)
Function called to get the device state of an endpoint.
Definition: chan_pjsip.c:1175
static int uid_hold_sort_fn(const void *obj_left, const void *obj_right, const int flags)
Definition: chan_pjsip.c:1085
static int chan_pjsip_transfer(struct ast_channel *ast, const char *target)
Function called by core for Asterisk initiated transfer.
Definition: chan_pjsip.c:2132
static int update_connected_line_information(void *data)
Update connected line information.
Definition: chan_pjsip.c:1430
static void transfer_redirect(struct ast_sip_session *session, const char *target)
Definition: chan_pjsip.c:1878
static void clear_session_and_channel(struct ast_sip_session *session, struct ast_channel *ast)
Clear a channel from a session along with its PVT.
Definition: chan_pjsip.c:2477
static void chan_pjsip_session_end(struct ast_sip_session *session)
Function called when the session ends.
Definition: chan_pjsip.c:2973
static int sendtext(void *obj)
Definition: chan_pjsip.c:2745
static void update_initial_connected_line(struct ast_sip_session *session)
Definition: chan_pjsip.c:2334
static struct topology_change_refresh_data * topology_change_refresh_data_alloc(struct ast_sip_session *session, const struct ast_stream_topology *topology)
Definition: chan_pjsip.c:1525
static int update_devstate(void *obj, void *arg, int flags)
Definition: chan_pjsip.c:3255
static struct ast_sip_session_supplement chan_pjsip_supplement
SIP session supplement structure.
Definition: chan_pjsip.c:143
static int remote_send_unhold(void *data)
Update local hold state to be unheld.
Definition: chan_pjsip.c:1507
static struct sendtext_data * sendtext_data_create(struct ast_channel *chan, struct ast_msg_data *msg)
Definition: chan_pjsip.c:2724
static void rtp_direct_media_data_destroy(void *data)
Definition: chan_pjsip.c:366
static int chan_pjsip_call(struct ast_channel *ast, const char *dest, int timeout)
Function called by core to actually start calling a remote party.
Definition: chan_pjsip.c:2386
static int direct_media_mitigate_glare(struct ast_sip_session *session)
Definition: chan_pjsip.c:268
static int chan_pjsip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *tpeer, const struct ast_format_cap *cap, int nat_active)
Function called by RTP engine to change where the remote party should send media.
Definition: chan_pjsip.c:448
static int request(void *obj)
Definition: chan_pjsip.c:2560
static int chan_pjsip_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
Function called by core to ask the channel to indicate some sort of condition.
Definition: chan_pjsip.c:1613
static int chan_pjsip_hangup(struct ast_channel *ast)
Function called by core to hang up a PJSIP session.
Definition: chan_pjsip.c:2517
static void chan_pjsip_pvt_dtor(void *obj)
Definition: chan_pjsip.c:82
static int handle_topology_request_change(struct ast_sip_session *session, const struct ast_stream_topology *proposed)
Definition: chan_pjsip.c:1593
static enum ast_rtp_glue_result chan_pjsip_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
Function called by RTP engine to get local audio RTP peer.
Definition: chan_pjsip.c:171
static struct ast_channel * chan_pjsip_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
Asterisk core interaction functions.
Definition: chan_pjsip.c:2695
static struct ast_custom_function chan_pjsip_dial_contacts_function
Definition: chan_pjsip.c:3262
static int send_topology_change_refresh(void *data)
Definition: chan_pjsip.c:1576
static int indicate(void *data)
Definition: chan_pjsip.c:1334
static int remote_send_hold(void *data)
Update local hold state to be held.
Definition: chan_pjsip.c:1501
static int on_topology_change_response(struct ast_sip_session *session, pjsip_rx_data *rdata)
Definition: chan_pjsip.c:1550
static struct ao2_container * pjsip_uids_onhold
Definition: chan_pjsip.c:1108
static int chan_pjsip_queryoption(struct ast_channel *ast, int option, void *data, int *datalen)
Function called to query options on a channel.
Definition: chan_pjsip.c:1238
static int chan_pjsip_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
Function called when a request is received on the session.
Definition: chan_pjsip.c:3008
struct ast_channel_tech chan_pjsip_tech
PBX interface structure for channel registration.
Definition: chan_pjsip.c:109
static void set_channel_on_rtp_instance(const struct ast_sip_session *session, const char *channel_id)
Definition: chan_pjsip.c:494
static struct ast_channel * chan_pjsip_request_with_stream_topology(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
Function called by core to create a new outgoing PJSIP session.
Definition: chan_pjsip.c:2668
static int uid_hold_hash_fn(const void *obj, const int flags)
Definition: chan_pjsip.c:1067
static struct ast_sip_session_supplement pbx_start_supplement
Definition: chan_pjsip.c:3150
static int chan_pjsip_digit_begin(struct ast_channel *ast, char digit)
Function called by core to start a DTMF digit.
Definition: chan_pjsip.c:2151
static struct transfer_data * transfer_data_alloc(struct ast_sip_session *session, const char *target)
Definition: chan_pjsip.c:1859
static void chan_pjsip_session_begin(struct ast_sip_session *session)
SIP session interaction functions.
Definition: chan_pjsip.c:2951
static void topology_change_refresh_data_free(struct topology_change_refresh_data *refresh_data)
Definition: chan_pjsip.c:1517
static int hangup_sip2cause(int cause)
Convert SIP hangup causes to Asterisk hangup causes.
Definition: chan_pjsip.c:2861
static void transport_info_destroy(void *obj)
Destructor function for transport_info_data.
Definition: chan_pjsip.c:253
static int send_direct_media_request(void *data)
Definition: chan_pjsip.c:396
static struct hangup_data * hangup_data_alloc(int cause, struct ast_channel *chan)
Definition: chan_pjsip.c:2462
static int chan_pjsip_sendtext_data(struct ast_channel *ast, struct ast_msg_data *msg)
Function called by core to send text on PJSIP session.
Definition: chan_pjsip.c:2816
static struct ast_rtp_glue chan_pjsip_rtp_glue
Local glue for interacting with the RTP engine core.
Definition: chan_pjsip.c:486
static pjsip_module refer_callback_module
REFER Callback module, used to attach session data structure to subscription.
Definition: chan_pjsip.c:1916
static int call_pickup_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
Definition: chan_pjsip.c:3066
static enum ast_rtp_glue_result chan_pjsip_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
Function called by RTP engine to get local video RTP peer.
Definition: chan_pjsip.c:215
static int rtp_find_rtcp_fd_position(struct ast_sip_session *session, struct ast_rtp_instance *rtp)
Helper function to find the position for RTCP.
Definition: chan_pjsip.c:298
static int transfer(void *data)
Definition: chan_pjsip.c:2097
static const char channel_type[]
Definition: chan_pjsip.c:78
static void chan_pjsip_remove_hold(const char *chan_uid)
Remove a channel ID from the list of PJSIP channels on hold.
Definition: chan_pjsip.c:1149
static int hangup(void *data)
Definition: chan_pjsip.c:2484
static int transmit_info_with_vidupdate(void *data)
Send SIP INFO with video update request.
Definition: chan_pjsip.c:1352
static void sendtext_data_destroy(void *obj)
Definition: chan_pjsip.c:2717
static struct ast_custom_function moh_passthrough_function
Definition: chan_pjsip.c:3284
static void chan_pjsip_incoming_response_update_cause(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
Function called when a response is received on the session.
Definition: chan_pjsip.c:3157
static struct ast_frame * chan_pjsip_cng_tone_detected(struct ast_channel *ast, struct ast_sip_session *session, struct ast_frame *f)
Internal helper function called when CNG tone is detected.
Definition: chan_pjsip.c:766
static int chan_pjsip_write_stream(struct ast_channel *ast, int stream_num, struct ast_frame *f)
Definition: chan_pjsip.c:950
static int answer(void *data)
Definition: chan_pjsip.c:683
static int transmit_info_dtmf(void *data)
Definition: chan_pjsip.c:2219
static struct ast_custom_function media_offer_function
Definition: chan_pjsip.c:3272
static int chan_pjsip_write(struct ast_channel *ast, struct ast_frame *f)
Definition: chan_pjsip.c:1040
static struct info_dtmf_data * info_dtmf_data_alloc(struct ast_sip_session *session, char digit, unsigned int duration)
Definition: chan_pjsip.c:2206
static int compatible_formats_exist(struct ast_stream_topology *top, struct ast_format_cap *cap)
Determine if a topology is compatible with format capabilities.
Definition: chan_pjsip.c:526
static void hangup_data_destroy(void *obj)
Definition: chan_pjsip.c:2455
static int load_module(void)
Load the module.
Definition: chan_pjsip.c:3305
static struct ast_sip_session_supplement chan_pjsip_ack_supplement
Definition: chan_pjsip.c:164
static int chan_pjsip_get_hold(const char *chan_uid)
Determine whether a channel ID is in the list of PJSIP channels on hold.
Definition: chan_pjsip.c:1162
static struct indicate_data * indicate_data_alloc(struct ast_sip_session *session, int condition, int response_code, const void *frame_data, size_t datalen)
Definition: chan_pjsip.c:1309
#define UNIQUEID_BUFSIZE
Definition: chan_pjsip.c:76
static int call(void *data)
Definition: chan_pjsip.c:2359
static int chan_pjsip_sendtext(struct ast_channel *ast, const char *text)
Definition: chan_pjsip.c:2838
static struct ast_custom_function chan_pjsip_parse_uri_function
Definition: chan_pjsip.c:3267
static void transfer_refer(struct ast_sip_session *session, const char *target)
Definition: chan_pjsip.c:2045
static struct ast_threadstorage uniqueid_threadbuf
Definition: chan_pjsip.c:75
static int unload_module(void)
Unload the PJSIP channel from Asterisk.
Definition: chan_pjsip.c:3404
static int pbx_start_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
Definition: chan_pjsip.c:3116
static int is_compatible_format(struct ast_sip_session *session, struct ast_frame *f)
Determine if the given frame is in a format we've negotiated.
Definition: chan_pjsip.c:825
static unsigned int chan_idx
Definition: chan_pjsip.c:80
static void indicate_data_destroy(void *obj)
Definition: chan_pjsip.c:1301
static struct ast_custom_function session_refresh_function
Definition: chan_pjsip.c:3290
static struct rtp_direct_media_data * rtp_direct_media_data_create(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, const struct ast_format_cap *cap, struct ast_sip_session *session)
Definition: chan_pjsip.c:377
static const char * chan_pjsip_get_uniqueid(struct ast_channel *ast)
Definition: chan_pjsip.c:1279
static int chan_pjsip_answer(struct ast_channel *ast)
Function called by core when we should answer a PJSIP session.
Definition: chan_pjsip.c:727
static void info_dtmf_data_destroy(void *obj)
Definition: chan_pjsip.c:2200
static int chan_pjsip_add_hold(const char *chan_uid)
Add a channel ID to the list of PJSIP channels on hold.
Definition: chan_pjsip.c:1118
static int is_colp_update_allowed(struct ast_sip_session *session)
Definition: chan_pjsip.c:1403
static int chan_pjsip_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
Function called by core to stop a DTMF digit.
Definition: chan_pjsip.c:2263
static struct ast_sip_session_supplement chan_pjsip_supplement_response
SIP session supplement structure just for responses.
Definition: chan_pjsip.c:155
static struct ast_frame * chan_pjsip_read_stream(struct ast_channel *ast)
Function called by core to read any waiting frames.
Definition: chan_pjsip.c:839
static void set_sipdomain_variable(struct ast_sip_session *session)
Definition: chan_pjsip.c:2995
static int chan_pjsip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
Function called by core to change the underlying owner channel.
Definition: chan_pjsip.c:1046
static struct ast_sip_session_supplement call_pickup_supplement
Definition: chan_pjsip.c:3110
static void chan_pjsip_incoming_response(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
Function called when a response is received on the session.
Definition: chan_pjsip.c:3187
static void local_hold_set_state(struct ast_sip_session_media *session_media, unsigned int held)
Callback which changes the value of locally held on the media stream.
Definition: chan_pjsip.c:1483
static struct ast_custom_function dtmf_mode_function
Definition: chan_pjsip.c:3278
PJSIP Channel Driver shared data structures.
enum sip_cc_notify_state state
Definition: chan_sip.c:963
General Asterisk PBX channel definitions.
struct ast_stream_topology * ast_channel_set_stream_topology(struct ast_channel *chan, struct ast_stream_topology *topology)
Set the topology of streams on a channel.
void ast_channel_rings_set(struct ast_channel *chan, int value)
void ast_channel_named_pickupgroups_set(struct ast_channel *chan, struct ast_namedgroups *value)
@ AST_CHAN_TP_SEND_TEXT_DATA
Channels have this property if they implement send_text_data.
Definition: channel.h:975
@ AST_CHAN_TP_WANTSJITTER
Channels have this property if they can accept input with jitter; i.e. most VoIP channels.
Definition: channel.h:960
@ AST_CHAN_TP_CREATESJITTER
Channels have this property if they can create jitter; i.e. most VoIP channels.
Definition: channel.h:965
#define AST_EXTENDED_FDS
Definition: channel.h:195
int ast_channel_get_device_name(struct ast_channel *chan, char *device_name, size_t name_buffer_length)
Get a device name given its channel structure.
Definition: channel.c:10599
void ast_channel_set_unbridged_nolock(struct ast_channel *chan, int value)
Variant of ast_channel_set_unbridged. Use this if the channel is already locked prior to calling.
#define ast_channel_alloc_with_endpoint(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag, endpoint,...)
Definition: channel.h:1262
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
int ast_set_read_format_path(struct ast_channel *chan, struct ast_format *raw_format, struct ast_format *core_format)
Set specific read path on channel.
Definition: channel.c:5484
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2538
int ast_queue_hangup(struct ast_channel *chan)
Queue a hangup frame.
Definition: channel.c:1140
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition: channel.c:1811
const char * ast_channel_uniqueid(const struct ast_channel *chan)
void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
void * ast_channel_tech_pvt(const struct ast_channel *chan)
int ast_channel_fdno(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2888
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
ast_t38_state
Possible T38 states on channels.
Definition: channel.h:878
@ T38_STATE_UNAVAILABLE
Definition: channel.h:879
@ T38_STATE_UNKNOWN
Definition: channel.h:880
@ T38_STATE_REJECTED
Definition: channel.h:882
@ T38_STATE_NEGOTIATED
Definition: channel.h:883
@ T38_STATE_NEGOTIATING
Definition: channel.h:881
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
Definition: channel.c:566
const char * ast_channel_context(const struct ast_channel *chan)
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition: channel.c:1221
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2913
struct ast_trans_pvt * ast_channel_readtrans(const struct ast_channel *chan)
const char * ast_channel_name(const struct ast_channel *chan)
int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
Queue a control frame with payload.
Definition: channel.c:1228
@ AST_ADSI_UNAVAILABLE
Definition: channel.h:871
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1156
void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format)
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)
void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value)
int ast_channel_hangupcause(const struct ast_channel *chan)
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition: channel.c:10648
void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format)
struct ast_format * ast_channel_rawreadformat(struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
Set the source of the hangup in this channel and it's bridge.
Definition: channel.c:2494
void ast_channel_named_callgroups_set(struct ast_channel *chan, struct ast_namedgroups *value)
void ast_channel_hangupcause_hash_set(struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen)
Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash on the given channel.
Definition: channel.c:4370
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format)
#define AST_CHANNEL_NAME
Definition: channel.h:171
struct ast_trans_pvt * ast_channel_writetrans(const struct ast_channel *chan)
int ast_channel_register(const struct ast_channel_tech *tech)
Register a channel technology (a new channel driver) Called by a channel module to register the kind ...
Definition: channel.c:535
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2924
void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src)
Copy the source party id information to the destination party id.
Definition: channel.c:1755
struct ast_party_id ast_channel_connected_effective_id(struct ast_channel *chan)
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition: channel.c:2012
int ast_channel_get_up_time(struct ast_channel *chan)
Obtain how long it has been since the channel was answered.
Definition: channel.c:2842
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
void ast_channel_set_fd(struct ast_channel *chan, int which, int fd)
Definition: channel.c:2421
struct ast_format * ast_channel_rawwriteformat(struct ast_channel *chan)
int ast_set_write_format_path(struct ast_channel *chan, struct ast_format *core_format, struct ast_format *raw_format)
Set specific write path on channel.
Definition: channel.c:5520
void ast_channel_zone_set(struct ast_channel *chan, struct ast_tone_zone *value)
void ast_channel_queue_connected_line_update(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Queue a connected line update frame on a channel.
Definition: channel.c:9106
const char * ast_channel_macrocontext(const struct ast_channel *chan)
void ast_channel_priority_set(struct ast_channel *chan, int value)
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value)
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value)
#define ast_channel_unlock(chan)
Definition: channel.h:2889
void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format)
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_RING
Definition: channelstate.h:40
@ AST_STATE_RINGING
Definition: channelstate.h:41
@ AST_STATE_DOWN
Definition: channelstate.h:36
@ AST_STATE_BUSY
Definition: channelstate.h:43
@ AST_STATE_UP
Definition: channelstate.h:42
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7386
Standard Command Line Interface.
int pjsip_channel_cli_register(void)
Registers the channel cli commands.
Definition: cli_commands.c:448
void pjsip_channel_cli_unregister(void)
Unregisters the channel cli commands.
Definition: cli_commands.c:484
PJSIP CLI functions header file.
@ AST_MEDIA_TYPE_AUDIO
Definition: codec.h:32
@ AST_MEDIA_TYPE_UNKNOWN
Definition: codec.h:31
@ AST_MEDIA_TYPE_VIDEO
Definition: codec.h:33
@ AST_MEDIA_TYPE_IMAGE
Definition: codec.h:34
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
Definition: codec.c:347
@ AST_DEVSTATE_CACHABLE
Definition: devicestate.h:70
void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state)
Add a device state to the aggregate device state.
Definition: devicestate.c:636
int ast_devstate_changed(enum ast_device_state state, enum ast_devstate_cache cachable, const char *fmt,...)
Tells Asterisk the State for Device is changed.
Definition: devicestate.c:510
void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg)
Initialize aggregate device state.
Definition: devicestate.c:630
enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg)
Get the aggregate device state result.
Definition: devicestate.c:663
enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate)
Convert channel state to devicestate.
Definition: devicestate.c:242
int ast_devstate_changed_literal(enum ast_device_state state, enum ast_devstate_cache cachable, const char *device)
Tells Asterisk the State for Device is changed.
Definition: devicestate.c:471
ast_device_state
Device States.
Definition: devicestate.h:52
@ AST_DEVICE_UNKNOWN
Definition: devicestate.h:53
@ AST_DEVICE_ONHOLD
Definition: devicestate.h:61
@ AST_DEVICE_INVALID
Definition: devicestate.h:57
@ AST_DEVICE_BUSY
Definition: devicestate.h:56
@ AST_DEVICE_NOT_INUSE
Definition: devicestate.h:54
@ AST_DEVICE_UNAVAILABLE
Definition: devicestate.h:58
Convenient Signal Processing routines.
void ast_dsp_free(struct ast_dsp *dsp)
Definition: dsp.c:1770
#define DSP_FEATURE_FAX_DETECT
Definition: dsp.h:29
int ast_dsp_get_features(struct ast_dsp *dsp)
Get features.
Definition: dsp.c:1764
struct ast_frame * ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, struct ast_frame *inf)
Return AST_FRAME_NULL frames when there is silence, AST_FRAME_BUSY on busies, and call progress,...
Definition: dsp.c:1494
void ast_dsp_set_features(struct ast_dsp *dsp, int features)
Select feature set.
Definition: dsp.c:1755
char connected
Definition: eagi_proxy.c:82
char * end
Definition: eagi_proxy.c:73
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
@ AST_ENDPOINT_OFFLINE
Definition: endpoints.h:55
@ AST_ENDPOINT_ONLINE
Definition: endpoints.h:57
const char * ast_endpoint_get_tech(const struct ast_endpoint *endpoint)
Gets the technology of the given endpoint.
const char * ast_endpoint_get_resource(const struct ast_endpoint *endpoint)
Gets the resource name of the given endpoint.
Generic File Format Support. Should be included by clients of the file handling routines....
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
@ AST_FORMAT_CMP_NOT_EQUAL
Definition: format.h:38
Media Format Cache API.
struct ast_format * ast_format_h264
Built-in cached h264 format.
Definition: format_cache.c:176
struct ast_format * ast_format_h265
Built-in cached h265 format.
Definition: format_cache.c:181
struct ast_format * ast_format_vp9
Built-in cached vp9 format.
Definition: format_cache.c:196
struct ast_format * ast_format_vp8
Built-in cached vp8 format.
Definition: format_cache.c:191
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:326
int ast_format_cap_empty(const struct ast_format_cap *cap)
Determine if a format cap has no formats in it.
Definition: format_cap.c:746
int ast_format_cap_append_by_type(struct ast_format_cap *cap, enum ast_media_type type)
Add all codecs Asterisk knows about for a specific type to the capabilities structure.
Definition: format_cap.c:216
void ast_format_cap_remove_by_type(struct ast_format_cap *cap, enum ast_media_type type)
Remove all formats matching a specific format type.
Definition: format_cap.c:525
const char * ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)
Get the names of codecs of a set of formats.
Definition: format_cap.c:736
enum ast_format_cmp_res ast_format_cap_iscompatible_format(const struct ast_format_cap *cap, const struct ast_format *format)
Find if ast_format is within the capabilities of the ast_format_cap object.
Definition: format_cap.c:583
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition: format_cap.h:38
struct ast_format * ast_format_cap_get_format(const struct ast_format_cap *cap, int position)
Get the format at a specific index.
Definition: format_cap.c:400
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
int ast_format_cap_identical(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
Determine if two capabilities structures are identical.
Definition: format_cap.c:689
int ast_format_cap_iscompatible(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
Determine if any joint capabilities exist between two capabilities structures.
Definition: format_cap.c:655
struct ast_format * ast_format_cap_get_best_by_type(const struct ast_format_cap *cap, enum ast_media_type type)
Get the most preferred format for a particular media type.
Definition: format_cap.c:417
#define ast_format_cap_append(cap, format, framing)
Definition: format_cap.h:103
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
size_t ast_format_cap_count(const struct ast_format_cap *cap)
Get the number of formats present within the capabilities structure.
Definition: format_cap.c:395
static int exists(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_logic.c:124
@ AST_RTP_DTMF_MODE_INBAND
Definition: rtp_engine.h:154
@ AST_RTP_DTMF_MODE_NONE
Definition: rtp_engine.h:150
@ AST_RTP_GLUE_RESULT_LOCAL
Definition: rtp_engine.h:164
@ AST_RTP_GLUE_RESULT_REMOTE
Definition: rtp_engine.h:162
@ AST_RTP_GLUE_RESULT_FORBID
Definition: rtp_engine.h:160
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object,...
const char * type
Definition: rtp_engine.h:722
struct ast_endpoint_snapshot * ast_endpoint_latest_snapshot(const char *tech, const char *resource)
Retrieve the most recent snapshot for the endpoint with the given name.
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
@ AST_RTP_PROPERTY_RTCP
Definition: rtp_engine.h:123
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
struct ast_msg_data * ast_msg_data_alloc(enum ast_msg_data_source_type source, struct ast_msg_data_attribute attributes[], size_t count)
Allocates an ast_msg_data structure.
Definition: message.c:1445
const char * ast_msg_data_get_attribute(struct ast_msg_data *msg, enum ast_msg_data_attribute_type attribute_type)
Get attribute from ast_msg_data.
Definition: message.c:1560
struct ast_msg_data * ast_msg_data_dup(struct ast_msg_data *msg)
Clone an ast_msg_data structure.
Definition: message.c:1522
@ AST_MSG_DATA_ATTR_BODY
Definition: message.h:458
@ AST_MSG_DATA_ATTR_TO
Definition: message.h:455
@ AST_MSG_DATA_ATTR_FROM
Definition: message.h:456
@ AST_MSG_DATA_ATTR_CONTENT_TYPE
Definition: message.h:457
@ AST_MSG_DATA_SOURCE_TYPE_UNKNOWN
Definition: message.h:447
int ast_sip_push_task(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Pushes a task to SIP servants.
Definition: res_pjsip.c:5175
int ast_sip_push_task_wait_servant(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to SIP servants and wait for it to complete.
Definition: res_pjsip.c:5241
int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to the serializer and wait for it to complete.
Definition: res_pjsip.c:5255
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
char * ast_get_encoded_str(const char *stream, char *result, size_t result_len)
Decode a stream of encoded control or extended ASCII characters.
Definition: main/app.c:2921
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the 'nonstandard' argument separation process for an application.
struct ast_features_pickup_config * ast_get_chan_features_pickup_config(struct ast_channel *chan)
Get the pickup configuration options for a channel.
@ AST_T38_REQUEST_PARMS
#define AST_FRAME_DTMF
ast_control_transfer
@ AST_TRANSFER_FAILED
@ AST_TRANSFER_SUCCESS
#define ast_frfree(fr)
#define AST_OPTION_T38_STATE
@ AST_FRAME_VIDEO
@ AST_FRAME_VOICE
@ AST_FRAME_RTCP
@ AST_FRAME_MODEM
@ AST_FRAME_CONTROL
char * ast_frame_subclass2str(struct ast_frame *f, char *subclass, size_t slen, char *moreinfo, size_t mlen)
Copy the discription of a frame's subclass into the provided string.
Definition: main/frame.c:406
@ AST_CONTROL_SRCUPDATE
@ AST_CONTROL_PROGRESS
@ AST_CONTROL_STREAM_TOPOLOGY_SOURCE_CHANGED
@ AST_CONTROL_BUSY
@ AST_CONTROL_UNHOLD
@ AST_CONTROL_VIDUPDATE
@ AST_CONTROL_STREAM_TOPOLOGY_REQUEST_CHANGE
@ AST_CONTROL_PROCEEDING
@ AST_CONTROL_REDIRECTING
@ AST_CONTROL_T38_PARAMETERS
@ AST_CONTROL_CONGESTION
@ AST_CONTROL_ANSWER
@ AST_CONTROL_RINGING
@ AST_CONTROL_HOLD
@ AST_CONTROL_STREAM_TOPOLOGY_CHANGED
@ AST_CONTROL_CONNECTED_LINE
@ AST_CONTROL_TRANSFER
@ AST_CONTROL_SRCCHANGE
@ AST_CONTROL_INCOMPLETE
@ AST_CONTROL_MASQUERADE_NOTIFY
@ AST_CONTROL_PVT_CAUSE_CODE
@ AST_CONTROL_UPDATE_RTP_PEER
struct ast_frame ast_null_frame
Definition: main/frame.c:79
Tone Indication Support.
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
Definition: indications.c:433
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
Asterisk locking-related definitions:
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:453
#define SCOPE_EXIT_RTN(...)
Definition: logger.h:915
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
Definition: logger.h:919
#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level,...)
Definition: logger.h:942
#define SCOPE_ENTER(level,...)
Definition: logger.h:900
#define SCOPE_ENTER_TASK(level, indent,...)
Definition: logger.h:904
#define ast_trace(level,...)
Definition: logger.h:891
#define LOG_ERROR
Definition: logger.h:286
#define ast_verb(level,...)
Definition: logger.h:464
#define LOG_NOTICE
Definition: logger.h:264
#define LOG_WARNING
Definition: logger.h:275
#define ast_trace_get_indent()
Definition: logger.h:894
static struct ao2_container * endpoints
Out-of-call text message support.
Asterisk module definitions.
@ AST_MODFLAG_LOAD_ORDER
Definition: module.h:317
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:543
@ AST_MODPRI_CHANNEL_DRIVER
Definition: module.h:327
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
Music on hold handling.
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:7766
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition: channel.c:7776
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. "null" in this sense essentially means uninitialized,...
Definition: netsock2.h:127
static void ast_sockaddr_setnull(struct ast_sockaddr *addr)
Sets address addr to null.
Definition: netsock2.h:140
Core PBX routines and definitions.
@ AST_PBX_FAILED
Definition: pbx.h:356
@ AST_PBX_CALL_LIMIT
Definition: pbx.h:357
@ AST_PBX_SUCCESS
Definition: pbx.h:355
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4179
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition: pbx.c:4712
int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
Set the channel to next execute the specified dialplan location.
Call Pickup API.
int ast_pickup_call(struct ast_channel *chan)
Pickup a call.
Definition: pickup.c:200
int pjsip_acf_moh_passthrough_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
PJSIP_MOH_PASSTHROUGH function read callback.
int pjsip_acf_media_offer_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
PJSIP_MEDIA_OFFER function read callback.
int pjsip_acf_media_offer_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
PJSIP_MEDIA_OFFER function write callback.
int pjsip_acf_dtmf_mode_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
PJSIP_DTMF_MODE function write callback.
int pjsip_acf_session_refresh_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
PJSIP_SEND_SESSION_REFRESH function write callback.
int pjsip_acf_moh_passthrough_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
PJSIP_MOH_PASSTHROUGH function write callback.
int pjsip_acf_channel_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
CHANNEL function read callback.
int pjsip_acf_dtmf_mode_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
PJSIP_DTMF_MODE function read callback.
int pjsip_acf_dial_contacts_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
PJSIP_DIAL_CONTACTS function read callback.
int pjsip_acf_parse_uri_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
PJSIP_PARSE_URI function read callback.
PJSIP dialplan functions header file.
static int cdata(void *userdata, int state, const char *cdata, size_t len)
struct stasis_forward * sub
Definition: res_corosync.c:240
const char * method
Definition: res_pjsip.c:4372
struct ast_sip_contact * ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list)
Retrieve the first bound contact from a list of AORs.
Definition: location.c:304
void ast_sip_unregister_service(pjsip_module *module)
Definition: res_pjsip.c:3368
struct ao2_container * ast_sip_get_endpoints(void)
Retrieve any endpoints available to sorcery.
int ast_sip_register_service(pjsip_module *module)
Register a SIP service in Asterisk.
Definition: res_pjsip.c:3352
@ AST_SIP_MEDIA_ENCRYPT_NONE
Definition: res_pjsip.h:529
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
@ AST_SIP_SUPPLEMENT_PRIORITY_CHANNEL
Definition: res_pjsip.h:2922
@ AST_SIP_SUPPLEMENT_PRIORITY_LAST
Definition: res_pjsip.h:2924
void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
Copy a pj_str_t into a standard character buffer.
Definition: res_pjsip.c:5277
int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint, void *token, void(*callback)(void *token, pjsip_event *e))
General purpose method for sending a SIP request.
Definition: res_pjsip.c:5071
int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body)
Add a body to an outbound SIP message.
Definition: res_pjsip.c:5128
unsigned int ast_sip_get_disable_multi_domain(void)
Retrieve the system setting 'disable multi domain'.
@ AST_SIP_DTMF_NONE
Definition: res_pjsip.h:429
@ AST_SIP_DTMF_AUTO_INFO
Definition: res_pjsip.h:440
@ AST_SIP_DTMF_AUTO
Definition: res_pjsip.h:438
@ AST_SIP_DTMF_INBAND
Definition: res_pjsip.h:434
@ AST_SIP_DTMF_INFO
Definition: res_pjsip.h:436
@ AST_SIP_DTMF_RFC_4733
Definition: res_pjsip.h:432
int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint, const char *uri, struct ast_sip_contact *contact, pjsip_tx_data **tdata)
General purpose method for creating a SIP request.
Definition: res_pjsip.c:4527
int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value)
Add a header to an outbound SIP message.
Definition: res_pjsip.c:5100
@ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_NONE
Definition: res_pjsip.h:514
@ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_INCOMING
Definition: res_pjsip.h:522
@ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_OUTGOING
Definition: res_pjsip.h:518
ast_sip_session_refresh_method
Definition: res_pjsip.h:505
@ AST_SIP_SESSION_REFRESH_METHOD_UPDATE
Definition: res_pjsip.h:509
@ AST_SIP_SESSION_REFRESH_METHOD_INVITE
Definition: res_pjsip.h:507
struct ast_sip_session_media_state * ast_sip_session_media_state_alloc(void)
Allocate a session media state structure.
struct ast_datastore * ast_sip_session_get_datastore(struct ast_sip_session *session, const char *name)
Retrieve a session datastore.
struct ast_datastore * ast_sip_session_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
Alternative for ast_datastore_alloc()
void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
Send a SIP request.
int ast_sip_session_add_datastore(struct ast_sip_session *session, struct ast_datastore *datastore)
Add a datastore to a SIP session.
@ AST_SIP_SESSION_AFTER_MEDIA
@ AST_SIP_SESSION_BEFORE_MEDIA
void ast_sip_session_remove_datastore(struct ast_sip_session *session, const char *name)
Remove a session datastore from the session.
void ast_sip_session_media_state_free(struct ast_sip_session_media_state *media_state)
Free a session media state structure.
const char * ast_sip_session_get_name(const struct ast_sip_session *session)
Get the channel or endpoint name associated with the session.
struct ast_sip_channel_pvt * ast_sip_channel_pvt_alloc(void *pvt, struct ast_sip_session *session)
Allocate a new SIP channel pvt structure.
#define ast_sip_session_register_supplement(supplement)
int ast_sip_session_create_invite(struct ast_sip_session *session, pjsip_tx_data **tdata)
Creates an INVITE request.
void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
Unregister a an supplement to SIP session processing.
Definition: pjsip_session.c:63
void ast_sip_session_unsuspend(struct ast_sip_session *session)
Request the session serializer be unsuspended.
void ast_sip_session_terminate(struct ast_sip_session *session, int response)
Terminate a session and, if possible, send the provided response code.
void ast_sip_session_media_state_reset(struct ast_sip_session_media_state *media_state)
Reset a media state to a clean state.
struct ast_sip_session * ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, const char *location, const char *request_user, struct ast_stream_topology *req_topology)
Create a new outgoing SIP session.
int ast_sip_session_refresh(struct ast_sip_session *session, ast_sip_session_request_creation_cb on_request_creation, ast_sip_session_sdp_creation_cb on_sdp_creation, ast_sip_session_response_cb on_response, enum ast_sip_session_refresh_method method, int generate_new_sdp, struct ast_sip_session_media_state *media_state)
Send a reinvite or UPDATE on a session.
void ast_sip_session_send_response(struct ast_sip_session *session, pjsip_tx_data *tdata)
Send a SIP response.
void ast_sip_session_suspend(struct ast_sip_session *session)
Request and wait for the session serializer to be suspended.
#define NULL
Definition: resample.c:96
Pluggable RTP Architecture.
#define AST_RTP_RTCP_PSFB
Definition: rtp_engine.h:299
enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance)
Get the DTMF mode of an RTP instance.
Definition: rtp_engine.c:2137
void ast_rtp_instance_set_last_rx(struct ast_rtp_instance *rtp, time_t time)
Set the last RTP reception time.
Definition: rtp_engine.c:3774
ast_rtp_glue_result
Definition: rtp_engine.h:158
#define ast_rtp_instance_get_and_cmp_remote_address(instance, address)
Get the address of the remote endpoint that we are sending RTP to, comparing its address to another.
Definition: rtp_engine.h:1228
int ast_rtp_instance_dtmf_begin(struct ast_rtp_instance *instance, char digit)
Begin sending a DTMF digit.
Definition: rtp_engine.c:2081
void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
Set the value of an RTP instance property.
Definition: rtp_engine.c:705
int ast_rtp_instance_dtmf_end_with_duration(struct ast_rtp_instance *instance, char digit, unsigned int duration)
Definition: rtp_engine.c:2109
int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
Send a frame out over RTP.
Definition: rtp_engine.c:568
void ast_rtp_instance_set_channel_id(struct ast_rtp_instance *instance, const char *uniqueid)
Set the channel that owns this RTP instance.
Definition: rtp_engine.c:553
#define ast_rtp_glue_register(glue)
Definition: rtp_engine.h:847
int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp)
Get the file descriptor for an RTP session (or RTCP)
Definition: rtp_engine.c:2192
int ast_rtp_glue_unregister(struct ast_rtp_glue *glue)
Unregister RTP glue.
Definition: rtp_engine.c:408
@ T38_PEER_REINVITE
Definition: sip.h:661
@ T38_LOCAL_REINVITE
Definition: sip.h:660
@ T38_REJECTED
Definition: sip.h:663
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
Endpoint abstractions.
Media Stream API.
struct ast_stream_topology * ast_stream_topology_clone(const struct ast_stream_topology *topology)
Create a deep clone of an existing stream topology.
Definition: stream.c:667
const char * ast_stream_topology_to_str(const struct ast_stream_topology *topology, struct ast_str **buf)
Get a string representing the topology for debugging/display purposes.
Definition: stream.c:936
int ast_stream_topology_get_count(const struct ast_stream_topology *topology)
Get the number of streams in a topology.
Definition: stream.c:765
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
Definition: stream.c:743
struct ast_stream * ast_stream_topology_get_stream(const struct ast_stream_topology *topology, unsigned int position)
Get a specific stream from the topology.
Definition: stream.c:788
struct ast_stream_topology * ast_stream_topology_create_from_format_cap(struct ast_format_cap *cap)
A helper function that, given a format capabilities structure, creates a topology and separates the m...
Definition: stream.c:848
struct ast_format_cap * ast_stream_topology_get_formats(struct ast_stream_topology *topology)
Create a format capabilities structure representing the topology.
Definition: stream.c:930
const struct ast_format_cap * ast_stream_get_formats(const struct ast_stream *stream)
Get the current negotiated formats of a stream.
Definition: stream.c:330
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:727
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:79
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1224
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:85
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_tmp(init_len, __expr)
Provides a temporary ast_str and returns a copy of its buffer.
Definition: strings.h:1154
#define ast_str_alloca(init_len)
Definition: strings.h:813
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:633
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1078
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
struct ast_sip_session * session
Definition: chan_pjsip.c:679
unsigned long indent
Definition: chan_pjsip.c:680
Generic container type.
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:604
const ast_string_field uniqueid
Structure representing a snapshot of channel state.
struct ast_channel_snapshot_base * base
enum ast_channel_state state
Structure to describe a channel "technology", ie a channel driver See for examples:
Definition: channel.h:628
struct ast_format_cap * capabilities
Definition: channel.h:632
const char *const type
Definition: channel.h:629
Main Channel structure associated with a channel.
const char * data
char chan_name[AST_CHANNEL_NAME]
enum ast_control_t38 request_response
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
Structure for a data store type.
Definition: datastore.h:31
const char * type
Definition: datastore.h:32
Structure for a data store object.
Definition: datastore.h:68
void * data
Definition: datastore.h:70
You shouldn't care about the contents of this struct.
Definition: devicestate.h:230
A snapshot of an endpoint's state.
Configuration relating to call pickup.
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
Definition of a media format.
Definition: format.c:43
struct ast_format * format
Data structure associated with a single frame of data.
union ast_frame::@250 data
struct ast_frame_subclass subclass