Asterisk - The Open Source Telephony Project GIT-master-35be64c
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions | Variables
res_fax.c File Reference

Generic FAX Resource for FAX technology resource modules. More...

#include "asterisk.h"
#include "asterisk/io.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/lock.h"
#include "asterisk/options.h"
#include "asterisk/strings.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/config.h"
#include "asterisk/astobj2.h"
#include "asterisk/res_fax.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/dsp.h"
#include "asterisk/indications.h"
#include "asterisk/ast_version.h"
#include "asterisk/translate.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/smoother.h"
#include "asterisk/format_cache.h"
Include dependency graph for res_fax.c:

Go to the source code of this file.

Data Structures

struct  ast_fax_debug_info
 
struct  debug_info_history
 
struct  fax_detect
 used for fax detect framehook More...
 
struct  fax_gateway
 used for gateway framehook More...
 
struct  fax_module
 registered FAX technology modules are put into this list More...
 
struct  fax_options
 
struct  faxmodules
 

Macros

#define FAX_DETECT_MODE_BOTH   (FAX_DETECT_MODE_CNG | FAX_DETECT_MODE_T38)
 
#define FAX_DETECT_MODE_CNG   (1 << 0)
 FAX Detect flags.
 
#define FAX_DETECT_MODE_T38   (1 << 1)
 
#define FAX_GATEWAY_TIMEOUT   RES_FAX_TIMEOUT
 
#define FAX_MAXBUCKETS   10
 maximum buckets for res_fax ao2 containers
 
#define GENERIC_FAX_EXEC_ERROR(fax, chan, errorstr, reason)
 
#define GENERIC_FAX_EXEC_ERROR_QUIET(fax, chan, errorstr, reason)
 
#define GENERIC_FAX_EXEC_SET_VARS(fax, chan, errorstr, reason)
 
#define RES_FAX_MAXRATE   14400
 
#define RES_FAX_MINRATE   4800
 
#define RES_FAX_MODEM   (AST_FAX_MODEM_V17 | AST_FAX_MODEM_V27TER | AST_FAX_MODEM_V29)
 
#define RES_FAX_STATUSEVENTS   0
 
#define RES_FAX_T38TIMEOUT   5000
 
#define RES_FAX_TIMEOUT   10000
 

Enumerations

enum  {
  OPT_CALLEDMODE = (1 << 0) , OPT_CALLERMODE = (1 << 1) , OPT_DEBUG = (1 << 2) , OPT_STATUS = (1 << 3) ,
  OPT_ALLOWAUDIO = (1 << 5) , OPT_REQUEST_T38 = (1 << 6) , OPT_FORCE_AUDIO = (1 << 7)
}
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int acf_faxopt_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 FAXOPT read function returns the contents of a FAX option.
 
static int acf_faxopt_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 FAXOPT write function modifies the contents of a FAX option.
 
static char * ast_fax_caps_to_str (enum ast_fax_capabilities caps, char *buf, size_t bufsize)
 
void ast_fax_log (int level, const char *file, const int line, const char *function, const char *msg)
 Log message at FAX or recommended level.
 
unsigned int ast_fax_maxrate (void)
 get the maxiumum supported fax rate
 
unsigned int ast_fax_minrate (void)
 get the minimum supported fax rate
 
static int ast_fax_modem_to_str (enum ast_fax_modems bits, char *tbuf, size_t bufsize)
 
const char * ast_fax_session_operation_str (struct ast_fax_session *s)
 get string representation of a FAX session's operation
 
const char * ast_fax_state_to_str (enum ast_fax_state state)
 convert a ast_fax_state to a string
 
int ast_fax_tech_register (struct ast_fax_tech *tech)
 register a FAX technology module
 
void ast_fax_tech_unregister (struct ast_fax_tech *tech)
 unregister a FAX technology module
 
struct ast_module * AST_MODULE_SELF_SYM (void)
 
static int check_modem_rate (enum ast_fax_modems modems, unsigned int rate)
 
static char * cli_fax_set_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 enable FAX debugging
 
static char * cli_fax_show_capabilities (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 display registered FAX capabilities
 
static char * cli_fax_show_session (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 display details of a specified fax session
 
static char * cli_fax_show_sessions (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 display fax sessions
 
static char * cli_fax_show_settings (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 display global defaults and settings
 
static char * cli_fax_show_stats (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 display fax stats
 
static char * cli_fax_show_version (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static void debug_check_frame_for_silence (struct ast_fax_session *s, unsigned int c2s, struct ast_frame *frame)
 
static void destroy_callback (void *data)
 
static void destroy_faxdetect (void *data)
 destroy a FAX detect structure
 
static void destroy_gateway (void *data)
 destroy a FAX gateway session structure
 
static void destroy_session (void *session)
 destroy a FAX session structure
 
static void destroy_session_details (void *details)
 destroy a FAX session details structure
 
static void destroy_v21_sessions (struct fax_gateway *gateway)
 destroy the v21 detection parts of a fax gateway session
 
static int disable_t38 (struct ast_channel *chan)
 
static int fax_detect_attach (struct ast_channel *chan, int timeout, int flags)
 Attach a faxdetect framehook object to a channel.
 
static struct ast_frame * fax_detect_framehook (struct ast_channel *chan, struct ast_frame *f, enum ast_framehook_event event, void *data)
 Fax Detect Framehook.
 
static void fax_detect_framehook_destroy (void *data)
 Deref the faxdetect data structure when the faxdetect framehook is detached.
 
static struct fax_detect * fax_detect_new (struct ast_channel *chan, int timeout, int flags)
 Create a new fax detect object.
 
static int fax_gateway_attach (struct ast_channel *chan, struct ast_fax_session_details *details)
 Attach a gateway framehook object to a channel.
 
static struct ast_frame * fax_gateway_detect_t38 (struct fax_gateway *gateway, struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *active, struct ast_frame *f)
 T38 Gateway Negotiate t38 parameters.
 
static struct ast_frame * fax_gateway_detect_v21 (struct fax_gateway *gateway, struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *active, struct ast_frame *f)
 
static struct ast_frame * fax_gateway_framehook (struct ast_channel *chan, struct ast_frame *f, enum ast_framehook_event event, void *data)
 T.30<->T.38 gateway framehook.
 
static void fax_gateway_framehook_destroy (void *data)
 Destroy the gateway data structure when the framehook is detached.
 
static void fax_gateway_indicate_t38 (struct ast_channel *chan, struct ast_channel *active, struct ast_control_t38_parameters *control_params)
 
static struct fax_gateway * fax_gateway_new (struct ast_channel *chan, struct ast_fax_session_details *details)
 Create a new fax gateway object.
 
static struct ast_frame * fax_gateway_request_t38 (struct fax_gateway *gateway, struct ast_channel *chan)
 
static int fax_gateway_start (struct fax_gateway *gateway, struct ast_fax_session_details *details, struct ast_channel *chan)
 Create a fax session and start T.30<->T.38 gateway mode.
 
static unsigned int fax_rate_str_to_int (const char *ratestr)
 convert a rate string to a rate
 
static struct ast_fax_session * fax_session_new (struct ast_fax_session_details *details, struct ast_channel *chan, struct ast_fax_session *reserved, struct ast_fax_tech_token *token)
 create a FAX session
 
static void fax_session_release (struct ast_fax_session *s, struct ast_fax_tech_token *token)
 Release a session token.
 
static struct ast_fax_session * fax_session_reserve (struct ast_fax_session_details *details, struct ast_fax_tech_token **token)
 Reserve a fax session.
 
static char * fax_session_tab_complete (struct ast_cli_args *a)
 fax session tab completion
 
static const char * fax_session_type (struct ast_fax_session *s)
 
static struct ast_fax_session * fax_v21_session_new (struct ast_channel *chan)
 
static struct ast_fax_session_details * find_details (struct ast_channel *chan)
 returns a reference counted pointer to a fax datastore, if it exists
 
static struct ast_fax_session_details * find_or_create_details (struct ast_channel *chan)
 returns a reference counted details structure from the channel's fax datastore. If the datastore does not exist it will be created
 
static void fixup_callback (void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
 Copies fax detection and gateway framehooks during masquerades.
 
static struct ast_json * generate_filenames_json (struct ast_fax_session_details *details)
 
static char * generate_filenames_string (struct ast_fax_session_details *details, char *prefix, char *separator)
 Generate a string of filenames using the given prefix and separator.
 
static int generic_fax_exec (struct ast_channel *chan, struct ast_fax_session_details *details, struct ast_fax_session *reserved, struct ast_fax_tech_token *token)
 this is the generic FAX session handling function
 
static void get_general_options (struct fax_options *options)
 
static int load_module (void)
 Load the module.
 
static int manager_fax_session (struct mansession *s, const struct message *m)
 
static int manager_fax_sessions (struct mansession *s, const struct message *m)
 
static int manager_fax_sessions_entry (struct mansession *s, struct ast_fax_session *session, const char *id_text)
 
static int manager_fax_stats (struct mansession *s, const struct message *m)
 
static int receivefax_exec (struct ast_channel *chan, const char *data)
 initiate a receive FAX session
 
static int receivefax_t38_init (struct ast_channel *chan, struct ast_fax_session_details *details)
 
static int reload_module (void)
 
static int report_fax_status (struct ast_channel *chan, struct ast_fax_session_details *details, const char *status)
 send a FAX status manager event
 
static int report_receive_fax_status (struct ast_channel *chan, const char *filename)
 Report on the final state of a receive fax operation.
 
static int report_send_fax_status (struct ast_channel *chan, struct ast_fax_session_details *details)
 Report on the status of a completed fax send attempt.
 
static int sendfax_exec (struct ast_channel *chan, const char *data)
 initiate a send FAX session
 
static int sendfax_t38_init (struct ast_channel *chan, struct ast_fax_session_details *details)
 
static int session_cmp_cb (void *obj, void *arg, int flags)
 compare callback for ao2
 
static struct ast_fax_session_details * session_details_new (void)
 create a FAX session details structure
 
static int session_hash_cb (const void *obj, const int flags)
 hash callback for ao2
 
static void set_channel_variables (struct ast_channel *chan, struct ast_fax_session_details *details)
 Set fax related channel variables.
 
static int set_config (int reload)
 configure res_fax
 
static int set_fax_t38_caps (struct ast_channel *chan, struct ast_fax_session_details *details)
 
static void set_general_options (const struct fax_options *options)
 
static int set_t38timeout (const char *value, unsigned int *t38timeout)
 
static void t38_parameters_ast_to_fax (struct ast_fax_t38_parameters *dst, const struct ast_control_t38_parameters *src)
 
static void t38_parameters_fax_to_ast (struct ast_control_t38_parameters *dst, const struct ast_fax_t38_parameters *src)
 
static int unload_module (void)
 unload res_fax
 
static int update_modem_bits (enum ast_fax_modems *bits, const char *value)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Generic FAX Applications" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_APP_DEPEND, }
 
static struct ast_custom_function acf_faxopt
 FAXOPT dialplan function.
 
static const char app_receivefax [] = "ReceiveFAX"
 
static const char app_sendfax [] = "SendFAX"
 
static const struct ast_module_info * ast_module_info = &__mod_info
 
static const char * config = "res_fax.conf"
 
static const struct fax_options default_options
 
static struct ast_cli_entry fax_cli []
 
static const struct ast_datastore_info fax_datastore
 
static const struct ast_app_option fax_exec_options [128] = { [ 'a' ] = { .flag = OPT_CALLEDMODE }, [ 'c' ] = { .flag = OPT_CALLERMODE }, [ 'd' ] = { .flag = OPT_DEBUG }, [ 'f' ] = { .flag = OPT_ALLOWAUDIO }, [ 'F' ] = { .flag = OPT_FORCE_AUDIO }, [ 's' ] = { .flag = OPT_STATUS }, [ 'z' ] = { .flag = OPT_REQUEST_T38 }, }
 
static int fax_logger_level = -1
 
static struct faxmodules faxmodules = AST_RWLIST_HEAD_INIT_VALUE
 
struct { 
 
   int   active_sessions 
 
   struct ao2_container *   container 
 
   int   fax_complete 
 
   int   fax_failures 
 
   int   fax_rx_attempts 
 
   int   fax_tx_attempts 
 
   int   nextsessionname 
 
   int   reserved_sessions 
 
} faxregistry 
 The faxregistry is used to manage information and statistics for all FAX sessions.
 
static struct fax_options general_options
 
static int global_fax_debug = 0
 
static ast_rwlock_t options_lock = AST_RWLOCK_INIT_VALUE
 
static struct ast_control_t38_parameters our_t38_parameters
 

Detailed Description

Generic FAX Resource for FAX technology resource modules.

Author
Dwayne M. Hubbard dhubb.nosp@m.ard@.nosp@m.digiu.nosp@m.m.co.nosp@m.m
Kevin P. Fleming kpfle.nosp@m.ming.nosp@m.@digi.nosp@m.um.c.nosp@m.om
Matthew Nicholson mnich.nosp@m.olso.nosp@m.n@dig.nosp@m.ium..nosp@m.com
Gregory H. Nietsky grego.nosp@m.ry@d.nosp@m.istro.nosp@m.tech.nosp@m..co.z.nosp@m.a

A generic FAX resource module that provides SendFAX and ReceiveFAX applications. This module requires FAX technology modules, like res_fax_spandsp, to register with it so it can use the technology modules to perform the actual FAX transmissions.

Definition in file res_fax.c.

Macro Definition Documentation

◆ FAX_DETECT_MODE_BOTH

#define FAX_DETECT_MODE_BOTH   (FAX_DETECT_MODE_CNG | FAX_DETECT_MODE_T38)

Definition at line 586 of file res_fax.c.

◆ FAX_DETECT_MODE_CNG

#define FAX_DETECT_MODE_CNG   (1 << 0)

FAX Detect flags.

Definition at line 584 of file res_fax.c.

◆ FAX_DETECT_MODE_T38

#define FAX_DETECT_MODE_T38   (1 << 1)

Definition at line 585 of file res_fax.c.

◆ FAX_GATEWAY_TIMEOUT

#define FAX_GATEWAY_TIMEOUT   RES_FAX_TIMEOUT

Definition at line 594 of file res_fax.c.

◆ FAX_MAXBUCKETS

#define FAX_MAXBUCKETS   10

maximum buckets for res_fax ao2 containers

Definition at line 591 of file res_fax.c.

◆ GENERIC_FAX_EXEC_ERROR

#define GENERIC_FAX_EXEC_ERROR (   fax,
  chan,
  errorstr,
  reason 
)
Value:
do { \
ast_log(LOG_ERROR, "channel '%s' FAX session '%u' failure, reason: '%s' (%s)\n", ast_channel_name(chan), fax->id, reason, errorstr); \
GENERIC_FAX_EXEC_ERROR_QUIET(fax, chan, errorstr, reason); \
} while (0)
const char * ast_channel_name(const struct ast_channel *chan)
#define LOG_ERROR

Definition at line 1586 of file res_fax.c.

1587 { \
1588 ast_log(LOG_ERROR, "channel '%s' FAX session '%u' failure, reason: '%s' (%s)\n", ast_channel_name(chan), fax->id, reason, errorstr); \
1589 GENERIC_FAX_EXEC_ERROR_QUIET(fax, chan, errorstr, reason); \
1590 } while (0)

◆ GENERIC_FAX_EXEC_ERROR_QUIET

#define GENERIC_FAX_EXEC_ERROR_QUIET (   fax,
  chan,
  errorstr,
  reason 
)
Value:
do { \
GENERIC_FAX_EXEC_SET_VARS(fax, chan, errorstr, reason); \
} while (0)

Definition at line 1581 of file res_fax.c.

1582 { \
1583 GENERIC_FAX_EXEC_SET_VARS(fax, chan, errorstr, reason); \
1584 } while (0)

◆ GENERIC_FAX_EXEC_SET_VARS

#define GENERIC_FAX_EXEC_SET_VARS (   fax,
  chan,
  errorstr,
  reason 
)

Definition at line 1570 of file res_fax.c.

1571 { \
1572 if (ast_strlen_zero(fax->details->result)) \
1573 ast_string_field_set(fax->details, result, "FAILED"); \
1574 if (ast_strlen_zero(fax->details->resultstr)) \
1575 ast_string_field_set(fax->details, resultstr, reason); \
1576 if (ast_strlen_zero(fax->details->error)) \
1577 ast_string_field_set(fax->details, error, errorstr); \
1578 set_channel_variables(chan, fax->details); \
1579 } while (0)
static PGresult * result
Definition cel_pgsql.c:84
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65

◆ RES_FAX_MAXRATE

#define RES_FAX_MAXRATE   14400

Definition at line 624 of file res_fax.c.

◆ RES_FAX_MINRATE

#define RES_FAX_MINRATE   4800

Definition at line 623 of file res_fax.c.

◆ RES_FAX_MODEM

#define RES_FAX_MODEM   (AST_FAX_MODEM_V17 | AST_FAX_MODEM_V27TER | AST_FAX_MODEM_V29)

Definition at line 626 of file res_fax.c.

◆ RES_FAX_STATUSEVENTS

#define RES_FAX_STATUSEVENTS   0

Definition at line 625 of file res_fax.c.

◆ RES_FAX_T38TIMEOUT

#define RES_FAX_T38TIMEOUT   5000

Definition at line 627 of file res_fax.c.

◆ RES_FAX_TIMEOUT

#define RES_FAX_TIMEOUT   10000

Definition at line 593 of file res_fax.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
OPT_CALLEDMODE 
OPT_CALLERMODE 
OPT_DEBUG 
OPT_STATUS 
OPT_ALLOWAUDIO 
OPT_REQUEST_T38 
OPT_FORCE_AUDIO 

Definition at line 658 of file res_fax.c.

658 {
659 OPT_CALLEDMODE = (1 << 0),
660 OPT_CALLERMODE = (1 << 1),
661 OPT_DEBUG = (1 << 2),
662 OPT_STATUS = (1 << 3),
663 OPT_ALLOWAUDIO = (1 << 5),
664 OPT_REQUEST_T38 = (1 << 6),
665 OPT_FORCE_AUDIO = (1 << 7),
666};
@ OPT_CALLEDMODE
Definition res_fax.c:659
@ OPT_REQUEST_T38
Definition res_fax.c:664
@ OPT_FORCE_AUDIO
Definition res_fax.c:665
@ OPT_CALLERMODE
Definition res_fax.c:660
@ OPT_ALLOWAUDIO
Definition res_fax.c:663
@ OPT_STATUS
Definition res_fax.c:662
@ OPT_DEBUG
Definition res_fax.c:661

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 4995 of file res_fax.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 4995 of file res_fax.c.

◆ acf_faxopt_read()

static int acf_faxopt_read ( struct ast_channel *  chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

FAXOPT read function returns the contents of a FAX option.

Definition at line 4654 of file res_fax.c.

4655{
4656 struct ast_fax_session_details *details = find_details(chan);
4657 int res = 0;
4658 char *filenames;
4659
4660 if (!details) {
4661 ast_debug(3, "channel '%s' can't read FAXOPT(%s) because it has never been written.\n", ast_channel_name(chan), data);
4662 return -1;
4663 }
4664 if (!strcasecmp(data, "ecm")) {
4665 ast_copy_string(buf, details->option.ecm ? "yes" : "no", len);
4666 } else if (!strcasecmp(data, "t38gateway") || !strcasecmp(data, "gateway") ||
4667 !strcasecmp(data, "t38_gateway") || !strcasecmp(data, "faxgateway")) {
4668 ast_copy_string(buf, details->gateway_id != -1 ? "yes" : "no", len);
4669 } else if (!strcasecmp(data, "faxdetect")) {
4670 ast_copy_string(buf, details->faxdetect_id != -1 ? "yes" : "no", len);
4671 } else if (!strcasecmp(data, "error")) {
4672 ast_copy_string(buf, details->error, len);
4673 } else if (!strcasecmp(data, "filename")) {
4674 if (AST_LIST_EMPTY(&details->documents)) {
4675 ast_debug(3, "channel '%s' can't read FAXOPT(%s) because it has never been written.\n", ast_channel_name(chan), data);
4676 res = -1;
4677 } else {
4678 ast_copy_string(buf, AST_LIST_FIRST(&details->documents)->filename, len);
4679 }
4680 } else if (!strcasecmp(data, "filenames")) {
4681 if (AST_LIST_EMPTY(&details->documents)) {
4682 ast_debug(3, "channel '%s' can't read FAXOPT(%s) because it has never been written.\n", ast_channel_name(chan), data);
4683 res = -1;
4684 } else if ((filenames = generate_filenames_string(details, "", ","))) {
4685 ast_copy_string(buf, filenames, len);
4686 ast_free(filenames);
4687 } else {
4688 ast_log(LOG_ERROR, "channel '%s' can't read FAXOPT(%s), there was an error generating the filenames list.\n", ast_channel_name(chan), data);
4689 res = -1;
4690 }
4691 } else if (!strcasecmp(data, "headerinfo")) {
4692 ast_copy_string(buf, details->headerinfo, len);
4693 } else if (!strcasecmp(data, "localstationid")) {
4695 } else if (!strcasecmp(data, "maxrate")) {
4696 snprintf(buf, len, "%u", details->maxrate);
4697 } else if (!strcasecmp(data, "minrate")) {
4698 snprintf(buf, len, "%u", details->minrate);
4699 } else if (!strcasecmp(data, "pages")) {
4700 snprintf(buf, len, "%u", details->pages_transferred);
4701 } else if (!strcasecmp(data, "rate")) {
4703 } else if (!strcasecmp(data, "remotestationid")) {
4705 } else if (!strcasecmp(data, "resolution")) {
4706 ast_copy_string(buf, details->resolution, len);
4707 } else if (!strcasecmp(data, "sessionid")) {
4708 snprintf(buf, len, "%u", details->id);
4709 } else if (!strcasecmp(data, "status")) {
4710 ast_copy_string(buf, details->result, len);
4711 } else if (!strcasecmp(data, "statusstr")) {
4712 ast_copy_string(buf, details->resultstr, len);
4713 } else if ((!strcasecmp(data, "modem")) || (!strcasecmp(data, "modems"))) {
4714 ast_fax_modem_to_str(details->modems, buf, len);
4715 } else if (!strcasecmp(data, "t38timeout")) {
4716 snprintf(buf, len, "%u", details->t38timeout);
4717 } else if (!strcasecmp(data, "negotiate_both")) {
4718 ast_copy_string(buf, details->negotiate_both != -1 ? "yes" : "no", len);
4719 } else {
4720 ast_log(LOG_WARNING, "channel '%s' can't read FAXOPT(%s) because it is unhandled!\n", ast_channel_name(chan), data);
4721 res = -1;
4722 }
4723 ao2_ref(details, -1);
4724
4725 return res;
4726}
#define ast_free(a)
Definition astmm.h:180
#define ast_log
Definition astobj2.c:42
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_WARNING
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
static struct ast_fax_session_details * find_details(struct ast_channel *chan)
returns a reference counted pointer to a fax datastore, if it exists
Definition res_fax.c:763
static int ast_fax_modem_to_str(enum ast_fax_modems bits, char *tbuf, size_t bufsize)
Definition res_fax.c:1006
static char * generate_filenames_string(struct ast_fax_session_details *details, char *prefix, char *separator)
Generate a string of filenames using the given prefix and separator.
Definition res_fax.c:1471
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
The data communicated between the high level applications and the generic fax function.
Definition res_fax.h:110
const ast_string_field localstationid
Definition res_fax.h:142
struct ast_fax_documents documents
Definition res_fax.h:119
const ast_string_field result
Definition res_fax.h:142
enum ast_fax_modems modems
Definition res_fax.h:115
unsigned int t38timeout
Definition res_fax.h:179
union ast_fax_session_details::@265 option
const ast_string_field headerinfo
Definition res_fax.h:142
unsigned int minrate
Definition res_fax.h:171
const ast_string_field resultstr
Definition res_fax.h:142
unsigned int maxrate
Definition res_fax.h:173
const ast_string_field error
Definition res_fax.h:142
unsigned int pages_transferred
Definition res_fax.h:144
const ast_string_field resolution
Definition res_fax.h:142
const ast_string_field remotestationid
Definition res_fax.h:142
const ast_string_field transfer_rate
Definition res_fax.h:142

References ao2_ref, ast_channel_name(), ast_copy_string(), ast_debug, ast_fax_modem_to_str(), ast_free, AST_LIST_EMPTY, AST_LIST_FIRST, ast_log, buf, ast_fax_session_details::documents, ast_fax_session_details::ecm, ast_fax_session_details::error, ast_fax_session_details::faxdetect_id, find_details(), ast_fax_session_details::gateway_id, generate_filenames_string(), ast_fax_session_details::headerinfo, ast_fax_session_details::id, len(), ast_fax_session_details::localstationid, LOG_ERROR, LOG_WARNING, ast_fax_session_details::maxrate, ast_fax_session_details::minrate, ast_fax_session_details::modems, ast_fax_session_details::negotiate_both, ast_fax_session_details::option, ast_fax_session_details::pages_transferred, ast_fax_session_details::remotestationid, ast_fax_session_details::resolution, ast_fax_session_details::result, ast_fax_session_details::resultstr, ast_fax_session_details::t38timeout, and ast_fax_session_details::transfer_rate.

◆ acf_faxopt_write()

static int acf_faxopt_write ( struct ast_channel *  chan,
const char *  cmd,
char *  data,
const char *  value 
)
static

FAXOPT write function modifies the contents of a FAX option.

Definition at line 4729 of file res_fax.c.

4730{
4731 int res = 0;
4732 struct ast_fax_session_details *details;
4733
4734 if (!(details = find_or_create_details(chan))) {
4735 ast_log(LOG_WARNING, "channel '%s' can't set FAXOPT(%s) to '%s' because it failed to create a datastore.\n", ast_channel_name(chan), data, value);
4736 return -1;
4737 }
4738 ast_debug(3, "channel '%s' setting FAXOPT(%s) to '%s'\n", ast_channel_name(chan), data, value);
4739
4740 if (!strcasecmp(data, "ecm")) {
4741 const char *val = ast_skip_blanks(value);
4742 if (ast_true(val)) {
4743 details->option.ecm = AST_FAX_OPTFLAG_TRUE;
4744 } else if (ast_false(val)) {
4745 details->option.ecm = AST_FAX_OPTFLAG_FALSE;
4746 } else {
4747 ast_log(LOG_WARNING, "Unsupported value '%s' passed to FAXOPT(ecm).\n", value);
4748 }
4749 } else if (!strcasecmp(data, "t38gateway") || !strcasecmp(data, "gateway") ||
4750 !strcasecmp(data, "t38_gateway") || !strcasecmp(data, "faxgateway")) {
4752 char *timeout = strchr(val, ',');
4753
4754 if (timeout) {
4755 *timeout++ = '\0';
4756 }
4757
4758 if (ast_true(val)) {
4759 if (details->gateway_id < 0) {
4760 details->gateway_timeout = 0;
4761 if (timeout) {
4762 unsigned int gwtimeout;
4763
4764 if (sscanf(timeout, "%30u", &gwtimeout) == 1) {
4765 details->gateway_timeout = gwtimeout * 1000;
4766 } else {
4767 ast_log(LOG_WARNING, "Unsupported timeout '%s' passed to FAXOPT(%s).\n", timeout, data);
4768 }
4769 }
4770
4771 details->gateway_id = fax_gateway_attach(chan, details);
4772 if (details->gateway_id < 0) {
4773 ast_log(LOG_ERROR, "Error attaching T.38 gateway to channel %s.\n", ast_channel_name(chan));
4774 res = -1;
4775 } else {
4776 ast_debug(1, "Attached T.38 gateway to channel %s.\n", ast_channel_name(chan));
4777 }
4778 } else {
4779 ast_log(LOG_WARNING, "Attempt to attach a T.38 gateway on channel (%s) with gateway already running.\n", ast_channel_name(chan));
4780 }
4781 } else if (ast_false(val)) {
4782 ast_channel_lock(chan);
4783 ast_framehook_detach(chan, details->gateway_id);
4784 ast_channel_unlock(chan);
4785 details->gateway_id = -1;
4786 } else {
4787 ast_log(LOG_WARNING, "Unsupported value '%s' passed to FAXOPT(%s).\n", value, data);
4788 }
4789 } else if (!strcasecmp(data, "faxdetect")) {
4791 char *timeout = strchr(val, ',');
4792 unsigned int fdtimeout = 0;
4793 int flags;
4794 int faxdetect;
4795
4796 if (timeout) {
4797 *timeout++ = '\0';
4798 }
4799
4800 if (ast_true(val) || !strcasecmp(val, "t38") || !strcasecmp(val, "cng")) {
4801 if (details->faxdetect_id < 0) {
4802 if (timeout) {
4803 if (sscanf(timeout, "%30u", &fdtimeout) == 1) {
4804 fdtimeout *= 1000;
4805 } else {
4806 ast_log(LOG_WARNING, "Unsupported timeout '%s' passed to FAXOPT(%s).\n",
4807 timeout, data);
4808 }
4809 }
4810
4811 if (!strcasecmp(val, "t38")) {
4812 flags = FAX_DETECT_MODE_T38;
4813 } else if (!strcasecmp(val, "cng")) {
4814 flags = FAX_DETECT_MODE_CNG;
4815 } else {
4816 flags = FAX_DETECT_MODE_BOTH;
4817 }
4818
4819 faxdetect = fax_detect_attach(chan, fdtimeout, flags);
4820 if (faxdetect < 0) {
4821 ast_log(LOG_ERROR, "Error attaching FAX detect to channel %s.\n", ast_channel_name(chan));
4822 res = -1;
4823 } else {
4824 ast_debug(1, "Attached FAX detect to channel %s.\n", ast_channel_name(chan));
4825 }
4826 } else {
4827 ast_log(LOG_WARNING, "Attempt to attach a FAX detect on channel (%s) with FAX detect already running.\n", ast_channel_name(chan));
4828 }
4829 } else if (ast_false(val)) {
4830 ast_channel_lock(chan);
4831 ast_framehook_detach(chan, details->faxdetect_id);
4832 ast_channel_unlock(chan);
4833 details->faxdetect_id = -1;
4834 } else {
4835 ast_log(LOG_WARNING, "Unsupported value '%s' passed to FAXOPT(%s).\n", value, data);
4836 }
4837 } else if (!strcasecmp(data, "headerinfo")) {
4839 } else if (!strcasecmp(data, "localstationid")) {
4841 } else if (!strcasecmp(data, "maxrate")) {
4842 details->maxrate = fax_rate_str_to_int(value);
4843 if (!details->maxrate) {
4844 details->maxrate = ast_fax_maxrate();
4845 }
4846 } else if (!strcasecmp(data, "minrate")) {
4847 details->minrate = fax_rate_str_to_int(value);
4848 if (!details->minrate) {
4849 details->minrate = ast_fax_minrate();
4850 }
4851 } else if (!strcasecmp(data, "t38timeout")) {
4852 if (set_t38timeout(value, &details->t38timeout)) {
4853 res = -1;
4854 }
4855 } else if ((!strcasecmp(data, "modem")) || (!strcasecmp(data, "modems"))) {
4856 update_modem_bits(&details->modems, value);
4857 } else if (!strcasecmp(data, "negotiate_both")) {
4859 } else {
4860 ast_log(LOG_WARNING, "channel '%s' set FAXOPT(%s) to '%s' is unhandled!\n", ast_channel_name(chan), data, value);
4861 res = -1;
4862 }
4863
4864 ao2_ref(details, -1);
4865
4866 return res;
4867}
static int fdtimeout
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
#define ast_channel_lock(chan)
Definition channel.h:2983
#define ast_channel_unlock(chan)
Definition channel.h:2984
int ast_framehook_detach(struct ast_channel *chan, int framehook_id)
Detach an framehook from a channel.
Definition framehook.c:177
unsigned int ast_fax_minrate(void)
get the minimum supported fax rate
Definition res_fax.c:905
static int update_modem_bits(enum ast_fax_modems *bits, const char *value)
Definition res_fax.c:913
#define FAX_DETECT_MODE_BOTH
Definition res_fax.c:586
static int set_t38timeout(const char *value, unsigned int *t38timeout)
Definition res_fax.c:4532
static int fax_detect_attach(struct ast_channel *chan, int timeout, int flags)
Attach a faxdetect framehook object to a channel.
Definition res_fax.c:4017
static int fax_gateway_attach(struct ast_channel *chan, struct ast_fax_session_details *details)
Attach a gateway framehook object to a channel.
Definition res_fax.c:3754
#define FAX_DETECT_MODE_T38
Definition res_fax.c:585
unsigned int ast_fax_maxrate(void)
get the maxiumum supported fax rate
Definition res_fax.c:897
static struct ast_fax_session_details * find_or_create_details(struct ast_channel *chan)
returns a reference counted details structure from the channel's fax datastore. If the datastore does...
Definition res_fax.c:865
static unsigned int fax_rate_str_to_int(const char *ratestr)
convert a rate string to a rate
Definition res_fax.c:1147
#define FAX_DETECT_MODE_CNG
FAX Detect flags.
Definition res_fax.c:584
@ AST_FAX_OPTFLAG_FALSE
Definition res_fax.h:85
@ AST_FAX_OPTFLAG_TRUE
Definition res_fax.h:87
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition utils.c:2233
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"....
Definition utils.c:2250
char *attribute_pure ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition strings.h:161
int value
Definition syslog.c:37

References ao2_ref, ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_debug, ast_false(), ast_fax_maxrate(), ast_fax_minrate(), AST_FAX_OPTFLAG_FALSE, AST_FAX_OPTFLAG_TRUE, ast_framehook_detach(), ast_log, ast_skip_blanks(), ast_strdupa, ast_string_field_set, ast_true(), ast_fax_session_details::ecm, fax_detect_attach(), FAX_DETECT_MODE_BOTH, FAX_DETECT_MODE_CNG, FAX_DETECT_MODE_T38, fax_gateway_attach(), fax_rate_str_to_int(), ast_fax_session_details::faxdetect_id, fdtimeout, find_or_create_details(), ast_fax_session_details::gateway_id, ast_fax_session_details::gateway_timeout, ast_fax_session_details::headerinfo, ast_fax_session_details::localstationid, LOG_ERROR, LOG_WARNING, ast_fax_session_details::maxrate, ast_fax_session_details::minrate, ast_fax_session_details::modems, ast_fax_session_details::negotiate_both, ast_fax_session_details::option, set_t38timeout(), ast_fax_session_details::t38timeout, update_modem_bits(), and value.

◆ ast_fax_caps_to_str()

static char * ast_fax_caps_to_str ( enum ast_fax_capabilities  caps,
char *  buf,
size_t  bufsize 
)
static

Definition at line 947 of file res_fax.c.

948{
949 char *out = buf;
950 size_t size = bufsize;
951 int first = 1;
952
953 if (caps & AST_FAX_TECH_SEND) {
954 if (!first) {
955 ast_build_string(&buf, &size, ",");
956 }
957 ast_build_string(&buf, &size, "SEND");
958 first = 0;
959 }
960 if (caps & AST_FAX_TECH_RECEIVE) {
961 if (!first) {
962 ast_build_string(&buf, &size, ",");
963 }
964 ast_build_string(&buf, &size, "RECEIVE");
965 first = 0;
966 }
967 if (caps & AST_FAX_TECH_AUDIO) {
968 if (!first) {
969 ast_build_string(&buf, &size, ",");
970 }
971 ast_build_string(&buf, &size, "AUDIO");
972 first = 0;
973 }
974 if (caps & AST_FAX_TECH_T38) {
975 if (!first) {
976 ast_build_string(&buf, &size, ",");
977 }
978 ast_build_string(&buf, &size, "T38");
979 first = 0;
980 }
981 if (caps & AST_FAX_TECH_MULTI_DOC) {
982 if (!first) {
983 ast_build_string(&buf, &size, ",");
984 }
985 ast_build_string(&buf, &size, "MULTI_DOC");
986 first = 0;
987 }
988 if (caps & AST_FAX_TECH_GATEWAY) {
989 if (!first) {
990 ast_build_string(&buf, &size, ",");
991 }
992 ast_build_string(&buf, &size, "GATEWAY");
993 first = 0;
994 }
995 if (caps & AST_FAX_TECH_V21_DETECT) {
996 if (!first) {
997 ast_build_string(&buf, &size, ",");
998 }
999 ast_build_string(&buf, &size, "V21");
1000 first = 0;
1001 }
1002
1003 return out;
1004}
struct sla_ringing_trunk * first
Definition app_sla.c:338
@ AST_FAX_TECH_T38
Definition res_fax.h:43
@ AST_FAX_TECH_AUDIO
Definition res_fax.h:41
@ AST_FAX_TECH_RECEIVE
Definition res_fax.h:39
@ AST_FAX_TECH_V21_DETECT
Definition res_fax.h:49
@ AST_FAX_TECH_MULTI_DOC
Definition res_fax.h:45
@ AST_FAX_TECH_SEND
Definition res_fax.h:37
@ AST_FAX_TECH_GATEWAY
Definition res_fax.h:47
int ast_build_string(char **buffer, size_t *space, const char *fmt,...)
Build a string in a buffer, designed to be called repeatedly.
Definition utils.c:2201
FILE * out
Definition utils/frame.c:33

References ast_build_string(), AST_FAX_TECH_AUDIO, AST_FAX_TECH_GATEWAY, AST_FAX_TECH_MULTI_DOC, AST_FAX_TECH_RECEIVE, AST_FAX_TECH_SEND, AST_FAX_TECH_T38, AST_FAX_TECH_V21_DETECT, buf, first, and out.

Referenced by fax_session_new(), and fax_session_reserve().

◆ ast_fax_log()

void ast_fax_log ( int  level,
const char *  file,
const int  line,
const char *  function,
const char *  msg 
)

Log message at FAX or recommended level.

The first four parameters can be represented with Asterisk's LOG_* levels. In other words, this function may be called like

ast_fax_log(LOG_DEBUG, msg);

Definition at line 1137 of file res_fax.c.

1138{
1139 if (fax_logger_level != -1) {
1141 } else {
1142 ast_log(level, file, line, function, "%s", msg);
1143 }
1144}
#define ast_log_dynamic_level(level,...)
Send a log message to a dynamically registered log level.
static int fax_logger_level
Definition res_fax.c:588

References ast_log, ast_log_dynamic_level, and fax_logger_level.

Referenced by spandsp_log().

◆ ast_fax_maxrate()

unsigned int ast_fax_maxrate ( void  )

get the maxiumum supported fax rate

Definition at line 897 of file res_fax.c.

898{
899 struct fax_options options;
901
902 return options.maxrate;
903}
static void get_general_options(struct fax_options *options)
Definition res_fax.c:4525
static struct test_options options

References get_general_options(), and options.

Referenced by acf_faxopt_write().

◆ ast_fax_minrate()

unsigned int ast_fax_minrate ( void  )

get the minimum supported fax rate

Definition at line 905 of file res_fax.c.

906{
907 struct fax_options options;
909
910 return options.minrate;
911}

References get_general_options(), and options.

Referenced by acf_faxopt_write().

◆ ast_fax_modem_to_str()

static int ast_fax_modem_to_str ( enum ast_fax_modems  bits,
char *  tbuf,
size_t  bufsize 
)
static

Definition at line 1006 of file res_fax.c.

1007{
1008 int count = 0;
1009
1010 if (bits & AST_FAX_MODEM_V17) {
1011 strcat(tbuf, "V17");
1012 count++;
1013 }
1014 if (bits & AST_FAX_MODEM_V27TER) {
1015 if (count) {
1016 strcat(tbuf, ",");
1017 }
1018 strcat(tbuf, "V27");
1019 count++;
1020 }
1021 if (bits & AST_FAX_MODEM_V29) {
1022 if (count) {
1023 strcat(tbuf, ",");
1024 }
1025 strcat(tbuf, "V29");
1026 count++;
1027 }
1028 if (bits & AST_FAX_MODEM_V34) {
1029 if (count) {
1030 strcat(tbuf, ",");
1031 }
1032 strcat(tbuf, "V34");
1033 count++;
1034 }
1035
1036 return 0;
1037}
@ AST_FAX_MODEM_V17
Definition res_fax.h:55
@ AST_FAX_MODEM_V29
Definition res_fax.h:59
@ AST_FAX_MODEM_V27TER
Definition res_fax.h:57
@ AST_FAX_MODEM_V34
Definition res_fax.h:61

References AST_FAX_MODEM_V17, AST_FAX_MODEM_V27TER, AST_FAX_MODEM_V29, and AST_FAX_MODEM_V34.

Referenced by acf_faxopt_read(), cli_fax_show_settings(), receivefax_exec(), sendfax_exec(), and set_config().

◆ ast_fax_session_operation_str()

const char * ast_fax_session_operation_str ( struct ast_fax_session *  s)

get string representation of a FAX session's operation

Definition at line 4382 of file res_fax.c.

4383{
4384 if (s->details->caps & AST_FAX_TECH_GATEWAY) {
4385 return "gateway";
4386 }
4387 if (s->details->caps & AST_FAX_TECH_SEND) {
4388 return "send";
4389 }
4390 if (s->details->caps & AST_FAX_TECH_RECEIVE) {
4391 return "receive";
4392 }
4394 return "V.21";
4395 }
4396
4397 return "none";
4398}
enum ast_fax_capabilities caps
Definition res_fax.h:113
struct ast_fax_session_details * details
Definition res_fax.h:208

References AST_FAX_TECH_GATEWAY, AST_FAX_TECH_RECEIVE, AST_FAX_TECH_SEND, AST_FAX_TECH_V21_DETECT, ast_fax_session_details::caps, and ast_fax_session::details.

Referenced by cli_fax_show_sessions(), manager_fax_sessions_entry(), and spandsp_manager_fax_session().

◆ ast_fax_state_to_str()

const char * ast_fax_state_to_str ( enum ast_fax_state  state)

convert a ast_fax_state to a string

convert an ast_fax_state to a string

Definition at line 1114 of file res_fax.c.

1115{
1116 switch (state) {
1118 return "Uninitialized";
1120 return "Initialized";
1121 case AST_FAX_STATE_OPEN:
1122 return "Open";
1124 return "Active";
1126 return "Complete";
1128 return "Reserved";
1130 return "Inactive";
1131 default:
1132 ast_log(LOG_WARNING, "unhandled FAX state: %u\n", state);
1133 return "Unknown";
1134 }
1135}
@ AST_FAX_STATE_INITIALIZED
Definition res_fax.h:69
@ AST_FAX_STATE_INACTIVE
Definition res_fax.h:79
@ AST_FAX_STATE_ACTIVE
Definition res_fax.h:73
@ AST_FAX_STATE_COMPLETE
Definition res_fax.h:75
@ AST_FAX_STATE_OPEN
Definition res_fax.h:71
@ AST_FAX_STATE_UNINITIALIZED
Definition res_fax.h:67
@ AST_FAX_STATE_RESERVED
Definition res_fax.h:77

References AST_FAX_STATE_ACTIVE, AST_FAX_STATE_COMPLETE, AST_FAX_STATE_INACTIVE, AST_FAX_STATE_INITIALIZED, AST_FAX_STATE_OPEN, AST_FAX_STATE_RESERVED, AST_FAX_STATE_UNINITIALIZED, ast_log, and LOG_WARNING.

Referenced by cli_fax_show_sessions(), manager_fax_sessions_entry(), spandsp_fax_cli_show_session(), spandsp_fax_write(), and spandsp_manager_fax_session().

◆ ast_fax_tech_register()

int ast_fax_tech_register ( struct ast_fax_tech *  tech)

register a FAX technology module

register a fax technology

Definition at line 1075 of file res_fax.c.

1076{
1077 struct fax_module *fax;
1078
1079 if (!(fax = ast_calloc(1, sizeof(*fax)))) {
1080 return -1;
1081 }
1082 fax->tech = tech;
1086
1087 ast_verb(3, "Registered handler for '%s' (%s)\n", fax->tech->type, fax->tech->description);
1088
1089 return 0;
1090}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
#define ast_verb(level,...)
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_RWLIST_INSERT_TAIL
const char *const type
Definition res_fax.h:237
const char *const description
Definition res_fax.h:239
registered FAX technology modules are put into this list
Definition res_fax.c:617
struct fax_module::@472 list
const struct ast_fax_tech * tech
Definition res_fax.c:618

References ast_calloc, AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_fax_tech::description, fax_module::list, fax_module::tech, and ast_fax_tech::type.

Referenced by load_module().

◆ ast_fax_tech_unregister()

void ast_fax_tech_unregister ( struct ast_fax_tech *  tech)

unregister a FAX technology module

unregister a fax technology

Definition at line 1093 of file res_fax.c.

1094{
1095 struct fax_module *fax;
1096
1097 ast_verb(3, "Unregistering FAX module type '%s'\n", tech->type);
1098
1101 if (fax->tech != tech) {
1102 continue;
1103 }
1105 ast_free(fax);
1106 ast_verb(4, "Unregistered FAX module type '%s'\n", tech->type);
1107 break;
1108 }
1111}
#define AST_RWLIST_REMOVE_CURRENT
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_RWLIST_TRAVERSE_SAFE_END

References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, fax_module::list, fax_module::tech, and ast_fax_tech::type.

Referenced by unload_module().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 4995 of file res_fax.c.

◆ check_modem_rate()

static int check_modem_rate ( enum ast_fax_modems  modems,
unsigned int  rate 
)
static

Definition at line 1039 of file res_fax.c.

1040{
1041 switch (rate) {
1042 case 2400:
1043 case 4800:
1044 if (!(modems & (AST_FAX_MODEM_V27TER | AST_FAX_MODEM_V34))) {
1045 return 1;
1046 }
1047 break;
1048 case 7200:
1049 case 9600:
1051 return 1;
1052 }
1053 break;
1054 case 12000:
1055 case 14400:
1056 if (!(modems & (AST_FAX_MODEM_V17 | AST_FAX_MODEM_V34))) {
1057 return 1;
1058 }
1059 break;
1060 case 28800:
1061 case 33600:
1062 if (!(modems & AST_FAX_MODEM_V34)) {
1063 return 1;
1064 }
1065 break;
1066 default:
1067 /* this should never happen */
1068 return 1;
1069 }
1070
1071 return 0;
1072}

References AST_FAX_MODEM_V17, AST_FAX_MODEM_V27TER, AST_FAX_MODEM_V29, AST_FAX_MODEM_V34, and fax_options::modems.

Referenced by receivefax_exec(), sendfax_exec(), and set_config().

◆ cli_fax_set_debug()

static char * cli_fax_set_debug ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
)
static

enable FAX debugging

Definition at line 4131 of file res_fax.c.

4132{
4133 int flag;
4134 const char *what;
4135
4136 switch (cmd) {
4137 case CLI_INIT:
4138 e->command = "fax set debug {on|off}";
4139 e->usage =
4140 "Usage: fax set debug { on | off }\n"
4141 " Enable/Disable FAX debugging on new FAX sessions. The basic FAX debugging will result in\n"
4142 " additional events sent to manager sessions with 'call' class permissions. When\n"
4143 " verbosity is greater than '5' events will be displayed to the console and audio versus\n"
4144 " energy analysis will be performed and displayed to the console.\n";
4145 return NULL;
4146 case CLI_GENERATE:
4147 return NULL;
4148 }
4149
4150 what = a->argv[e->args-1]; /* guaranteed to exist */
4151 if (!strcasecmp(what, "on")) {
4152 flag = 1;
4153 } else if (!strcasecmp(what, "off")) {
4154 flag = 0;
4155 } else {
4156 return CLI_SHOWUSAGE;
4157 }
4158
4160 ast_cli(a->fd, "\n\nFAX Debug %s\n\n", (flag) ? "Enabled" : "Disabled");
4161
4162 return CLI_SUCCESS;
4163}
#define CLI_SHOWUSAGE
Definition cli.h:45
#define CLI_SUCCESS
Definition cli.h:44
void ast_cli(int fd, const char *fmt,...)
Definition clicompat.c:6
@ CLI_INIT
Definition cli.h:152
@ CLI_GENERATE
Definition cli.h:153
long int flag
Definition f2c.h:83
static int global_fax_debug
Definition res_fax.c:656
#define NULL
Definition resample.c:96
int args
This gets set in ast_cli_register()
Definition cli.h:185
char * command
Definition cli.h:186
const char * usage
Definition cli.h:177
static struct test_val a

References a, ast_cli_entry::args, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, global_fax_debug, NULL, and ast_cli_entry::usage.

◆ cli_fax_show_capabilities()

static char * cli_fax_show_capabilities ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
)
static

display registered FAX capabilities

Definition at line 4166 of file res_fax.c.

4167{
4168 struct fax_module *fax;
4169 unsigned int num_modules = 0;
4170
4171 switch (cmd) {
4172 case CLI_INIT:
4173 e->command = "fax show capabilities";
4174 e->usage =
4175 "Usage: fax show capabilities\n"
4176 " Shows the capabilities of the registered FAX technology modules\n";
4177 return NULL;
4178 case CLI_GENERATE:
4179 return NULL;
4180 }
4181
4182 ast_cli(a->fd, "\n\nRegistered FAX Technology Modules:\n\n");
4185 ast_cli(a->fd, "%-15s : %s\n%-15s : %s\n%-15s : ", "Type", fax->tech->type, "Description", fax->tech->description, "Capabilities");
4186 fax->tech->cli_show_capabilities(a->fd);
4187 num_modules++;
4188 }
4190 ast_cli(a->fd, "%u registered modules\n\n", num_modules);
4191
4192 return CLI_SUCCESS;
4193}
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition linkedlists.h:78
#define AST_RWLIST_TRAVERSE
char *(*const cli_show_capabilities)(int)
Definition res_fax.h:267

References a, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, ast_fax_tech::cli_show_capabilities, CLI_SUCCESS, ast_cli_entry::command, ast_fax_tech::description, fax_module::list, NULL, fax_module::tech, ast_fax_tech::type, and ast_cli_entry::usage.

◆ cli_fax_show_session()

static char * cli_fax_show_session ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
)
static

display details of a specified fax session

Definition at line 4235 of file res_fax.c.

4236{
4237 struct ast_fax_session *s, tmp;
4238
4239 switch (cmd) {
4240 case CLI_INIT:
4241 e->command = "fax show session";
4242 e->usage =
4243 "Usage: fax show session <session number>\n"
4244 " Shows status of the named FAX session\n";
4245 return NULL;
4246 case CLI_GENERATE:
4248 }
4249
4250 if (a->argc != 4) {
4251 return CLI_SHOWUSAGE;
4252 }
4253
4254 if (sscanf(a->argv[3], "%u", &tmp.id) != 1) {
4255 ast_log(LOG_ERROR, "invalid session id: '%s'\n", a->argv[3]);
4256 return RESULT_SUCCESS;
4257 }
4258
4259 ast_cli(a->fd, "\nFAX Session Details:\n--------------------\n\n");
4260 s = ao2_find(faxregistry.container, &tmp, OBJ_POINTER);
4261 if (s) {
4262 ast_cli(a->fd, "%-22s : %s\n", "channel", s->channame);
4263 s->tech->cli_show_session(s, a->fd);
4264 ao2_ref(s, -1);
4265 }
4266 ast_cli(a->fd, "\n\n");
4267
4268 return CLI_SUCCESS;
4269}
#define OBJ_POINTER
Definition astobj2.h:1150
#define ao2_find(container, arg, flags)
Definition astobj2.h:1736
#define RESULT_SUCCESS
Definition cli.h:40
static struct @470 faxregistry
The faxregistry is used to manage information and statistics for all FAX sessions.
static char * fax_session_tab_complete(struct ast_cli_args *a)
fax session tab completion
Definition res_fax.c:4071
The data required to handle a fax session.
Definition res_fax.h:202
const struct ast_fax_tech * tech
Definition res_fax.h:214
char * channame
Definition res_fax.h:220
unsigned int id
Definition res_fax.h:204
char *(*const cli_show_session)(struct ast_fax_session *, int)
Definition res_fax.h:269

References a, ao2_find, ao2_ref, ast_cli(), ast_log, ast_fax_session::channame, CLI_GENERATE, CLI_INIT, ast_fax_tech::cli_show_session, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, fax_session_tab_complete(), faxregistry, ast_fax_session::id, LOG_ERROR, NULL, OBJ_POINTER, RESULT_SUCCESS, ast_fax_session::tech, and ast_cli_entry::usage.

◆ cli_fax_show_sessions()

static char * cli_fax_show_sessions ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
)
static

display fax sessions

Definition at line 4401 of file res_fax.c.

4402{
4403 struct ast_fax_session *s;
4404 struct ao2_iterator i;
4405 int session_count;
4406 char *filenames;
4407
4408 switch (cmd) {
4409 case CLI_INIT:
4410 e->command = "fax show sessions";
4411 e->usage =
4412 "Usage: fax show sessions\n"
4413 " Shows the current FAX sessions\n";
4414 return NULL;
4415 case CLI_GENERATE:
4416 return NULL;
4417 }
4418
4419 ast_cli(a->fd, "\nCurrent FAX Sessions:\n\n");
4420 ast_cli(a->fd, "%-30.30s %-10.10s %-10.10s %-5.5s %-10.10s %-15.15s %-30.30s\n",
4421 "Channel", "Tech", "FAXID", "Type", "Operation", "State", "File(s)");
4422 i = ao2_iterator_init(faxregistry.container, 0);
4423 while ((s = ao2_iterator_next(&i))) {
4424 ao2_lock(s);
4425
4426 filenames = generate_filenames_string(s->details, "", ", ");
4427
4428 ast_cli(a->fd, "%-30.30s %-10.10s %-10u %-5.5s %-10.10s %-15.15s %-30s\n",
4429 s->channame, s->tech->type, s->id,
4432 ast_fax_state_to_str(s->state), S_OR(filenames, ""));
4433
4434 ast_free(filenames);
4435 ao2_unlock(s);
4436 ao2_ref(s, -1);
4437 }
4440 ast_cli(a->fd, "\n%d FAX sessions\n\n", session_count);
4441
4442 return CLI_SUCCESS;
4443}
#define ao2_iterator_next(iter)
Definition astobj2.h:1911
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_unlock(a)
Definition astobj2.h:729
#define ao2_lock(a)
Definition astobj2.h:717
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
static int session_count
Definition http.c:110
const char * ast_fax_state_to_str(enum ast_fax_state state)
convert a ast_fax_state to a string
Definition res_fax.c:1114
static const char * fax_session_type(struct ast_fax_session *s)
Definition res_fax.c:4370
const char * ast_fax_session_operation_str(struct ast_fax_session *s)
get string representation of a FAX session's operation
Definition res_fax.c:4382
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition astobj2.h:1821
enum ast_fax_state state
Definition res_fax.h:218

References a, ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, ast_cli(), ast_fax_session_operation_str(), ast_fax_state_to_str(), ast_free, ast_fax_session::channame, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_fax_session::details, fax_session_type(), faxregistry, generate_filenames_string(), ast_fax_session::id, NULL, S_OR, session_count, ast_fax_session::state, ast_fax_session::tech, ast_fax_tech::type, and ast_cli_entry::usage.

◆ cli_fax_show_settings()

static char * cli_fax_show_settings ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
)
static

display global defaults and settings

Definition at line 4196 of file res_fax.c.

4197{
4198 struct fax_module *fax;
4199 char modems[128] = "";
4200 struct fax_options options;
4201
4202 switch (cmd) {
4203 case CLI_INIT:
4204 e->command = "fax show settings";
4205 e->usage =
4206 "Usage: fax show settings\n"
4207 " Show the global settings and defaults of both the FAX core and technology modules\n";
4208 return NULL;
4209 case CLI_GENERATE:
4210 return NULL;
4211 }
4212
4214
4215 ast_cli(a->fd, "FAX For Asterisk Settings:\n");
4216 ast_cli(a->fd, "\tECM: %s\n", options.ecm ? "Enabled" : "Disabled");
4217 ast_cli(a->fd, "\tStatus Events: %s\n", options.statusevents ? "On" : "Off");
4218 ast_cli(a->fd, "\tMinimum Bit Rate: %u\n", options.minrate);
4219 ast_cli(a->fd, "\tMaximum Bit Rate: %u\n", options.maxrate);
4220 ast_fax_modem_to_str(options.modems, modems, sizeof(modems));
4221 ast_cli(a->fd, "\tModem Modulations Allowed: %s\n", modems);
4222 ast_cli(a->fd, "\tT.38 Negotiation Timeout: %u\n", options.t38timeout);
4223 ast_cli(a->fd, "\n\nFAX Technology Modules:\n\n");
4225 AST_RWLIST_TRAVERSE(&faxmodules, fax, list) {
4226 ast_cli(a->fd, "%s (%s) Settings:\n", fax->tech->type, fax->tech->description);
4227 fax->tech->cli_show_settings(a->fd);
4228 }
4230
4231 return CLI_SUCCESS;
4232}
char *(*const cli_show_settings)(int)
Definition res_fax.h:276
enum ast_fax_modems modems
Definition res_fax.c:630

References a, ast_cli(), ast_fax_modem_to_str(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, ast_fax_tech::cli_show_settings, CLI_SUCCESS, ast_cli_entry::command, ast_fax_tech::description, get_general_options(), fax_options::modems, NULL, options, fax_module::tech, ast_fax_tech::type, and ast_cli_entry::usage.

◆ cli_fax_show_stats()

static char * cli_fax_show_stats ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
)
static

display fax stats

Definition at line 4309 of file res_fax.c.

4310{
4311 struct fax_module *fax;
4312
4313 switch (cmd) {
4314 case CLI_INIT:
4315 e->command = "fax show stats";
4316 e->usage =
4317 "Usage: fax show stats\n"
4318 " Shows a statistical summary of FAX transmissions\n";
4319 return NULL;
4320 case CLI_GENERATE:
4321 return NULL;
4322 }
4323
4324 ast_cli(a->fd, "\nFAX Statistics:\n---------------\n\n");
4325 ast_cli(a->fd, "%-20.20s : %d\n", "Current Sessions", faxregistry.active_sessions);
4326 ast_cli(a->fd, "%-20.20s : %d\n", "Reserved Sessions", faxregistry.reserved_sessions);
4327 ast_cli(a->fd, "%-20.20s : %d\n", "Transmit Attempts", faxregistry.fax_tx_attempts);
4328 ast_cli(a->fd, "%-20.20s : %d\n", "Receive Attempts", faxregistry.fax_rx_attempts);
4329 ast_cli(a->fd, "%-20.20s : %d\n", "Completed FAXes", faxregistry.fax_complete);
4330 ast_cli(a->fd, "%-20.20s : %d\n", "Failed FAXes", faxregistry.fax_failures);
4333 fax->tech->cli_show_stats(a->fd);
4334 }
4336 ast_cli(a->fd, "\n\n");
4337
4338 return CLI_SUCCESS;
4339}
char *(*const cli_show_stats)(int)
Definition res_fax.h:274

References a, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, ast_fax_tech::cli_show_stats, CLI_SUCCESS, ast_cli_entry::command, faxregistry, fax_module::list, NULL, fax_module::tech, and ast_cli_entry::usage.

◆ cli_fax_show_version()

static char * cli_fax_show_version ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
)
static

Definition at line 4099 of file res_fax.c.

4100{
4101 struct fax_module *fax;
4102
4103 switch(cmd) {
4104 case CLI_INIT:
4105 e->command = "fax show version";
4106 e->usage =
4107 "Usage: fax show version\n"
4108 " Show versions of FAX For Asterisk components.\n";
4109 return NULL;
4110 case CLI_GENERATE:
4111 return NULL;
4112 }
4113
4114 if (a->argc != 3) {
4115 return CLI_SHOWUSAGE;
4116 }
4117
4118 ast_cli(a->fd, "FAX For Asterisk Components:\n");
4119 ast_cli(a->fd, "\tApplications: %s\n", ast_get_version());
4122 ast_cli(a->fd, "\t%s: %s\n", fax->tech->description, fax->tech->version);
4123 }
4125 ast_cli(a->fd, "\n");
4126
4127 return CLI_SUCCESS;
4128}
const char * ast_get_version(void)
Retrieve the Asterisk version string.
const char *const version
Definition res_fax.h:241

References a, ast_cli(), ast_get_version(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_fax_tech::description, fax_module::list, NULL, fax_module::tech, ast_cli_entry::usage, and ast_fax_tech::version.

◆ debug_check_frame_for_silence()

static void debug_check_frame_for_silence ( struct ast_fax_session *  s,
unsigned int  c2s,
struct ast_frame *  frame 
)
static

Definition at line 678 of file res_fax.c.

679{
680 struct debug_info_history *history = c2s ? &s->debug_info->c2s : &s->debug_info->s2c;
681 int dspsilence;
682 unsigned int last_consec_frames, last_consec_ms;
683 unsigned char wassil;
684 struct timeval diff;
685
686 diff = ast_tvsub(ast_tvnow(), s->debug_info->base_tv);
687
689 ast_dsp_silence(s->debug_info->dsp, frame, &dspsilence);
690
691 wassil = history->silence;
692 history->silence = (dspsilence != 0) ? 1 : 0;
693 if (history->silence != wassil) {
694 last_consec_frames = history->consec_frames;
695 last_consec_ms = history->consec_ms;
696 history->consec_frames = 0;
697 history->consec_ms = 0;
698
699 if ((last_consec_frames != 0)) {
700 ast_verb(0, "Channel '%s' fax session '%u', [ %.3ld.%.6ld ], %s sent %u frames (%u ms) of %s.\n",
701 s->channame, s->id, (long) diff.tv_sec, (long int) diff.tv_usec,
702 (c2s) ? "channel" : "stack", last_consec_frames, last_consec_ms,
703 (wassil) ? "silence" : "energy");
704 }
705 }
706
707 history->consec_frames++;
708 history->consec_ms += (frame->samples / 8);
709}
int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
Process the audio frame for silence.
Definition dsp.c:1672
void ast_dsp_reset(struct ast_dsp *dsp)
Reset total silence count.
Definition dsp.c:2028
struct debug_info_history c2s s2c
Definition res_fax.c:540
struct timeval base_tv
Definition res_fax.c:539
struct ast_dsp * dsp
Definition res_fax.c:541
struct ast_fax_debug_info * debug_info
Definition res_fax.h:226
unsigned int consec_ms
Definition res_fax.c:534
unsigned int consec_frames
Definition res_fax.c:533
unsigned char silence
Definition res_fax.c:535
struct timeval ast_tvsub(struct timeval a, struct timeval b)
Returns the difference of two timevals a - b.
Definition extconf.c:2293
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159

References ast_dsp_reset(), ast_dsp_silence(), ast_tvnow(), ast_tvsub(), ast_verb, ast_fax_debug_info::base_tv, ast_fax_session::channame, debug_info_history::consec_frames, debug_info_history::consec_ms, ast_fax_session::debug_info, ast_fax_debug_info::dsp, ast_fax_session::id, ast_fax_debug_info::s2c, ast_frame::samples, and debug_info_history::silence.

Referenced by generic_fax_exec().

◆ destroy_callback()

static void destroy_callback ( void *  data)
static

Definition at line 711 of file res_fax.c.

712{
713 if (data) {
714 ao2_ref(data, -1);
715 }
716}

References ao2_ref.

◆ destroy_faxdetect()

static void destroy_faxdetect ( void *  data)
static

destroy a FAX detect structure

Definition at line 3804 of file res_fax.c.

3805{
3806 struct fax_detect *faxdetect = data;
3807
3808 if (faxdetect->dsp) {
3809 ast_dsp_free(faxdetect->dsp);
3810 faxdetect->dsp = NULL;
3811 }
3812 ao2_cleanup(faxdetect->details);
3813 ao2_cleanup(faxdetect->orig_format);
3814}
#define ao2_cleanup(obj)
Definition astobj2.h:1934
void ast_dsp_free(struct ast_dsp *dsp)
Definition dsp.c:1968
used for fax detect framehook
Definition res_fax.c:570
struct ast_dsp * dsp
DSP Processor.
Definition res_fax.c:574
struct ast_format * orig_format
original audio formats
Definition res_fax.c:576
struct ast_fax_session_details * details
fax session details
Definition res_fax.c:578

References ao2_cleanup, ast_dsp_free(), fax_detect::details, fax_detect::dsp, NULL, and fax_detect::orig_format.

Referenced by fax_detect_new().

◆ destroy_gateway()

static void destroy_gateway ( void *  data)
static

destroy a FAX gateway session structure

Definition at line 2940 of file res_fax.c.

2941{
2942 struct fax_gateway *gateway = data;
2943
2944 destroy_v21_sessions(gateway);
2945
2946 if (gateway->s) {
2947 fax_session_release(gateway->s, gateway->token);
2948 gateway->token = NULL;
2949
2950 ao2_unlink(faxregistry.container, gateway->s);
2951
2952 ao2_ref(gateway->s, -1);
2953 gateway->s = NULL;
2954 }
2955
2956 ao2_cleanup(gateway->chan_read_format);
2958 ao2_cleanup(gateway->peer_read_format);
2960}
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition astobj2.h:1578
static void fax_session_release(struct ast_fax_session *s, struct ast_fax_tech_token *token)
Release a session token.
Definition res_fax.c:1184
static void destroy_v21_sessions(struct fax_gateway *gateway)
destroy the v21 detection parts of a fax gateway session
Definition res_fax.c:2922
used for gateway framehook
Definition res_fax.c:545
struct ast_format * chan_read_format
original audio formats
Definition res_fax.c:563
struct ast_format * chan_write_format
Definition res_fax.c:564
struct ast_format * peer_write_format
Definition res_fax.c:566
struct ast_format * peer_read_format
Definition res_fax.c:565
struct ast_fax_session * s
FAX Session.
Definition res_fax.c:547
struct ast_fax_tech_token * token
reserved fax session token
Definition res_fax.c:551

References ao2_cleanup, ao2_ref, ao2_unlink, fax_gateway::chan_read_format, fax_gateway::chan_write_format, destroy_v21_sessions(), fax_session_release(), faxregistry, NULL, fax_gateway::peer_read_format, fax_gateway::peer_write_format, fax_gateway::s, and fax_gateway::token.

Referenced by fax_gateway_new().

◆ destroy_session()

static void destroy_session ( void *  session)
static

destroy a FAX session structure

Definition at line 1197 of file res_fax.c.

1198{
1199 struct ast_fax_session *s = session;
1200
1201 if (s->tech) {
1203 if (s->tech_pvt) {
1204 s->tech->destroy_session(s);
1205 }
1206 ast_module_unref(s->tech->module);
1207 }
1208
1209 if (s->details) {
1210 if (s->details->caps & AST_FAX_TECH_GATEWAY) {
1211 s->details->caps &= ~AST_FAX_TECH_GATEWAY;
1212 }
1213 ao2_ref(s->details, -1);
1214 s->details = NULL;
1215 }
1216
1217 if (s->debug_info) {
1219 ast_free(s->debug_info);
1220 }
1221
1222 if (s->smoother) {
1224 }
1225
1226 if (s->state != AST_FAX_STATE_INACTIVE) {
1227 ast_atomic_fetchadd_int(&faxregistry.active_sessions, -1);
1228 }
1229
1230 ast_free(s->channame);
1232}
static struct ast_mansession session
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:764
#define ast_module_unref(mod)
Release a reference to the module.
Definition module.h:483
void ast_smoother_free(struct ast_smoother *s)
Definition smoother.c:220
void * tech_pvt
Definition res_fax.h:216
char * chan_uniqueid
Definition res_fax.h:222
struct ast_smoother * smoother
Definition res_fax.h:228
void(*const destroy_session)(struct ast_fax_session *)
Definition res_fax.h:253

References ao2_ref, ast_atomic_fetchadd_int(), ast_dsp_free(), AST_FAX_STATE_INACTIVE, AST_FAX_TECH_GATEWAY, ast_free, ast_module_unref, ast_smoother_free(), ast_fax_session_details::caps, ast_fax_session::chan_uniqueid, ast_fax_session::channame, ast_fax_session::debug_info, ast_fax_tech::destroy_session, ast_fax_session::details, ast_fax_debug_info::dsp, fax_session_release(), faxregistry, NULL, session, ast_fax_session::smoother, ast_fax_session::state, ast_fax_session::tech, and ast_fax_session::tech_pvt.

Referenced by fax_session_new(), and fax_session_reserve().

◆ destroy_session_details()

static void destroy_session_details ( void *  details)
static

destroy a FAX session details structure

Definition at line 785 of file res_fax.c.

786{
787 struct ast_fax_session_details *d = details;
788 struct ast_fax_document *doc;
789
790 while ((doc = AST_LIST_REMOVE_HEAD(&d->documents, next))) {
791 ast_free(doc);
792 }
794}
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
struct ast_fax_document * next
Definition res_fax.h:103
static struct test_val d

References ast_free, AST_LIST_REMOVE_HEAD, ast_string_field_free_memory, d, and ast_fax_document::next.

Referenced by session_details_new().

◆ destroy_v21_sessions()

static void destroy_v21_sessions ( struct fax_gateway *  gateway)
static

destroy the v21 detection parts of a fax gateway session

Definition at line 2922 of file res_fax.c.

2923{
2924 if (gateway->chan_v21_session) {
2925 ao2_unlink(faxregistry.container, gateway->chan_v21_session);
2926
2927 ao2_ref(gateway->chan_v21_session, -1);
2928 gateway->chan_v21_session = NULL;
2929 }
2930
2931 if (gateway->peer_v21_session) {
2932 ao2_unlink(faxregistry.container, gateway->peer_v21_session);
2933
2934 ao2_ref(gateway->peer_v21_session, -1);
2935 gateway->peer_v21_session = NULL;
2936 }
2937}
struct ast_fax_session * peer_v21_session
Definition res_fax.c:548
struct ast_fax_session * chan_v21_session
Definition res_fax.c:549

References ao2_ref, ao2_unlink, fax_gateway::chan_v21_session, faxregistry, NULL, and fax_gateway::peer_v21_session.

Referenced by destroy_gateway(), fax_gateway_detect_v21(), and fax_gateway_start().

◆ disable_t38()

static int disable_t38 ( struct ast_channel *  chan)
static

Definition at line 1628 of file res_fax.c.

1629{
1630 int timeout_ms;
1631 struct ast_frame *frame = NULL;
1633 struct timeval start;
1634 int ms;
1635
1636 ast_debug(1, "Shutting down T.38 on %s\n", ast_channel_name(chan));
1637 if (ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters)) != 0) {
1638 ast_debug(1, "error while disabling T.38 on channel '%s'\n", ast_channel_name(chan));
1639 return -1;
1640 }
1641
1642 /* wait up to five seconds for negotiation to complete */
1643 timeout_ms = 5000;
1644 start = ast_tvnow();
1645 while ((ms = ast_remaining_ms(start, timeout_ms))) {
1646 ms = ast_waitfor(chan, ms);
1647
1648 if (ms == 0) {
1649 break;
1650 }
1651 if (ms < 0) {
1652 ast_debug(1, "error while disabling T.38 on channel '%s'\n", ast_channel_name(chan));
1653 return -1;
1654 }
1655
1656 if (!(frame = ast_read(chan))) {
1657 return -1;
1658 }
1659 if ((frame->frametype == AST_FRAME_CONTROL) &&
1661 (frame->datalen == sizeof(t38_parameters))) {
1662 struct ast_control_t38_parameters *parameters = frame->data.ptr;
1663
1664 switch (parameters->request_response) {
1665 case AST_T38_TERMINATED:
1666 ast_debug(1, "Shut down T.38 on %s\n", ast_channel_name(chan));
1667 break;
1668 case AST_T38_REFUSED:
1669 ast_log(LOG_WARNING, "channel '%s' refused to disable T.38\n", ast_channel_name(chan));
1670 ast_frfree(frame);
1671 return -1;
1672 default:
1673 ast_log(LOG_ERROR, "channel '%s' failed to disable T.38\n", ast_channel_name(chan));
1674 ast_frfree(frame);
1675 return -1;
1676 }
1677 ast_frfree(frame);
1678 break;
1679 }
1680 ast_frfree(frame);
1681 }
1682
1683 if (ms == 0) { /* all done, nothing happened */
1684 ast_debug(1, "channel '%s' timed-out during T.38 shutdown\n", ast_channel_name(chan));
1685 }
1686
1687 return 0;
1688}
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition channel.c:3166
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition channel.c:4278
int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
Definition channel.c:4676
@ AST_T38_TERMINATED
@ AST_T38_REQUEST_TERMINATE
#define ast_frfree(fr)
@ AST_FRAME_CONTROL
@ AST_CONTROL_T38_PARAMETERS
enum ast_control_t38 request_response
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
enum ast_frame_type frametype
union ast_frame::@237 data
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition utils.c:2315

References ast_channel_name(), AST_CONTROL_T38_PARAMETERS, ast_debug, AST_FRAME_CONTROL, ast_frfree, ast_indicate_data(), ast_log, ast_read(), ast_remaining_ms(), AST_T38_REFUSED, AST_T38_REQUEST_TERMINATE, AST_T38_TERMINATED, ast_tvnow(), ast_waitfor(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, ast_frame_subclass::integer, LOG_ERROR, LOG_WARNING, NULL, ast_frame::ptr, ast_control_t38_parameters::request_response, and ast_frame::subclass.

Referenced by receivefax_exec(), and sendfax_exec().

◆ fax_detect_attach()

static int fax_detect_attach ( struct ast_channel *  chan,
int  timeout,
int  flags 
)
static

Attach a faxdetect framehook object to a channel.

Parameters
chanthe channel to attach to
timeoutin ms to remove framehook in this time if not zero
Returns
the faxdetect structure or NULL on error
Parameters
flagsrequired options
Return values
-1error

Definition at line 4017 of file res_fax.c.

4018{
4019 struct fax_detect *faxdetect;
4020 struct ast_fax_session_details *details;
4021 struct ast_framehook_interface fr_hook = {
4023 .event_cb = fax_detect_framehook,
4024 .destroy_cb = fax_detect_framehook_destroy,
4025 };
4026
4027 if (!(details = find_or_create_details(chan))) {
4028 ast_log(LOG_ERROR, "System cannot provide memory for session requirements.\n");
4029 return -1;
4030 }
4031
4032 /* set up the frame hook*/
4033 faxdetect = fax_detect_new(chan, timeout, flags);
4034 if (!faxdetect) {
4035 ao2_ref(details, -1);
4036 return -1;
4037 }
4038
4039 fr_hook.data = faxdetect;
4040 faxdetect->details = details;
4041 ast_channel_lock(chan);
4042 details->faxdetect_id = ast_framehook_attach(chan, &fr_hook);
4043 details->faxdetect_timeout = timeout;
4044 details->faxdetect_flags = flags;
4045 ast_channel_unlock(chan);
4046
4047 if (details->faxdetect_id < 0) {
4048 ao2_ref(faxdetect, -1);
4049 }
4050
4051 return details->faxdetect_id;
4052}
int ast_framehook_attach(struct ast_channel *chan, struct ast_framehook_interface *i)
Attach an framehook onto a channel for frame interception.
Definition framehook.c:132
#define AST_FRAMEHOOK_INTERFACE_VERSION
Definition framehook.h:227
static void fax_detect_framehook_destroy(void *data)
Deref the faxdetect data structure when the faxdetect framehook is detached.
Definition res_fax.c:3855
static struct fax_detect * fax_detect_new(struct ast_channel *chan, int timeout, int flags)
Create a new fax detect object.
Definition res_fax.c:3822
static struct ast_frame * fax_detect_framehook(struct ast_channel *chan, struct ast_frame *f, enum ast_framehook_event event, void *data)
Fax Detect Framehook.
Definition res_fax.c:3873

References ao2_ref, ast_channel_lock, ast_channel_unlock, ast_framehook_attach(), AST_FRAMEHOOK_INTERFACE_VERSION, ast_log, ast_framehook_interface::data, fax_detect::details, fax_detect_framehook(), fax_detect_framehook_destroy(), fax_detect_new(), ast_fax_session_details::faxdetect_flags, ast_fax_session_details::faxdetect_id, ast_fax_session_details::faxdetect_timeout, find_or_create_details(), LOG_ERROR, and ast_framehook_interface::version.

Referenced by acf_faxopt_write(), and fixup_callback().

◆ fax_detect_framehook()

static struct ast_frame * fax_detect_framehook ( struct ast_channel *  chan,
struct ast_frame *  f,
enum ast_framehook_event  event,
void *  data 
)
static

Fax Detect Framehook.

Listen for fax tones in audio path and enable jumping to a extension when detected.

Parameters
chanchannel
fframe to handle may be NULL
eventframehook event
dataframehook data (struct fax_detect *)
Returns
processed frame or NULL when f is NULL or a null frame

Definition at line 3873 of file res_fax.c.

3874{
3875 struct fax_detect *faxdetect = data;
3876 struct ast_fax_session_details *details;
3877 struct ast_control_t38_parameters *control_params;
3878 RAII_VAR(struct ast_channel *, peer, NULL, ao2_cleanup);
3879 RAII_VAR(struct ast_channel *, chan_ref, chan, ao2_cleanup);
3880 int result = 0;
3881
3882 /* Ref bump the channel for when we have to unlock it */
3883 ao2_ref(chan, 1);
3884
3885 details = faxdetect->details;
3886
3887 switch (event) {
3889 /* Setup format for DSP on ATTACH*/
3891
3896 ast_framehook_detach(chan, details->faxdetect_id);
3897 details->faxdetect_id = -1;
3898 return f;
3899 }
3900 }
3901
3902 return NULL;
3904 /* restore audio formats when we are detached */
3905 ast_set_read_format(chan, faxdetect->orig_format);
3906 ast_channel_unlock(chan);
3907 peer = ast_channel_bridge_peer(chan);
3908 if (peer) {
3909 ast_channel_make_compatible(chan, peer);
3910 }
3911 ast_channel_lock(chan);
3912 return NULL;
3914 if (f) {
3915 break;
3916 }
3917 default:
3918 return f;
3919 };
3920
3921 if (details->faxdetect_id < 0) {
3922 return f;
3923 }
3924
3925 if (!ast_tvzero(faxdetect->timeout_start)
3926 && ast_tvdiff_ms(ast_tvnow(), faxdetect->timeout_start) > details->faxdetect_timeout) {
3927 ast_debug(1, "FAXOPT(faxdetect) timeout on %s\n", ast_channel_name(chan));
3928 ast_framehook_detach(chan, details->faxdetect_id);
3929 details->faxdetect_id = -1;
3930 return f;
3931 }
3932
3933 /* only handle VOICE and CONTROL frames*/
3934 switch (f->frametype) {
3935 case AST_FRAME_VOICE:
3936 /* we have no DSP this means we not detecting CNG */
3937 if (!faxdetect->dsp) {
3938 return f;
3939 }
3940 /* We can only process some formats*/
3944 return f;
3945 }
3946 break;
3947 case AST_FRAME_CONTROL:
3949 (faxdetect->flags & FAX_DETECT_MODE_T38)) {
3950 break;
3951 }
3952 return f;
3953 default:
3954 return f;
3955 }
3956
3957 if (f->frametype == AST_FRAME_VOICE) {
3958 f = ast_dsp_process(chan, faxdetect->dsp, f);
3959 if (f->frametype == AST_FRAME_DTMF) {
3960 result = f->subclass.integer;
3961 }
3962 } else if ((f->frametype == AST_FRAME_CONTROL) && (f->datalen == sizeof(struct ast_control_t38_parameters))) {
3963 control_params = f->data.ptr;
3964 switch (control_params->request_response) {
3965 case AST_T38_NEGOTIATED:
3967 result = 't';
3968 break;
3969 default:
3970 break;
3971 }
3972 }
3973
3974 if (result) {
3975 const char *target_context;
3976
3977 switch (result) {
3978 case 'f':
3979 case 't':
3980 target_context = ast_channel_context(chan);
3981
3982 ast_channel_unlock(chan);
3983 ast_frfree(f);
3984 f = &ast_null_frame;
3985 if (ast_exists_extension(chan, target_context, "fax", 1,
3986 S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
3987 ast_verb(2, "Redirecting '%s' to fax extension due to %s detection\n",
3988 ast_channel_name(chan), (result == 'f') ? "CNG" : "T38");
3989 pbx_builtin_setvar_helper(chan, "FAXEXTEN", ast_channel_exten(chan));
3990 if (ast_async_goto(chan, target_context, "fax", 1)) {
3991 ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", ast_channel_name(chan), target_context);
3992 }
3993 } else {
3994 ast_log(LOG_NOTICE, "FAX %s detected but no fax extension in context (%s)\n",
3995 (result == 'f') ? "CNG" : "T38", target_context);
3996 }
3997 ast_channel_lock(chan);
3998
3999 ast_framehook_detach(chan, details->faxdetect_id);
4000 details->faxdetect_id = -1;
4001 break;
4002 default:
4003 break;
4004 }
4005 }
4006
4007 return f;
4008}
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition astobj2.h:501
struct ast_channel * ast_channel_bridge_peer(struct ast_channel *chan)
Get the channel's bridge peer only if the bridge is two-party.
Definition channel.c:10744
int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
Make the frame formats of two channels compatible.
Definition channel.c:6739
const char * ast_channel_context(const struct ast_channel *chan)
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
Definition channel.c:5785
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
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:1683
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_EQUAL
Definition format.h:36
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
struct ast_format * ast_format_alaw
Built-in cached alaw format.
@ AST_FRAMEHOOK_EVENT_ATTACHED
Definition framehook.h:154
@ AST_FRAMEHOOK_EVENT_DETACHED
Definition framehook.h:155
@ AST_FRAMEHOOK_EVENT_READ
Definition framehook.h:152
@ AST_T38_NEGOTIATED
@ AST_T38_REQUEST_NEGOTIATE
#define AST_FRAME_DTMF
struct ast_frame ast_null_frame
Definition main/frame.c:79
#define LOG_NOTICE
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:2735
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.
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.
Definition pbx.c:5251
#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:87
Main Channel structure associated with a channel.
struct ast_format * format
struct timeval timeout_start
the start of our timeout counter
Definition res_fax.c:572
int flags
mode
Definition res_fax.c:580
Number structure.
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition time.h:117
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition time.h:107
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981

References ao2_cleanup, ao2_ref, ao2_replace, ast_async_goto(), ast_channel_bridge_peer(), ast_channel_caller(), ast_channel_context(), ast_channel_exten(), ast_channel_lock, ast_channel_make_compatible(), ast_channel_name(), ast_channel_readformat(), ast_channel_unlock, AST_CONTROL_T38_PARAMETERS, ast_debug, ast_dsp_process(), ast_exists_extension(), ast_format_alaw, ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_slin, ast_format_ulaw, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_VOICE, ast_framehook_detach(), AST_FRAMEHOOK_EVENT_ATTACHED, AST_FRAMEHOOK_EVENT_DETACHED, AST_FRAMEHOOK_EVENT_READ, ast_frfree, ast_log, ast_null_frame, ast_set_read_format(), AST_T38_NEGOTIATED, AST_T38_REQUEST_NEGOTIATE, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_verb, ast_frame::data, ast_frame::datalen, fax_detect::details, fax_detect::dsp, FAX_DETECT_MODE_T38, ast_fax_session_details::faxdetect_id, ast_fax_session_details::faxdetect_timeout, fax_detect::flags, ast_frame_subclass::format, ast_frame::frametype, ast_frame_subclass::integer, LOG_NOTICE, NULL, fax_detect::orig_format, pbx_builtin_setvar_helper(), ast_frame::ptr, RAII_VAR, ast_control_t38_parameters::request_response, result, S_COR, ast_frame::subclass, and fax_detect::timeout_start.

Referenced by fax_detect_attach().

◆ fax_detect_framehook_destroy()

static void fax_detect_framehook_destroy ( void *  data)
static

Deref the faxdetect data structure when the faxdetect framehook is detached.

Parameters
dataframehook data (faxdetect data)

Definition at line 3855 of file res_fax.c.

3856{
3857 struct fax_detect *faxdetect = data;
3858
3859 ao2_ref(faxdetect, -1);
3860}

References ao2_ref.

Referenced by fax_detect_attach().

◆ fax_detect_new()

static struct fax_detect * fax_detect_new ( struct ast_channel *  chan,
int  timeout,
int  flags 
)
static

Create a new fax detect object.

Parameters
chanthe channel attaching to
timeoutin ms to remove framehook in this time if not zero
flagsrequired options
Returns
NULL or a fax gateway object

Definition at line 3822 of file res_fax.c.

3823{
3824 struct fax_detect *faxdetect = ao2_alloc(sizeof(*faxdetect), destroy_faxdetect);
3825 if (!faxdetect) {
3826 return NULL;
3827 }
3828
3829 faxdetect->flags = flags;
3830
3831 if (timeout) {
3832 faxdetect->timeout_start = ast_tvnow();
3833 } else {
3834 faxdetect->timeout_start.tv_sec = 0;
3835 faxdetect->timeout_start.tv_usec = 0;
3836 }
3837
3838 if (faxdetect->flags & FAX_DETECT_MODE_CNG) {
3839 faxdetect->dsp = ast_dsp_new();
3840 if (!faxdetect->dsp) {
3841 ao2_ref(faxdetect, -1);
3842 return NULL;
3843 }
3846 } else {
3847 faxdetect->dsp = NULL;
3848 }
3849
3850 return faxdetect;
3851}
#define ao2_alloc(data_size, destructor_fn)
Definition astobj2.h:409
#define DSP_FEATURE_FAX_DETECT
Definition dsp.h:29
#define DSP_FAXMODE_DETECT_SQUELCH
Definition dsp.h:51
#define DSP_FAXMODE_DETECT_CNG
Definition dsp.h:49
int ast_dsp_set_faxmode(struct ast_dsp *dsp, int faxmode)
Set fax mode.
Definition dsp.c:2070
void ast_dsp_set_features(struct ast_dsp *dsp, int features)
Select feature set.
Definition dsp.c:1953
struct ast_dsp * ast_dsp_new(void)
Allocates a new dsp, assumes 8khz for internal sample rate.
Definition dsp.c:1943
static void destroy_faxdetect(void *data)
destroy a FAX detect structure
Definition res_fax.c:3804

References ao2_alloc, ao2_ref, ast_dsp_new(), ast_dsp_set_faxmode(), ast_dsp_set_features(), ast_tvnow(), destroy_faxdetect(), fax_detect::dsp, DSP_FAXMODE_DETECT_CNG, DSP_FAXMODE_DETECT_SQUELCH, DSP_FEATURE_FAX_DETECT, FAX_DETECT_MODE_CNG, fax_detect::flags, NULL, and fax_detect::timeout_start.

Referenced by fax_detect_attach().

◆ fax_gateway_attach()

static int fax_gateway_attach ( struct ast_channel *  chan,
struct ast_fax_session_details *  details 
)
static

Attach a gateway framehook object to a channel.

Parameters
chanthe channel to attach to
detailsfax session details
Returns
the framehook id of the attached framehook or -1 on error
Return values
-1error

Definition at line 3754 of file res_fax.c.

3755{
3756 struct fax_gateway *gateway;
3757 struct ast_framehook_interface fr_hook = {
3759 .event_cb = fax_gateway_framehook,
3760 .destroy_cb = fax_gateway_framehook_destroy,
3761 .disable_inheritance = 1, /* Masquerade inheritance is handled through the datastore fixup */
3762 };
3763
3764 if (global_fax_debug) {
3766 }
3767
3768 ast_string_field_set(details, result, "SUCCESS");
3769 ast_string_field_set(details, resultstr, "gateway operation started successfully");
3770 ast_string_field_set(details, error, "NO_ERROR");
3771 set_channel_variables(chan, details);
3772
3773 /* set up the frame hook*/
3774 gateway = fax_gateway_new(chan, details);
3775 if (!gateway) {
3776 ast_string_field_set(details, result, "FAILED");
3777 ast_string_field_set(details, resultstr, "error initializing gateway session");
3778 ast_string_field_set(details, error, "INIT_ERROR");
3779 details->is_t38_negotiated = 0;
3780 set_channel_variables(chan, details);
3781 report_fax_status(chan, details, "No Available Resource");
3782 return -1;
3783 }
3784
3785 fr_hook.data = gateway;
3786 ast_channel_lock(chan);
3787 gateway->framehook = ast_framehook_attach(chan, &fr_hook);
3788 ast_channel_unlock(chan);
3789
3790 if (gateway->framehook < 0) {
3791 ao2_ref(gateway, -1);
3792 ast_string_field_set(details, result, "FAILED");
3793 ast_string_field_set(details, resultstr, "error attaching gateway to channel");
3794 ast_string_field_set(details, error, "INIT_ERROR");
3795 details->is_t38_negotiated = 0;
3796 set_channel_variables(chan, details);
3797 return -1;
3798 }
3799
3800 return gateway->framehook;
3801}
static int report_fax_status(struct ast_channel *chan, struct ast_fax_session_details *details, const char *status)
send a FAX status manager event
Definition res_fax.c:1508
static struct ast_frame * fax_gateway_framehook(struct ast_channel *chan, struct ast_frame *f, enum ast_framehook_event event, void *data)
T.30<->T.38 gateway framehook.
Definition res_fax.c:3488
static void fax_gateway_framehook_destroy(void *data)
Destroy the gateway data structure when the framehook is detached.
Definition res_fax.c:3447
static struct fax_gateway * fax_gateway_new(struct ast_channel *chan, struct ast_fax_session_details *details)
Create a new fax gateway object.
Definition res_fax.c:2981
static void set_channel_variables(struct ast_channel *chan, struct ast_fax_session_details *details)
Set fax related channel variables.
Definition res_fax.c:1548
int framehook
framehook used in gateway mode
Definition res_fax.c:555

References ao2_ref, ast_channel_lock, ast_channel_unlock, AST_FAX_OPTFLAG_TRUE, ast_framehook_attach(), AST_FRAMEHOOK_INTERFACE_VERSION, ast_string_field_set, ast_framehook_interface::data, ast_fax_session_details::debug, error(), fax_gateway_framehook(), fax_gateway_framehook_destroy(), fax_gateway_new(), fax_gateway::framehook, global_fax_debug, ast_fax_session_details::is_t38_negotiated, ast_fax_session_details::option, report_fax_status(), result, set_channel_variables(), and ast_framehook_interface::version.

Referenced by acf_faxopt_write(), and fixup_callback().

◆ fax_gateway_detect_t38()

static struct ast_frame * fax_gateway_detect_t38 ( struct fax_gateway *  gateway,
struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_channel *  active,
struct ast_frame *  f 
)
static

T38 Gateway Negotiate t38 parameters.

Parameters
gatewaygateway object
chanchannel running the gateway
peerchannel im bridged too
activechannel the frame originated on
fthe control frame to process
Precondition
chan is locked on entry
Returns
processed control frame or null frame

Definition at line 3211 of file res_fax.c.

3212{
3213 struct ast_control_t38_parameters *control_params = f->data.ptr;
3214 struct ast_channel *other = (active == chan) ? peer : chan;
3215 struct ast_fax_session_details *details;
3216 enum ast_t38_state state_other;
3217
3218 if (f->datalen != sizeof(struct ast_control_t38_parameters)) {
3219 /* invalaid AST_CONTROL_T38_PARAMETERS frame, we can't
3220 * do anything with it, pass it on */
3221 return f;
3222 }
3223
3224 /* ignore frames from ourselves */
3225 if ((gateway->t38_state == T38_STATE_NEGOTIATED && control_params->request_response == AST_T38_NEGOTIATED)
3226 || (gateway->t38_state == T38_STATE_REJECTED && control_params->request_response == AST_T38_REFUSED)
3227 || (gateway->t38_state == T38_STATE_NEGOTIATING && control_params->request_response == AST_T38_REQUEST_TERMINATE)) {
3228
3229 return f;
3230 }
3231
3232 if (!(details = find_details(chan))) {
3233 ast_log(LOG_ERROR, "no FAX session details found on chan %s for T.38 gateway session, odd\n", ast_channel_name(chan));
3234 ast_framehook_detach(chan, gateway->framehook);
3235 return f;
3236 }
3237
3238 if (control_params->request_response == AST_T38_REQUEST_NEGOTIATE) {
3239 ast_channel_unlock(chan);
3240 state_other = ast_channel_get_t38_state(other);
3241 ast_channel_lock(chan);
3242
3243 if (state_other == T38_STATE_UNKNOWN) {
3244 /* we detected a request to negotiate T.38 and the
3245 * other channel appears to support T.38, we'll pass
3246 * the request through and only step in if the other
3247 * channel rejects the request */
3248 ast_debug(1, "%s is attempting to negotiate T.38 with %s, we'll see what happens\n", ast_channel_name(active), ast_channel_name(other));
3249 t38_parameters_ast_to_fax(&details->their_t38_parameters, control_params);
3250 gateway->t38_state = T38_STATE_UNKNOWN;
3251 gateway->timeout_start = ast_tvnow();
3252 details->is_t38_negotiated = 0;
3254 ao2_ref(details, -1);
3255 return f;
3256 } else if (state_other == T38_STATE_UNAVAILABLE || state_other == T38_STATE_REJECTED) {
3257 /* the other channel does not support T.38, we need to
3258 * step in here */
3259 ast_debug(1, "%s is attempting to negotiate T.38 but %s does not support it\n", ast_channel_name(active), ast_channel_name(other));
3260 ast_debug(1, "starting T.38 gateway for T.38 channel %s and G.711 channel %s\n", ast_channel_name(active), ast_channel_name(other));
3261
3262 t38_parameters_ast_to_fax(&details->their_t38_parameters, control_params);
3263 t38_parameters_fax_to_ast(control_params, &details->our_t38_parameters);
3264
3265 if (fax_gateway_start(gateway, details, chan)) {
3266 ast_log(LOG_ERROR, "error starting T.38 gateway for T.38 channel %s and G.711 channel %s\n", ast_channel_name(active), ast_channel_name(other));
3267 gateway->t38_state = T38_STATE_REJECTED;
3268 details->is_t38_negotiated = 0;
3269 control_params->request_response = AST_T38_REFUSED;
3270
3271 ast_framehook_detach(chan, details->gateway_id);
3272 details->gateway_id = -1;
3273 } else {
3275 details->is_t38_negotiated = chan == active;
3276 control_params->request_response = AST_T38_NEGOTIATED;
3277 report_fax_status(chan, details, "T.38 Negotiated");
3278 }
3279
3280 fax_gateway_indicate_t38(chan, active, control_params);
3281
3282 ao2_ref(details, -1);
3283 return &ast_null_frame;
3284 } else if (gateway->t38_state == T38_STATE_NEGOTIATING) {
3285 /* we got a request to negotiate T.38 after we already
3286 * sent one to the other party based on v21 preamble
3287 * detection. We'll just pretend we passed this request
3288 * through in the first place. */
3289
3290 t38_parameters_ast_to_fax(&details->their_t38_parameters, control_params);
3291 gateway->t38_state = T38_STATE_UNKNOWN;
3292 gateway->timeout_start = ast_tvnow();
3293 details->is_t38_negotiated = 0;
3295
3296 ast_debug(1, "%s is attempting to negotiate T.38 after we already sent a negotiation request based on v21 preamble detection\n", ast_channel_name(active));
3297 ao2_ref(details, -1);
3298 return &ast_null_frame;
3299 } else if (gateway->t38_state == T38_STATE_NEGOTIATED) {
3300 /* we got a request to negotiate T.38 after we already
3301 * sent one to the other party based on v21 preamble
3302 * detection and received a response. We need to
3303 * respond to this and shut down the gateway. */
3304
3305 t38_parameters_fax_to_ast(control_params, &details->their_t38_parameters);
3306 ast_framehook_detach(chan, details->gateway_id);
3307 details->gateway_id = -1;
3308
3309 control_params->request_response = AST_T38_NEGOTIATED;
3310
3311 fax_gateway_indicate_t38(chan, active, control_params);
3312
3313 ast_string_field_set(details, result, "SUCCESS");
3314 ast_string_field_set(details, resultstr, "no gateway necessary");
3315 ast_string_field_set(details, error, "NATIVE_T38");
3316 details->is_t38_negotiated = 1;
3317 set_channel_variables(chan, details);
3318
3319 ast_debug(1, "%s is attempting to negotiate T.38 after we already negotiated T.38 with %s, disabling the gateway\n", ast_channel_name(active), ast_channel_name(other));
3320 ao2_ref(details, -1);
3321 return &ast_null_frame;
3322 } else {
3323 ast_log(LOG_WARNING, "%s is attempting to negotiate T.38 while %s is in an unsupported state\n", ast_channel_name(active), ast_channel_name(other));
3324 ao2_ref(details, -1);
3325 return f;
3326 }
3327 } else if (gateway->t38_state == T38_STATE_NEGOTIATING
3328 && control_params->request_response == AST_T38_REFUSED) {
3329
3330 ast_debug(1, "unable to negotiate T.38 on %s for fax gateway\n", ast_channel_name(active));
3331 details->is_t38_negotiated = 0;
3332
3333 /* our request to negotiate T.38 was refused, if the other
3334 * channel supports T.38, they might still reinvite and save
3335 * the day. Otherwise disable the gateway. */
3336 ast_channel_unlock(chan);
3337 state_other = ast_channel_get_t38_state(other);
3338 ast_channel_lock(chan);
3339 if (state_other == T38_STATE_UNKNOWN) {
3341 } else if (state_other != T38_STATE_NEGOTIATING) {
3342 ast_framehook_detach(chan, details->gateway_id);
3343 details->gateway_id = -1;
3344
3345 ast_string_field_set(details, result, "FAILED");
3346 ast_string_field_set(details, resultstr, "unable to negotiate T.38");
3347 ast_string_field_set(details, error, "T38_NEG_ERROR");
3348 set_channel_variables(chan, details);
3349 }
3350
3351 ao2_ref(details, -1);
3352 return &ast_null_frame;
3353 } else if (gateway->t38_state == T38_STATE_NEGOTIATING
3354 && control_params->request_response == AST_T38_NEGOTIATED) {
3355
3356 ast_debug(1, "starting T.38 gateway for T.38 channel %s and G.711 channel %s\n", ast_channel_name(active), ast_channel_name(other));
3357
3358 t38_parameters_ast_to_fax(&details->their_t38_parameters, control_params);
3359
3360 if (fax_gateway_start(gateway, details, chan)) {
3361 ast_log(LOG_ERROR, "error starting T.38 gateway for T.38 channel %s and G.711 channel %s\n", ast_channel_name(active), ast_channel_name(other));
3363 details->is_t38_negotiated = 0;
3365
3366 fax_gateway_indicate_t38(chan, active, control_params);
3367 } else {
3369 details->is_t38_negotiated = chan == active;
3370 report_fax_status(chan, details, "T.38 Negotiated");
3371 }
3372
3373 ao2_ref(details, -1);
3374 return &ast_null_frame;
3375 } else if (control_params->request_response == AST_T38_REFUSED) {
3376 /* the other channel refused the request to negotiate T.38,
3377 * we'll step in here and pretend the request was accepted */
3378
3379 ast_debug(1, "%s attempted to negotiate T.38 but %s refused the request\n", ast_channel_name(other), ast_channel_name(active));
3380 ast_debug(1, "starting T.38 gateway for T.38 channel %s and G.711 channel %s\n", ast_channel_name(other), ast_channel_name(active));
3381
3382 t38_parameters_fax_to_ast(control_params, &details->our_t38_parameters);
3383
3384 if (fax_gateway_start(gateway, details, chan)) {
3385 ast_log(LOG_ERROR, "error starting T.38 gateway for T.38 channel %s and G.711 channel %s\n", ast_channel_name(other), ast_channel_name(active));
3386 gateway->t38_state = T38_STATE_REJECTED;
3387 details->is_t38_negotiated = 0;
3388 control_params->request_response = AST_T38_REFUSED;
3389
3390 ast_framehook_detach(chan, details->gateway_id);
3391 details->gateway_id = -1;
3392 } else {
3394 details->is_t38_negotiated = chan == other;
3395 control_params->request_response = AST_T38_NEGOTIATED;
3396 }
3397
3398 ao2_ref(details, -1);
3399 return f;
3400 } else if (control_params->request_response == AST_T38_REQUEST_TERMINATE) {
3401 /* the channel wishes to end our short relationship, we shall
3402 * oblige */
3403
3404 ast_debug(1, "T.38 channel %s is requesting a shutdown of T.38, disabling the gateway\n", ast_channel_name(active));
3405
3406 ast_framehook_detach(chan, details->gateway_id);
3407 details->gateway_id = -1;
3408
3409 gateway->t38_state = T38_STATE_REJECTED;
3410 details->is_t38_negotiated = 0;
3411 control_params->request_response = AST_T38_TERMINATED;
3412
3413 fax_gateway_indicate_t38(chan, active, control_params);
3414
3415 ao2_ref(details, -1);
3416 return &ast_null_frame;
3417 } else if (control_params->request_response == AST_T38_NEGOTIATED) {
3418 ast_debug(1, "T.38 successfully negotiated between %s and %s, no gateway necessary\n", ast_channel_name(active), ast_channel_name(other));
3419
3420 ast_framehook_detach(chan, details->gateway_id);
3421 details->gateway_id = -1;
3422
3423 ast_string_field_set(details, result, "SUCCESS");
3424 ast_string_field_set(details, resultstr, "no gateway necessary");
3425 ast_string_field_set(details, error, "NATIVE_T38");
3426 details->is_t38_negotiated = 1;
3427 set_channel_variables(chan, details);
3428
3429 ao2_ref(details, -1);
3430 return f;
3431 } else if (control_params->request_response == AST_T38_TERMINATED) {
3432 ast_debug(1, "T.38 disabled on channel %s\n", ast_channel_name(active));
3433
3434 ast_framehook_detach(chan, details->gateway_id);
3435 details->gateway_id = -1;
3436
3437 ao2_ref(details, -1);
3438 return &ast_null_frame;
3439 }
3440
3441 ao2_ref(details, -1);
3442 return f;
3443}
static enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan)
Retrieves the current T38 state of a channel.
Definition channel.h:2911
ast_t38_state
Possible T38 states on channels.
Definition channel.h:898
@ T38_STATE_UNAVAILABLE
Definition channel.h:899
@ T38_STATE_UNKNOWN
Definition channel.h:900
@ T38_STATE_REJECTED
Definition channel.h:902
@ T38_STATE_NEGOTIATED
Definition channel.h:903
@ T38_STATE_NEGOTIATING
Definition channel.h:901
static int fax_gateway_start(struct fax_gateway *gateway, struct ast_fax_session_details *details, struct ast_channel *chan)
Create a fax session and start T.30<->T.38 gateway mode.
Definition res_fax.c:3018
static void fax_gateway_indicate_t38(struct ast_channel *chan, struct ast_channel *active, struct ast_control_t38_parameters *control_params)
Definition res_fax.c:3187
static void t38_parameters_fax_to_ast(struct ast_control_t38_parameters *dst, const struct ast_fax_t38_parameters *src)
Definition res_fax.c:852
static void t38_parameters_ast_to_fax(struct ast_fax_t38_parameters *dst, const struct ast_control_t38_parameters *src)
Definition res_fax.c:841
#define FAX_GATEWAY_TIMEOUT
Definition res_fax.c:594
struct ast_fax_t38_parameters their_t38_parameters
Definition res_fax.h:177
struct ast_fax_t38_parameters our_t38_parameters
Definition res_fax.h:175
struct timeval timeout_start
the start of our timeout counter
Definition res_fax.c:553
enum ast_t38_state t38_state
a flag to track the state of our negotiation
Definition res_fax.c:561

References ao2_ref, ast_channel_get_t38_state(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_debug, ast_framehook_detach(), ast_log, ast_null_frame, ast_string_field_set, AST_T38_NEGOTIATED, AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, AST_T38_REQUEST_TERMINATE, AST_T38_TERMINATED, ast_tvnow(), ast_frame::data, ast_frame::datalen, ast_fax_session_details::error, fax_gateway_indicate_t38(), fax_gateway_start(), FAX_GATEWAY_TIMEOUT, find_details(), fax_gateway::framehook, ast_fax_session_details::gateway_id, ast_fax_session_details::gateway_timeout, ast_fax_session_details::is_t38_negotiated, LOG_ERROR, LOG_WARNING, ast_fax_session_details::our_t38_parameters, ast_frame::ptr, report_fax_status(), ast_control_t38_parameters::request_response, result, ast_fax_session_details::resultstr, set_channel_variables(), t38_parameters_ast_to_fax(), t38_parameters_fax_to_ast(), fax_gateway::t38_state, T38_STATE_NEGOTIATED, T38_STATE_NEGOTIATING, T38_STATE_REJECTED, T38_STATE_UNAVAILABLE, T38_STATE_UNKNOWN, ast_fax_session_details::their_t38_parameters, and fax_gateway::timeout_start.

Referenced by fax_gateway_framehook().

◆ fax_gateway_detect_v21()

static struct ast_frame * fax_gateway_detect_v21 ( struct fax_gateway *  gateway,
struct ast_channel *  chan,
struct ast_channel *  peer,
struct ast_channel *  active,
struct ast_frame *  f 
)
static
Precondition
chan is locked on entry

Definition at line 3113 of file res_fax.c.

3114{
3115 struct ast_channel *other = (active == chan) ? peer : chan;
3116 struct ast_fax_session *active_v21_session = (active == chan) ? gateway->chan_v21_session : gateway->peer_v21_session;
3117
3118 if (!active_v21_session || gateway->detected_v21) {
3119 return f;
3120 }
3121
3122 if (active_v21_session->tech->write(active_v21_session, f) == 0 &&
3123 active_v21_session->details->option.v21_detected) {
3124 gateway->detected_v21 = 1;
3125 }
3126
3127 if (gateway->detected_v21) {
3128 enum ast_t38_state state_other;
3129 enum ast_t38_state state_active;
3130 struct ast_frame *fp;
3131 struct ast_fax_session_details *details;
3132 int negotiate_both = 0;
3133
3134 /*
3135 * The default behavior is to wait for the active endpoint to initiate negotiation.
3136 * Find out if this has been overridden. If so, instead of waiting have Asterisk
3137 * initiate the negotiation requests out to both endpoints.
3138 */
3139 details = find_or_create_details(active);
3140 if (details) {
3141 negotiate_both = details->negotiate_both;
3142 ao2_ref(details, -1);
3143 } else {
3144 ast_log(LOG_WARNING, "Detect v21 - no session details for channel '%s'\n",
3145 ast_channel_name(chan));
3146 }
3147
3148 destroy_v21_sessions(gateway);
3149
3150 ast_channel_unlock(chan);
3151 state_active = ast_channel_get_t38_state(active);
3152 state_other = ast_channel_get_t38_state(other);
3153 ast_channel_lock(chan);
3154
3155 ast_debug(1, "detected v21 preamble from %s\n", ast_channel_name(active));
3156
3157 if (state_active == T38_STATE_UNKNOWN || state_other == T38_STATE_UNKNOWN) {
3158 if (!(fp = fax_gateway_request_t38(gateway, chan))) {
3159 return f;
3160 }
3161 /* May be called endpoint is improperly configured to rely on the calling endpoint
3162 * to initiate T.38 re-INVITEs, send T.38 negotiation request to called endpoint */
3163 if (negotiate_both && state_active == T38_STATE_UNKNOWN) {
3164 ast_debug(1, "sending T.38 negotiation request to %s\n", ast_channel_name(active));
3165 if (active == chan) {
3166 ast_channel_unlock(chan);
3167 }
3168 ast_write(active, fp);
3169 if (active == chan) {
3170 ast_channel_lock(chan);
3171 }
3172 }
3173 if (state_other == T38_STATE_UNKNOWN) {
3174 ast_debug(1, "sending T.38 negotiation request to %s\n", ast_channel_name(other));
3175 return fp;
3176 }
3177 ast_frfree(fp);
3178 } else {
3179 ast_debug(1, "neither %s nor %s support T.38 for T.38 gateway session\n", ast_channel_name(active), ast_channel_name(other));
3180 }
3181 }
3182
3183 return f;
3184}
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition channel.c:5167
static struct ast_frame * fax_gateway_request_t38(struct fax_gateway *gateway, struct ast_channel *chan)
Definition res_fax.c:3073
struct ast_channel * chan
Definition res_fax.h:224
int(*const write)(struct ast_fax_session *, const struct ast_frame *)
Definition res_fax.h:257
int detected_v21
1 if a v21 preamble has been detected
Definition res_fax.c:559

References ao2_ref, ast_channel_get_t38_state(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_debug, ast_frfree, ast_log, ast_write(), ast_fax_session::chan, fax_gateway::chan_v21_session, destroy_v21_sessions(), ast_fax_session::details, fax_gateway::detected_v21, fax_gateway_request_t38(), find_or_create_details(), LOG_WARNING, ast_fax_session_details::negotiate_both, ast_fax_session_details::option, fax_gateway::peer_v21_session, T38_STATE_UNKNOWN, ast_fax_session::tech, ast_fax_session_details::v21_detected, and ast_fax_tech::write.

Referenced by fax_gateway_framehook().

◆ fax_gateway_framehook()

static struct ast_frame * fax_gateway_framehook ( struct ast_channel *  chan,
struct ast_frame *  f,
enum ast_framehook_event  event,
void *  data 
)
static

T.30<->T.38 gateway framehook.

Intercept packets on bridged channels and determine if a T.38 gateway is required. If a gateway is required, start a gateway and handle T.38 negotiation if necessary.

Parameters
chanchannel running the gateway
fframe to handle may be NULL
eventframehook event
dataframehook data (struct fax_gateway *)
Precondition
chan is locked on entry
Note
Read frames replaced by the gateway are released here. Write frames remain owned by the caller.
Returns
processed frame or NULL when f is NULL or a null frame

Definition at line 3488 of file res_fax.c.

3489{
3490 struct fax_gateway *gateway = data;
3491 struct ast_channel *active;
3492 RAII_VAR(struct ast_fax_session_details *, details, NULL, ao2_cleanup);
3493 RAII_VAR(struct ast_channel *, peer, NULL, ao2_cleanup);
3494 RAII_VAR(struct ast_channel *, chan_ref, chan, ao2_cleanup);
3495
3496 /* Ref bump channel for when we have to unlock it */
3497 ao2_ref(chan_ref, 1);
3498
3499 if (gateway->s) {
3500 details = gateway->s->details;
3501 ao2_ref(details, 1);
3502 } else {
3503 if (!(details = find_details(chan))) {
3504 ast_log(LOG_ERROR, "no FAX session details found on chan %s for T.38 gateway session, odd\n", ast_channel_name(chan));
3505 ast_framehook_detach(chan, gateway->framehook);
3506 return f;
3507 }
3508 }
3509
3510 /* restore audio formats when we are detached */
3512 set_channel_variables(chan, details);
3513
3514 if (gateway->bridged) {
3515 ast_set_read_format(chan, gateway->chan_read_format);
3517
3518 ast_channel_unlock(chan);
3519 peer = ast_channel_bridge_peer(chan);
3520 if (peer) {
3521 ast_set_read_format(peer, gateway->peer_read_format);
3523 ast_channel_make_compatible(chan, peer);
3524 }
3525 ast_channel_lock(chan);
3526 }
3527 return NULL;
3528 }
3529
3530 if (!f || (event == AST_FRAMEHOOK_EVENT_ATTACHED)) {
3531 return NULL;
3532 };
3533
3534 /* this frame was generated by the fax gateway, pass it on */
3536 return f;
3537 }
3538
3539 /* If we aren't bridged or we don't have a peer, don't do anything */
3540 ast_channel_unlock(chan);
3541 peer = ast_channel_bridge_peer(chan);
3542 ast_channel_lock(chan);
3543 if (!peer) {
3544 return f;
3545 }
3546
3547 if (!gateway->bridged) {
3548 enum ast_t38_state state_chan;
3549 enum ast_t38_state state_peer;
3550 int chan_is_hungup;
3551 int peer_is_hungup;
3552
3553 chan_is_hungup = ast_check_hangup(chan);
3554 peer_is_hungup = ast_check_hangup(peer);
3555 /* Don't start a gateway if either channel is hung up */
3556 if (chan_is_hungup || peer_is_hungup) {
3557 return f;
3558 }
3559
3560 ast_channel_unlock(chan);
3561 state_chan = ast_channel_get_t38_state(chan);
3562 state_peer = ast_channel_get_t38_state(peer);
3563 ast_channel_lock(chan);
3564
3565 /* don't start a gateway if neither channel can handle T.38 */
3566 if (state_chan == T38_STATE_UNAVAILABLE && state_peer == T38_STATE_UNAVAILABLE) {
3567 ast_debug(1, "not starting gateway for %s and %s; neither channel supports T.38\n", ast_channel_name(chan), ast_channel_name(peer));
3568 ast_framehook_detach(chan, gateway->framehook);
3569 details->gateway_id = -1;
3570
3571 ast_string_field_set(details, result, "FAILED");
3572 ast_string_field_set(details, resultstr, "neither channel supports T.38");
3573 ast_string_field_set(details, error, "T38_NEG_ERROR");
3574 details->is_t38_negotiated = 0;
3575 set_channel_variables(chan, details);
3576 return f;
3577 }
3578
3579 if (details->gateway_timeout) {
3580 gateway->timeout_start = ast_tvnow();
3581 }
3582
3583 ast_channel_unlock(chan);
3584 ast_channel_lock_both(chan, peer);
3585
3586 /* we are bridged, change r/w formats to SLIN for v21 preamble
3587 * detection and T.30 */
3590
3593
3596
3599
3600 ast_channel_unlock(peer);
3601
3602 gateway->bridged = 1;
3603 if (!(gateway->peer_v21_session = fax_v21_session_new(peer))) {
3604 ast_log(LOG_ERROR, "Can't create V21 session on chan %s for T.38 gateway session\n", ast_channel_name(peer));
3605 ast_framehook_detach(chan, gateway->framehook);
3606 return f;
3607 }
3608 }
3609
3610 if (gateway->bridged && !ast_tvzero(gateway->timeout_start)) {
3611 if (ast_tvdiff_ms(ast_tvnow(), gateway->timeout_start) > details->gateway_timeout) {
3612 ast_debug(1, "no fax activity between %s and %s after %d ms, disabling gateway\n", ast_channel_name(chan), ast_channel_name(peer), details->gateway_timeout);
3613 ast_framehook_detach(chan, gateway->framehook);
3614 details->gateway_id = -1;
3615
3616 ast_string_field_set(details, result, "FAILED");
3617 ast_string_field_build(details, resultstr, "no fax activity after %d ms", details->gateway_timeout);
3618 ast_string_field_set(details, error, "TIMEOUT");
3619 details->is_t38_negotiated = 0;
3620 set_channel_variables(chan, details);
3621 return f;
3622 }
3623 }
3624
3625 /* only handle VOICE, MODEM, and CONTROL frames*/
3626 switch (f->frametype) {
3627 case AST_FRAME_VOICE:
3631 return f;
3632 }
3633 break;
3634 case AST_FRAME_MODEM:
3635 if (f->subclass.integer == AST_MODEM_T38) {
3636 break;
3637 }
3638 return f;
3639 case AST_FRAME_CONTROL:
3641 break;
3642 }
3643 return f;
3644 default:
3645 return f;
3646 }
3647
3648 /* detect the active channel */
3649 switch (event) {
3651 active = peer;
3652 break;
3654 active = chan;
3655 break;
3656 default:
3657 ast_log(LOG_WARNING, "unhandled framehook event %u\n", event);
3658 return f;
3659 }
3660
3661 /* handle control frames */
3663 struct ast_frame *result = fax_gateway_detect_t38(gateway, chan, peer, active, f);
3664
3665 if (event == AST_FRAMEHOOK_EVENT_READ && result != f) {
3666 /* On READ hooks, replacing/dropping the frame leaves us owning it, so we must free it here. */
3667 ast_frfree(f);
3668 }
3669 return result;
3670 }
3671
3672 if (!gateway->detected_v21 && gateway->t38_state == T38_STATE_UNAVAILABLE && f->frametype == AST_FRAME_VOICE) {
3673 struct ast_frame *result;
3674
3675 /* not in gateway mode and have not detected v21 yet, listen
3676 * for v21 */
3677 result = fax_gateway_detect_v21(gateway, chan, peer, active, f);
3678 if (event == AST_FRAMEHOOK_EVENT_READ && result != f) {
3679 ast_frfree(f);
3680 }
3681 return result;
3682 }
3683
3684 /* in gateway mode, gateway some packets */
3685 if (gateway->t38_state == T38_STATE_NEGOTIATED) {
3686 struct ast_trans_pvt *readtrans;
3687
3688 if (!gateway->s || !gateway->s->tech_pvt) {
3689 ast_log(LOG_ERROR, "no FAX session on chan %s for T.38 gateway session, odd", ast_channel_name(chan));
3690 return f;
3691 }
3692
3693 /* framehooks are called in __ast_read() before frame format
3694 * translation is done, so we need to translate here */
3696 && (readtrans = ast_channel_readtrans(active))) {
3697 if ((f = ast_translate(readtrans, f, event == AST_FRAMEHOOK_EVENT_WRITE ? 0 : 1)) == NULL) {
3698 f = &ast_null_frame;
3699 return f;
3700 }
3701 /* XXX we ignore the return value here, perhaps we should
3702 * disable the gateway if a write fails. I am not sure how a
3703 * write would fail, or even if a failure would be fatal so for
3704 * now we'll just ignore the return value. */
3705 gateway->s->tech->write(gateway->s, f);
3706 ast_frfree(f);
3707 } else {
3708 gateway->s->tech->write(gateway->s, f);
3710 ast_frfree(f);
3711 }
3712 }
3713
3714 f = &ast_null_frame;
3715 return f;
3716 }
3717
3718 /* force silence on the line if T.38 negotiation might be taking place */
3719 if (gateway->t38_state != T38_STATE_UNAVAILABLE && gateway->t38_state != T38_STATE_REJECTED) {
3720 if (f->frametype == AST_FRAME_VOICE &&
3722 struct ast_frame *silence;
3723 short silence_buf[f->samples];
3724 struct ast_frame silence_frame = {
3726 .subclass.format = ast_format_slin,
3727 .data.ptr = silence_buf,
3728 .samples = f->samples,
3729 .datalen = sizeof(silence_buf),
3730 };
3731 memset(silence_buf, 0, sizeof(silence_buf));
3732 silence = ast_frisolate(&silence_frame);
3734 ast_frfree(f);
3735 }
3736 return silence;
3737 } else {
3739 ast_frfree(f);
3740 }
3741 return &ast_null_frame;
3742 }
3743 }
3744
3745 return f;
3746}
struct ast_trans_pvt * ast_channel_readtrans(const struct ast_channel *chan)
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition channel.h:2990
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition channel.c:446
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition channel.c:5826
@ AST_FRAMEHOOK_EVENT_WRITE
Definition framehook.h:153
#define ast_frisolate(fr)
Makes a frame independent of any static storage.
#define AST_MODEM_T38
static struct ast_fax_session * fax_v21_session_new(struct ast_channel *chan)
Definition res_fax.c:2962
static struct ast_frame * fax_gateway_detect_v21(struct fax_gateway *gateway, struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *active, struct ast_frame *f)
Definition res_fax.c:3113
static struct ast_frame * fax_gateway_detect_t38(struct fax_gateway *gateway, struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *active, struct ast_frame *f)
T38 Gateway Negotiate t38 parameters.
Definition res_fax.c:3211
#define AST_FAX_FRFLAG_GATEWAY
Definition res_fax.h:232
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
Definition translate.h:213
struct ast_frame f
Definition translate.h:215
int bridged
bridged
Definition res_fax.c:557
struct ast_frame * ast_translate(struct ast_trans_pvt *tr, struct ast_frame *f, int consume)
translates one or more frames Apply an input frame into the translator and receive zero or one output...
Definition translate.c:623
#define ast_test_flag(p, flag)
Definition utils.h:64

References ao2_cleanup, ao2_ref, ao2_replace, ast_channel_bridge_peer(), ast_channel_get_t38_state(), ast_channel_lock, ast_channel_lock_both, ast_channel_make_compatible(), ast_channel_name(), ast_channel_readformat(), ast_channel_readtrans(), ast_channel_unlock, ast_channel_writeformat(), ast_check_hangup(), AST_CONTROL_T38_PARAMETERS, ast_debug, AST_FAX_FRFLAG_GATEWAY, ast_format_alaw, ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_slin, ast_format_ulaw, AST_FRAME_CONTROL, AST_FRAME_MODEM, AST_FRAME_VOICE, ast_framehook_detach(), AST_FRAMEHOOK_EVENT_ATTACHED, AST_FRAMEHOOK_EVENT_DETACHED, AST_FRAMEHOOK_EVENT_READ, AST_FRAMEHOOK_EVENT_WRITE, ast_frfree, ast_frisolate, ast_log, AST_MODEM_T38, ast_null_frame, ast_set_read_format(), ast_set_write_format(), ast_string_field_build, ast_string_field_set, ast_test_flag, ast_translate(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), fax_gateway::bridged, fax_gateway::chan_read_format, fax_gateway::chan_write_format, ast_fax_session::details, fax_gateway::detected_v21, error(), ast_trans_pvt::f, fax_gateway_detect_t38(), fax_gateway_detect_v21(), fax_v21_session_new(), find_details(), ast_frame_subclass::format, fax_gateway::framehook, ast_frame::frametype, ast_frame_subclass::integer, LOG_ERROR, LOG_WARNING, NULL, fax_gateway::peer_read_format, fax_gateway::peer_v21_session, fax_gateway::peer_write_format, RAII_VAR, result, fax_gateway::s, ast_frame::samples, set_channel_variables(), ast_frame::subclass, fax_gateway::t38_state, T38_STATE_NEGOTIATED, T38_STATE_REJECTED, T38_STATE_UNAVAILABLE, ast_fax_session::tech, ast_fax_session::tech_pvt, fax_gateway::timeout_start, and ast_fax_tech::write.

Referenced by fax_gateway_attach().

◆ fax_gateway_framehook_destroy()

static void fax_gateway_framehook_destroy ( void *  data)
static

Destroy the gateway data structure when the framehook is detached.

Parameters
dataframehook data (gateway data)

Definition at line 3447 of file res_fax.c.

3448{
3449 struct fax_gateway *gateway = data;
3450
3451 if (gateway->s) {
3452 switch (gateway->s->state) {
3454 case AST_FAX_STATE_OPEN:
3457 if (gateway->s->tech->cancel_session) {
3458 gateway->s->tech->cancel_session(gateway->s);
3459 }
3460 /* fall through */
3461 default:
3462 break;
3463 }
3464 }
3465
3466 ao2_ref(gateway, -1);
3467}
int(*const cancel_session)(struct ast_fax_session *)
Definition res_fax.h:261

References ao2_ref, AST_FAX_STATE_ACTIVE, AST_FAX_STATE_COMPLETE, AST_FAX_STATE_INITIALIZED, AST_FAX_STATE_OPEN, ast_fax_tech::cancel_session, fax_gateway::s, ast_fax_session::state, and ast_fax_session::tech.

Referenced by fax_gateway_attach().

◆ fax_gateway_indicate_t38()

static void fax_gateway_indicate_t38 ( struct ast_channel *  chan,
struct ast_channel *  active,
struct ast_control_t38_parameters *  control_params 
)
static
Precondition
chan is locked on entry

Definition at line 3187 of file res_fax.c.

3188{
3189 if (active == chan) {
3190 ast_channel_unlock(chan);
3191 ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, control_params, sizeof(*control_params));
3192 ast_channel_lock(chan);
3193 } else {
3194 ast_queue_control_data(chan, AST_CONTROL_T38_PARAMETERS, control_params, sizeof(*control_params));
3195 }
3196}
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:1296

References ast_channel_lock, ast_channel_unlock, AST_CONTROL_T38_PARAMETERS, ast_indicate_data(), and ast_queue_control_data().

Referenced by fax_gateway_detect_t38().

◆ fax_gateway_new()

static struct fax_gateway * fax_gateway_new ( struct ast_channel *  chan,
struct ast_fax_session_details *  details 
)
static

Create a new fax gateway object.

Parameters
chanthe channel the gateway object will be attached to
detailsthe fax session details
Returns
NULL or a fax gateway object

Definition at line 2981 of file res_fax.c.

2982{
2983 struct fax_gateway *gateway = ao2_alloc(sizeof(*gateway), destroy_gateway);
2984 if (!gateway) {
2985 return NULL;
2986 }
2987
2988 if (!(gateway->chan_v21_session = fax_v21_session_new(chan))) {
2989 ast_log(LOG_ERROR, "Can't create V21 session on chan %s for T.38 gateway session\n", ast_channel_name(chan));
2990 ao2_ref(gateway, -1);
2991 return NULL;
2992 }
2993
2994 gateway->framehook = -1;
2995
2996 details->caps = AST_FAX_TECH_GATEWAY;
2997 if (details->gateway_timeout && !(gateway->s = fax_session_reserve(details, &gateway->token))) {
2998 details->caps &= ~AST_FAX_TECH_GATEWAY;
2999 ast_log(LOG_ERROR, "Can't reserve a FAX session, gateway attempt failed.\n");
3000 ao2_ref(gateway, -1);
3001 return NULL;
3002 }
3003
3004 return gateway;
3005}
static struct ast_fax_session * fax_session_reserve(struct ast_fax_session_details *details, struct ast_fax_tech_token **token)
Reserve a fax session.
Definition res_fax.c:1247
static void destroy_gateway(void *data)
destroy a FAX gateway session structure
Definition res_fax.c:2940

References ao2_alloc, ao2_ref, ast_channel_name(), AST_FAX_TECH_GATEWAY, ast_log, ast_fax_session_details::caps, fax_gateway::chan_v21_session, destroy_gateway(), fax_session_reserve(), fax_v21_session_new(), fax_gateway::framehook, ast_fax_session_details::gateway_timeout, LOG_ERROR, NULL, fax_gateway::s, and fax_gateway::token.

Referenced by fax_gateway_attach().

◆ fax_gateway_request_t38()

static struct ast_frame * fax_gateway_request_t38 ( struct fax_gateway *  gateway,
struct ast_channel *  chan 
)
static
Precondition
chan is locked on entry

Definition at line 3073 of file res_fax.c.

3074{
3075 struct ast_frame *fp;
3076 struct ast_control_t38_parameters t38_parameters = {
3078 };
3079 struct ast_frame control_frame = {
3080 .src = "res_fax",
3081 .frametype = AST_FRAME_CONTROL,
3082 .datalen = sizeof(t38_parameters),
3084 .data.ptr = &t38_parameters,
3085 };
3086
3087 struct ast_fax_session_details *details = find_details(chan);
3088
3089 if (!details) {
3090 ast_log(LOG_ERROR, "no FAX session details found on chan %s for T.38 gateway session, odd\n", ast_channel_name(chan));
3091 ast_framehook_detach(chan, gateway->framehook);
3092 return NULL;
3093 }
3094
3095 t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
3096 ao2_ref(details, -1);
3097
3098 if (!(fp = ast_frisolate(&control_frame))) {
3099 ast_log(LOG_ERROR, "error generating T.38 request control frame on chan %s for T.38 gateway session\n", ast_channel_name(chan));
3100 return NULL;
3101 }
3102
3104 gateway->timeout_start = ast_tvnow();
3105 details->is_t38_negotiated = 0;
3107
3108 ast_debug(1, "requesting T.38 for gateway session for %s\n", ast_channel_name(chan));
3109 return fp;
3110}

References ao2_ref, ast_channel_name(), AST_CONTROL_T38_PARAMETERS, ast_debug, AST_FRAME_CONTROL, ast_framehook_detach(), ast_frisolate, ast_log, AST_T38_REQUEST_NEGOTIATE, ast_tvnow(), FAX_GATEWAY_TIMEOUT, find_details(), fax_gateway::framehook, ast_fax_session_details::gateway_timeout, ast_frame_subclass::integer, ast_fax_session_details::is_t38_negotiated, LOG_ERROR, NULL, ast_fax_session_details::our_t38_parameters, ast_control_t38_parameters::request_response, ast_frame::src, ast_frame::subclass, t38_parameters_fax_to_ast(), fax_gateway::t38_state, T38_STATE_NEGOTIATING, and fax_gateway::timeout_start.

Referenced by fax_gateway_detect_v21().

◆ fax_gateway_start()

static int fax_gateway_start ( struct fax_gateway *  gateway,
struct ast_fax_session_details *  details,
struct ast_channel *  chan 
)
static

Create a fax session and start T.30<->T.38 gateway mode.

Parameters
gatewaya fax gateway object
detailsfax session details
chanactive channel
Precondition
chan is locked on entry
Returns
0 on error 1 on success

Definition at line 3018 of file res_fax.c.

3019{
3020 struct ast_fax_session *s;
3021 int start_res;
3022
3023 /* if the fax gateway is already started then do nothing */
3024 if (gateway->s &&
3025 gateway->s->state != AST_FAX_STATE_RESERVED && gateway->s->state != AST_FAX_STATE_INACTIVE) {
3026 return 0;
3027 }
3028
3029 /* if we start gateway we don't need v21 detection sessions any more */
3030 destroy_v21_sessions(gateway);
3031
3032 /* create the FAX session */
3033 if (!(s = fax_session_new(details, chan, gateway->s, gateway->token))) {
3034 gateway->token = NULL;
3036 ast_string_field_set(details, resultstr, "error starting gateway session");
3037 ast_string_field_set(details, error, "INIT_ERROR");
3040 report_fax_status(chan, details, "No Available Resource");
3041 ast_log(LOG_ERROR, "Can't create a FAX session, gateway attempt failed.\n");
3042 return -1;
3043 }
3044 /* release the reference for the reserved session and replace it with
3045 * the real session */
3046 if (gateway->s) {
3047 ao2_ref(gateway->s, -1);
3048 }
3049 gateway->s = s;
3050 gateway->token = NULL;
3051
3053 start_res = gateway->s->tech->start_session(gateway->s);
3055 if (start_res < 0) {
3057 ast_string_field_set(details, resultstr, "error starting gateway session");
3058 ast_string_field_set(details, error, "INIT_ERROR");
3061 return -1;
3062 }
3063
3064 gateway->timeout_start.tv_sec = 0;
3065 gateway->timeout_start.tv_usec = 0;
3066
3067 report_fax_status(chan, details, "FAX Transmission In Progress");
3068
3069 return 0;
3070}
static struct ast_fax_session * fax_session_new(struct ast_fax_session_details *details, struct ast_channel *chan, struct ast_fax_session *reserved, struct ast_fax_tech_token *token)
create a FAX session
Definition res_fax.c:1316
int(*const start_session)(struct ast_fax_session *)
Definition res_fax.h:259

References ao2_ref, ast_channel_lock, ast_channel_unlock, AST_FAX_STATE_INACTIVE, AST_FAX_STATE_RESERVED, ast_log, ast_string_field_set, ast_fax_session::chan, destroy_v21_sessions(), ast_fax_session::details, error(), fax_session_new(), ast_fax_session_details::is_t38_negotiated, LOG_ERROR, NULL, report_fax_status(), result, fax_gateway::s, set_channel_variables(), ast_fax_tech::start_session, ast_fax_session::state, ast_fax_session::tech, fax_gateway::timeout_start, and fax_gateway::token.

Referenced by fax_gateway_detect_t38().

◆ fax_rate_str_to_int()

static unsigned int fax_rate_str_to_int ( const char *  ratestr)
static

convert a rate string to a rate

Definition at line 1147 of file res_fax.c.

1148{
1149 int rate;
1150
1151 if (sscanf(ratestr, "%d", &rate) != 1) {
1152 ast_log(LOG_ERROR, "failed to sscanf '%s' to rate\n", ratestr);
1153 return 0;
1154 }
1155 switch (rate) {
1156 case 2400:
1157 case 4800:
1158 case 7200:
1159 case 9600:
1160 case 12000:
1161 case 14400:
1162 case 28800:
1163 case 33600:
1164 return rate;
1165 default:
1166 ast_log(LOG_WARNING, "ignoring invalid rate '%s'. Valid options are {2400 | 4800 | 7200 | 9600 | 12000 | 14400 | 28800 | 33600}\n", ratestr);
1167 return 0;
1168 }
1169}

References ast_log, LOG_ERROR, and LOG_WARNING.

Referenced by acf_faxopt_write(), and set_config().

◆ fax_session_new()

static struct ast_fax_session * fax_session_new ( struct ast_fax_session_details *  details,
struct ast_channel *  chan,
struct ast_fax_session *  reserved,
struct ast_fax_tech_token *  token 
)
static

create a FAX session

Parameters
detailsdetails for the session
chanthe channel the session will run on
reserveda reserved session to base this session on (can be NULL)
tokenthe token for a reserved session (can be NULL)

Create a new fax session based on the given details structure.

Note
The given token is always consumed (by tech->new_session() or by fax_session_release() in the event of a failure). The given reference to a reserved session is never consumed and must be dereferenced separately from the reference returned by this function.
Returns
NULL or a reference to a new fax session

Definition at line 1316 of file res_fax.c.

1317{
1318 struct ast_fax_session *s = NULL;
1319 struct fax_module *faxmod;
1320
1321 if (reserved) {
1322 s = reserved;
1323 ao2_ref(reserved, +1);
1324 ao2_unlink(faxregistry.container, reserved);
1325
1326 /* NOTE: we don't consume the reference to the reserved
1327 * session. The session returned from fax_session_new() is a
1328 * new reference and must be derefed in addition to the
1329 * reserved session.
1330 */
1331
1332 if (s->state == AST_FAX_STATE_RESERVED) {
1333 ast_atomic_fetchadd_int(&faxregistry.reserved_sessions, -1);
1335 }
1336 }
1337
1338 if (!s && !(s = ao2_alloc(sizeof(*s), destroy_session))) {
1339 return NULL;
1340 }
1341
1342 ast_atomic_fetchadd_int(&faxregistry.active_sessions, 1);
1344
1345 if (details->option.debug && (details->caps & AST_FAX_TECH_AUDIO)) {
1346 if (!(s->debug_info = ast_calloc(1, sizeof(*(s->debug_info))))) {
1347 fax_session_release(s, token);
1348 ao2_ref(s, -1);
1349 return NULL;
1350 }
1351 if (!(s->debug_info->dsp = ast_dsp_new())) {
1352 ast_free(s->debug_info);
1353 s->debug_info = NULL;
1354 fax_session_release(s, token);
1355 ao2_ref(s, -1);
1356 return NULL;
1357 }
1359 }
1360
1361 if (!(s->channame = ast_strdup(ast_channel_name(chan)))) {
1362 fax_session_release(s, token);
1363 ao2_ref(s, -1);
1364 return NULL;
1365 }
1366
1367 if (!(s->chan_uniqueid = ast_strdup(ast_channel_uniqueid(chan)))) {
1368 fax_session_release(s, token);
1369 ao2_ref(s, -1);
1370 return NULL;
1371 }
1372
1373 s->chan = chan;
1374 if (!s->details) {
1375 s->details = details;
1376 ao2_ref(s->details, 1);
1377 }
1378
1379 details->id = s->id = ast_atomic_fetchadd_int(&faxregistry.nextsessionname, 1);
1380
1381 if (!token) {
1382 /* locate a FAX technology module that can handle said requirements */
1385 if ((faxmod->tech->caps & details->caps) != details->caps) {
1386 continue;
1387 }
1388 if (!ast_module_running_ref(faxmod->tech->module)) {
1389 continue;
1390 }
1391 ast_debug(4, "Requesting a new FAX session from '%s'.\n", faxmod->tech->description);
1392 if (reserved) {
1393 /* Balance module ref from reserved session */
1394 ast_module_unref(reserved->tech->module);
1395 }
1396 s->tech = faxmod->tech;
1397 break;
1398 }
1400
1401 if (!faxmod) {
1402 char caps[128] = "";
1403 ast_log(LOG_ERROR, "Could not locate a FAX technology module with capabilities (%s)\n", ast_fax_caps_to_str(details->caps, caps, sizeof(caps)));
1404 ao2_ref(s, -1);
1405 return NULL;
1406 }
1407 }
1408
1409 if (!(s->tech_pvt = s->tech->new_session(s, token))) {
1410 ast_log(LOG_ERROR, "FAX session failed to initialize.\n");
1411 ao2_ref(s, -1);
1412 return NULL;
1413 }
1414 /* link the session to the session container */
1415 if (!(ao2_link(faxregistry.container, s))) {
1416 ast_log(LOG_ERROR, "failed to add FAX session '%u' to container.\n", s->id);
1417 ao2_ref(s, -1);
1418 return NULL;
1419 }
1420 ast_debug(4, "channel '%s' using FAX session '%u'\n", s->channame, s->id);
1421
1422 return s;
1423}
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ao2_link(container, obj)
Add an object to a container.
Definition astobj2.h:1532
const char * ast_channel_uniqueid(const struct ast_channel *chan)
void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold)
Set the minimum average magnitude threshold to determine talking by the DSP.
Definition dsp.c:1973
#define ast_module_running_ref(mod)
Hold a reference to the module if it is running.
Definition module.h:469
static char * ast_fax_caps_to_str(enum ast_fax_capabilities caps, char *buf, size_t bufsize)
Definition res_fax.c:947
static void destroy_session(void *session)
destroy a FAX session structure
Definition res_fax.c:1197
void *(*const new_session)(struct ast_fax_session *, struct ast_fax_tech_token *)
Definition res_fax.h:251
enum ast_fax_capabilities caps
Definition res_fax.h:243

References ao2_alloc, ao2_link, ao2_ref, ao2_unlink, ast_atomic_fetchadd_int(), ast_calloc, ast_channel_name(), ast_channel_uniqueid(), ast_debug, ast_dsp_new(), ast_dsp_set_threshold(), ast_fax_caps_to_str(), AST_FAX_STATE_RESERVED, AST_FAX_STATE_UNINITIALIZED, AST_FAX_TECH_AUDIO, ast_free, ast_log, ast_module_running_ref, ast_module_unref, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, ast_fax_session_details::caps, ast_fax_tech::caps, ast_fax_session::chan, ast_fax_session::chan_uniqueid, ast_fax_session::channame, ast_fax_session_details::debug, ast_fax_session::debug_info, ast_fax_tech::description, destroy_session(), ast_fax_session::details, ast_fax_debug_info::dsp, fax_session_release(), faxregistry, ast_fax_session_details::id, ast_fax_session::id, fax_module::list, LOG_ERROR, ast_fax_tech::new_session, NULL, ast_fax_session_details::option, ast_fax_session::state, ast_fax_session::tech, fax_module::tech, and ast_fax_session::tech_pvt.

Referenced by fax_gateway_start(), fax_v21_session_new(), and generic_fax_exec().

◆ fax_session_release()

static void fax_session_release ( struct ast_fax_session *  s,
struct ast_fax_tech_token *  token 
)
static

Release a session token.

Parameters
sa session returned from fax_session_reserve()
tokena token generated from fax_session_reserve()

This function releases the given token and marks the given session as no longer reserved. It is safe to call on a session that is not actually reserved and with a NULL token. This is so that sessions returned by technologies that do not support reserved sessions don't require extra logic to handle.

Note
This function DOES NOT release the given fax session, only the given token.

Definition at line 1184 of file res_fax.c.

1185{
1186 if (token) {
1187 s->tech->release_token(token);
1188 }
1189
1190 if (s->state == AST_FAX_STATE_RESERVED) {
1191 ast_atomic_fetchadd_int(&faxregistry.reserved_sessions, -1);
1193 }
1194}
void(*const release_token)(struct ast_fax_tech_token *)
Definition res_fax.h:249

References ast_atomic_fetchadd_int(), AST_FAX_STATE_INACTIVE, AST_FAX_STATE_RESERVED, faxregistry, ast_fax_tech::release_token, ast_fax_session::state, and ast_fax_session::tech.

Referenced by destroy_gateway(), destroy_session(), fax_session_new(), receivefax_exec(), and sendfax_exec().

◆ fax_session_reserve()

static struct ast_fax_session * fax_session_reserve ( struct ast_fax_session_details *  details,
struct ast_fax_tech_token **  token 
)
static

Reserve a fax session.

Parameters
detailsthe fax session details
tokena pointer to a place to store a token to be passed to fax_session_new() later

This function reserves a fax session for use later. If the selected fax technology does not support reserving sessions a session will still be returned but token will not be set.

Note
The reference returned by this function does not get consumed by fax_session_new() and must always be dereferenced separately.
Returns
NULL or an uninitialized and possibly reserved session

Definition at line 1247 of file res_fax.c.

1248{
1249 struct ast_fax_session *s;
1250 struct fax_module *faxmod;
1251
1252 if (!(s = ao2_alloc(sizeof(*s), destroy_session))) {
1253 return NULL;
1254 }
1255
1257 s->details = details;
1258 ao2_ref(s->details, 1);
1259
1260 /* locate a FAX technology module that can handle said requirements
1261 * Note: the requirements have not yet been finalized as T.38
1262 * negotiation has not yet occured. */
1265 if ((faxmod->tech->caps & details->caps) != details->caps) {
1266 continue;
1267 }
1268 if (!ast_module_running_ref(faxmod->tech->module)) {
1269 continue;
1270 }
1271 ast_debug(4, "Reserving a FAX session from '%s'.\n", faxmod->tech->description);
1272 s->tech = faxmod->tech;
1273 break;
1274 }
1276
1277 if (!faxmod) {
1278 char caps[128] = "";
1279 ast_log(LOG_ERROR, "Could not locate a FAX technology module with capabilities (%s)\n", ast_fax_caps_to_str(details->caps, caps, sizeof(caps)));
1280 ao2_ref(s, -1);
1281 return NULL;
1282 }
1283
1284 if (!s->tech->reserve_session) {
1285 ast_debug(1, "Selected FAX technology module (%s) does not support reserving sessions.\n", s->tech->description);
1286 return s;
1287 }
1288
1289 if (!(*token = s->tech->reserve_session(s))) {
1290 ao2_ref(s, -1);
1291 return NULL;
1292 }
1293
1295 ast_atomic_fetchadd_int(&faxregistry.reserved_sessions, 1);
1296
1297 return s;
1298}
struct ast_module *struct ast_fax_tech_token *(*const reserve_session)(struct ast_fax_session *)
Definition res_fax.h:247

References ao2_alloc, ao2_ref, ast_atomic_fetchadd_int(), ast_debug, ast_fax_caps_to_str(), AST_FAX_STATE_INACTIVE, AST_FAX_STATE_RESERVED, ast_log, ast_module_running_ref, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_fax_session_details::caps, ast_fax_tech::caps, ast_fax_tech::description, destroy_session(), ast_fax_session::details, faxregistry, fax_module::list, LOG_ERROR, NULL, ast_fax_tech::reserve_session, ast_fax_session::state, ast_fax_session::tech, and fax_module::tech.

Referenced by fax_gateway_new(), receivefax_exec(), and sendfax_exec().

◆ fax_session_tab_complete()

static char * fax_session_tab_complete ( struct ast_cli_args *  a)
static

fax session tab completion

Definition at line 4071 of file res_fax.c.

4072{
4073 int tklen;
4074 int wordnum = 0;
4075 char *name = NULL;
4076 struct ao2_iterator i;
4077 struct ast_fax_session *s;
4078 char tbuf[5];
4079
4080 if (a->pos != 3) {
4081 return NULL;
4082 }
4083
4084 tklen = strlen(a->word);
4085 i = ao2_iterator_init(faxregistry.container, 0);
4086 while ((s = ao2_iterator_next(&i))) {
4087 snprintf(tbuf, sizeof(tbuf), "%u", s->id);
4088 if (!strncasecmp(a->word, tbuf, tklen) && ++wordnum > a->n) {
4089 name = ast_strdup(tbuf);
4090 ao2_ref(s, -1);
4091 break;
4092 }
4093 ao2_ref(s, -1);
4094 }
4096 return name;
4097}
static const char name[]
Definition format_mp3.c:68

References a, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_strdup, faxregistry, ast_fax_session::id, name, and NULL.

Referenced by cli_fax_show_session().

◆ fax_session_type()

static const char * fax_session_type ( struct ast_fax_session *  s)
static

Definition at line 4370 of file res_fax.c.

4371{
4372 if (s->details->caps & AST_FAX_TECH_AUDIO) {
4373 return "G.711";
4374 }
4375 if (s->details->caps & AST_FAX_TECH_T38) {
4376 return "T.38";
4377 }
4378
4379 return "none";
4380}

References AST_FAX_TECH_AUDIO, AST_FAX_TECH_T38, ast_fax_session_details::caps, and ast_fax_session::details.

Referenced by cli_fax_show_sessions(), and manager_fax_sessions_entry().

◆ fax_v21_session_new()

static struct ast_fax_session * fax_v21_session_new ( struct ast_channel *  chan)
static

Definition at line 2962 of file res_fax.c.

2962 {
2963 struct ast_fax_session_details *v21_details;
2964 struct ast_fax_session *v21_session;
2965
2966 if (!chan || !(v21_details = session_details_new())) {
2967 return NULL;
2968 }
2969
2970 v21_details->caps = AST_FAX_TECH_V21_DETECT;
2971 v21_session = fax_session_new(v21_details, chan, NULL, NULL);
2972 ao2_ref(v21_details, -1);
2973 return v21_session;
2974}
static struct ast_fax_session_details * session_details_new(void)
create a FAX session details structure
Definition res_fax.c:797

References ao2_ref, AST_FAX_TECH_V21_DETECT, ast_fax_session_details::caps, ast_fax_session::chan, fax_session_new(), NULL, and session_details_new().

Referenced by fax_gateway_framehook(), and fax_gateway_new().

◆ find_details()

static struct ast_fax_session_details * find_details ( struct ast_channel *  chan)
static

returns a reference counted pointer to a fax datastore, if it exists

Definition at line 763 of file res_fax.c.

764{
765 struct ast_fax_session_details *details;
766 struct ast_datastore *datastore;
767
768 ast_channel_lock(chan);
769 if (!(datastore = ast_channel_datastore_find(chan, &fax_datastore, NULL))) {
770 ast_channel_unlock(chan);
771 return NULL;
772 }
773 if (!(details = datastore->data)) {
774 ast_log(LOG_WARNING, "Huh? channel '%s' has a FAX datastore without data!\n", ast_channel_name(chan));
775 ast_channel_unlock(chan);
776 return NULL;
777 }
778 ao2_ref(details, 1);
779 ast_channel_unlock(chan);
780
781 return details;
782}
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition channel.c:2390
static const struct ast_datastore_info fax_datastore
Definition res_fax.c:720
Structure for a data store object.
Definition datastore.h:64
void * data
Definition datastore.h:66

References ao2_ref, ast_channel_datastore_find(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_log, ast_datastore::data, fax_datastore, LOG_WARNING, and NULL.

Referenced by acf_faxopt_read(), fax_gateway_detect_t38(), fax_gateway_framehook(), fax_gateway_request_t38(), and find_or_create_details().

◆ find_or_create_details()

static struct ast_fax_session_details * find_or_create_details ( struct ast_channel *  chan)
static

returns a reference counted details structure from the channel's fax datastore. If the datastore does not exist it will be created

Definition at line 865 of file res_fax.c.

866{
867 struct ast_fax_session_details *details;
868 struct ast_datastore *datastore;
869
870 if ((details = find_details(chan))) {
871 return details;
872 }
873 /* channel does not have one so we must create one */
874 if (!(details = session_details_new())) {
875 ast_log(LOG_WARNING, "channel '%s' can't get a FAX details structure for the datastore!\n", ast_channel_name(chan));
876 return NULL;
877 }
878 if (!(datastore = ast_datastore_alloc(&fax_datastore, NULL))) {
879 ao2_ref(details, -1);
880 ast_log(LOG_WARNING, "channel '%s' can't get a datastore!\n", ast_channel_name(chan));
881 return NULL;
882 }
883 /* add the datastore to the channel and increment the refcount */
884 datastore->data = details;
885
886 /* initialize default T.38 parameters */
889
890 ao2_ref(details, 1);
891 ast_channel_lock(chan);
892 ast_channel_datastore_add(chan, datastore);
893 ast_channel_unlock(chan);
894 return details;
895}
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition channel.c:2376
#define ast_datastore_alloc(info, uid)
Definition datastore.h:85
static struct ast_control_t38_parameters our_t38_parameters
Definition res_fax.c:834

References ao2_ref, ast_channel_datastore_add(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_datastore_alloc, ast_log, ast_datastore::data, fax_datastore, find_details(), LOG_WARNING, NULL, ast_fax_session_details::our_t38_parameters, our_t38_parameters, session_details_new(), t38_parameters_ast_to_fax(), and ast_fax_session_details::their_t38_parameters.

Referenced by acf_faxopt_write(), fax_detect_attach(), fax_gateway_detect_v21(), fixup_callback(), receivefax_exec(), and sendfax_exec().

◆ fixup_callback()

static void fixup_callback ( void *  data,
struct ast_channel *  old_chan,
struct ast_channel *  new_chan 
)
static

Copies fax detection and gateway framehooks during masquerades.

Note
must be called with both old_chan and new_chan locked. Since this is only called by do_masquerade, that shouldn't be an issue.

Definition at line 737 of file res_fax.c.

738{
739 struct ast_fax_session_details *old_details = data;
740 struct ast_datastore *datastore = ast_channel_datastore_find(old_chan, &fax_datastore, NULL);
741
742 if (old_details->gateway_id >= 0) {
743 struct ast_fax_session_details *new_details = find_or_create_details(new_chan);
744
745 ast_framehook_detach(old_chan, old_details->gateway_id);
746 new_details->is_t38_negotiated = old_details->is_t38_negotiated;
747 fax_gateway_attach(new_chan, new_details);
748 ao2_cleanup(new_details);
749 }
750
751 if (old_details->faxdetect_id >= 0) {
752 ast_framehook_detach(old_chan, old_details->faxdetect_id);
753 fax_detect_attach(new_chan, old_details->faxdetect_timeout, old_details->faxdetect_flags);
754 }
755
756 if (datastore) {
757 ast_channel_datastore_remove(old_chan, datastore);
758 ast_datastore_free(datastore);
759 }
760}
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition channel.c:2385
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition datastore.c:68

References ao2_cleanup, ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_datastore_free(), ast_framehook_detach(), fax_datastore, fax_detect_attach(), fax_gateway_attach(), ast_fax_session_details::faxdetect_flags, ast_fax_session_details::faxdetect_id, ast_fax_session_details::faxdetect_timeout, find_or_create_details(), ast_fax_session_details::gateway_id, ast_fax_session_details::is_t38_negotiated, and NULL.

◆ generate_filenames_json()

static struct ast_json * generate_filenames_json ( struct ast_fax_session_details *  details)
static

Definition at line 1431 of file res_fax.c.

1432{
1433 RAII_VAR(struct ast_json *, json_array, ast_json_array_create(), ast_json_unref);
1434 struct ast_fax_document *doc;
1435
1436 if (!details || !json_array) {
1437 return NULL;
1438 }
1439
1440 /* don't process empty lists */
1441 if (AST_LIST_EMPTY(&details->documents)) {
1442 return NULL;
1443 }
1444
1445 AST_LIST_TRAVERSE(&details->documents, doc, next) {
1446 struct ast_json *entry = ast_json_string_create(doc->filename);
1447 if (!entry) {
1448 return NULL;
1449 }
1450 if (ast_json_array_append(json_array, entry)) {
1451 return NULL;
1452 }
1453 }
1454
1455 ast_json_ref(json_array);
1456 return json_array;
1457}
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition json.c:278
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition json.c:73
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition json.c:378
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition json.c:362
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition json.c:67
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
char filename[0]
Definition res_fax.h:104
Abstract JSON element (object, array, string, int, ...).

References ast_json_array_append(), ast_json_array_create(), ast_json_ref(), ast_json_string_create(), ast_json_unref(), AST_LIST_EMPTY, AST_LIST_TRAVERSE, ast_fax_session_details::documents, ast_fax_document::filename, ast_fax_document::next, NULL, and RAII_VAR.

Referenced by report_fax_status(), and report_send_fax_status().

◆ generate_filenames_string()

static char * generate_filenames_string ( struct ast_fax_session_details *  details,
char *  prefix,
char *  separator 
)
static

Generate a string of filenames using the given prefix and separator.

Parameters
detailsthe fax session details
prefixthe prefix to each filename
separatorthe separator between filenames

This function generates a string of filenames from the given details structure and using the given prefix and separator.

Return values
NULLthere was an error generating the string
Returns
the string generated string

Definition at line 1471 of file res_fax.c.

1472{
1473 char *filenames, *c;
1474 size_t size = 0;
1475 int first = 1;
1476 struct ast_fax_document *doc;
1477
1478 /* don't process empty lists */
1479 if (AST_LIST_EMPTY(&details->documents)) {
1480 return ast_strdup("");
1481 }
1482
1483 /* Calculate the total length of all of the file names */
1484 AST_LIST_TRAVERSE(&details->documents, doc, next) {
1485 size += strlen(separator) + strlen(prefix) + strlen(doc->filename);
1486 }
1487 size += 1; /* add space for the terminating null */
1488
1489 if (!(filenames = ast_malloc(size))) {
1490 return NULL;
1491 }
1492 c = filenames;
1493
1494 ast_build_string(&c, &size, "%s%s", prefix, AST_LIST_FIRST(&details->documents)->filename);
1495 AST_LIST_TRAVERSE(&details->documents, doc, next) {
1496 if (first) {
1497 first = 0;
1498 continue;
1499 }
1500
1501 ast_build_string(&c, &size, "%s%s%s", separator, prefix, doc->filename);
1502 }
1503
1504 return filenames;
1505}
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
static char prefix[MAX_PREFIX]
Definition http.c:145
static struct test_val c

References ast_build_string(), AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_TRAVERSE, ast_malloc, ast_strdup, c, ast_fax_session_details::documents, ast_fax_document::filename, first, ast_fax_document::next, NULL, and prefix.

Referenced by acf_faxopt_read(), cli_fax_show_sessions(), manager_fax_sessions_entry(), and sendfax_exec().

◆ generic_fax_exec()

static int generic_fax_exec ( struct ast_channel *  chan,
struct ast_fax_session_details *  details,
struct ast_fax_session *  reserved,
struct ast_fax_tech_token *  token 
)
static

this is the generic FAX session handling function

Definition at line 1691 of file res_fax.c.

1692{
1693 int ms;
1694 int timeout = RES_FAX_TIMEOUT;
1695 int chancount;
1696 unsigned int expected_frametype = -1;
1697 struct ast_frame_subclass expected_framesubclass = { .integer = 0, };
1698 unsigned int t38negotiated = (ast_channel_get_t38_state(chan) == T38_STATE_NEGOTIATED);
1699 struct ast_control_t38_parameters t38_parameters;
1700 const char *tempvar;
1701 struct ast_fax_session *fax = NULL;
1702 struct ast_frame *frame = NULL;
1703 struct ast_channel *c = chan;
1704 RAII_VAR(struct ast_format *, orig_write_format, NULL, ao2_cleanup);
1705 RAII_VAR(struct ast_format *, orig_read_format, NULL, ao2_cleanup);
1706 int remaining_time;
1707 struct timeval start;
1708
1709 chancount = 1;
1710
1711 /* Make sure one or the other is set to avoid race condition */
1712 if (t38negotiated) {
1713 details->caps |= AST_FAX_TECH_T38;
1714 } else {
1715 details->caps |= AST_FAX_TECH_AUDIO;
1716 }
1717
1718 /* create the FAX session */
1719 if (!(fax = fax_session_new(details, chan, reserved, token))) {
1720 ast_log(LOG_ERROR, "Can't create a FAX session, FAX attempt failed.\n");
1721 report_fax_status(chan, details, "No Available Resource");
1722 return -1;
1723 }
1724
1725 ast_channel_lock(chan);
1726 /* update session details */
1727 if (ast_strlen_zero(details->headerinfo) && (tempvar = pbx_builtin_getvar_helper(chan, "LOCALHEADERINFO"))) {
1728 ast_string_field_set(details, headerinfo, tempvar);
1729 }
1730 if (ast_strlen_zero(details->localstationid)) {
1731 tempvar = pbx_builtin_getvar_helper(chan, "LOCALSTATIONID");
1732 ast_string_field_set(details, localstationid, tempvar ? tempvar : "unknown");
1733 }
1734 ast_channel_unlock(chan);
1735
1736 report_fax_status(chan, details, "Allocating Resources");
1737
1738 if (details->caps & AST_FAX_TECH_AUDIO) {
1739 expected_frametype = AST_FRAME_VOICE;
1740 expected_framesubclass.format = ast_format_slin;
1741 orig_write_format = ao2_bump(ast_channel_writeformat(chan));
1742 if (ast_set_write_format(chan, ast_format_slin) < 0) {
1743 ast_log(LOG_ERROR, "channel '%s' failed to set write format to signed linear'.\n", ast_channel_name(chan));
1744 ao2_unlink(faxregistry.container, fax);
1745 ao2_ref(fax, -1);
1746 return -1;
1747 }
1748 orig_read_format = ao2_bump(ast_channel_readformat(chan));
1749 if (ast_set_read_format(chan, ast_format_slin) < 0) {
1750 ast_log(LOG_ERROR, "channel '%s' failed to set read format to signed linear.\n", ast_channel_name(chan));
1751 ao2_unlink(faxregistry.container, fax);
1752 ao2_ref(fax, -1);
1753 return -1;
1754 }
1755 if (fax->smoother) {
1757 fax->smoother = NULL;
1758 }
1759 if (!(fax->smoother = ast_smoother_new(320))) {
1760 ast_log(LOG_WARNING, "Channel '%s' FAX session '%u' failed to obtain a smoother.\n", ast_channel_name(chan), fax->id);
1761 }
1762 } else {
1763 expected_frametype = AST_FRAME_MODEM;
1764 expected_framesubclass.integer = AST_MODEM_T38;
1765 }
1766
1767 if (fax->debug_info) {
1768 fax->debug_info->base_tv = ast_tvnow();
1769 }
1770
1771 /* reset our result fields just in case the fax tech driver wants to
1772 * set custom error messages */
1773 ast_string_field_set(details, result, "");
1774 ast_string_field_set(details, resultstr, "");
1775 ast_string_field_set(details, error, "");
1776 details->is_t38_negotiated = t38negotiated;
1777 set_channel_variables(chan, details);
1778
1779 if (fax->tech->start_session(fax) < 0) {
1780 GENERIC_FAX_EXEC_ERROR(fax, chan, "INIT_ERROR", "failed to start FAX session");
1781 }
1782
1783 report_fax_status(chan, details, "FAX Transmission In Progress");
1784
1785 ast_debug(5, "channel %s will wait on FAX fd %d\n", ast_channel_name(chan), fax->fd);
1786
1787 /* handle frames for the session */
1788 remaining_time = timeout;
1789 start = ast_tvnow();
1790 while (remaining_time > 0) {
1791 struct ast_channel *ready_chan;
1792 int ofd, exception;
1793
1794 ms = 1000;
1795 errno = 0;
1796 ready_chan = ast_waitfor_nandfds(&c, chancount, &fax->fd, 1, &exception, &ofd, &ms);
1797 if (ready_chan) {
1798 if (!(frame = ast_read(chan))) {
1799 /* the channel is probably gone, so lets stop polling on it and let the
1800 * FAX session complete before we exit the application. if needed,
1801 * send the FAX stack silence so the modems can finish their session without
1802 * any problems */
1803 ast_debug(1, "Channel '%s' did not return a frame; probably hung up.\n", ast_channel_name(chan));
1804 GENERIC_FAX_EXEC_SET_VARS(fax, chan, "HANGUP", "remote channel hungup");
1805 c = NULL;
1806 chancount = 0;
1807 remaining_time = ast_remaining_ms(start, timeout);
1808 fax->tech->cancel_session(fax);
1809 if (fax->tech->generate_silence) {
1810 fax->tech->generate_silence(fax);
1811 }
1812 continue;
1813 }
1814
1815 if ((frame->frametype == AST_FRAME_CONTROL) &&
1817 (frame->datalen == sizeof(t38_parameters))) {
1818 unsigned int was_t38 = t38negotiated;
1819 struct ast_control_t38_parameters *parameters = frame->data.ptr;
1820
1821 switch (parameters->request_response) {
1823 /* the other end has requested a switch to T.38, so reply that we are willing, if we can
1824 * do T.38 as well
1825 */
1826 t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
1827 if (details->caps & AST_FAX_TECH_T38) {
1828 details->is_t38_negotiated = 1;
1829 t38_parameters.request_response = AST_T38_NEGOTIATED;
1830 } else {
1831 t38_parameters.request_response = AST_T38_REFUSED;
1832 }
1833 ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters));
1834 break;
1835 case AST_T38_NEGOTIATED:
1836 t38_parameters_ast_to_fax(&details->their_t38_parameters, parameters);
1837 t38negotiated = 1;
1838 details->is_t38_negotiated = 1;
1839 break;
1840 default:
1841 break;
1842 }
1843 if (t38negotiated && !was_t38) {
1844 if (fax->tech->switch_to_t38(fax)) {
1845 GENERIC_FAX_EXEC_ERROR(fax, chan, "UNKNOWN", "T.38 switch failed");
1846 break;
1847 }
1848 details->caps &= ~AST_FAX_TECH_AUDIO;
1849 expected_frametype = AST_FRAME_MODEM;
1850 expected_framesubclass.integer = AST_MODEM_T38;
1851 if (fax->smoother) {
1853 fax->smoother = NULL;
1854 }
1855
1856 report_fax_status(chan, details, "T.38 Negotiated");
1857
1858 ast_verb(3, "Channel '%s' switched to T.38 FAX session '%u'.\n", ast_channel_name(chan), fax->id);
1859 }
1860 } else if ((frame->frametype == expected_frametype) && (expected_framesubclass.integer == frame->subclass.integer) &&
1861 ((!frame->subclass.format && !expected_framesubclass.format) ||
1862 (frame->subclass.format && expected_framesubclass.format &&
1863 (ast_format_cmp(frame->subclass.format, expected_framesubclass.format) != AST_FORMAT_CMP_NOT_EQUAL)))) {
1864 struct ast_frame *f;
1865
1866 if (fax->smoother) {
1867 /* push the frame into a smoother */
1868 if (ast_smoother_feed(fax->smoother, frame) < 0) {
1869 GENERIC_FAX_EXEC_ERROR(fax, chan, "UNKNOWN", "Failed to feed the smoother");
1870 }
1871 while ((f = ast_smoother_read(fax->smoother)) && (f->data.ptr)) {
1872 if (fax->debug_info) {
1874 }
1875 /* write the frame to the FAX stack */
1876 fax->tech->write(fax, f);
1877 fax->frames_received++;
1878 if (f != frame) {
1879 ast_frfree(f);
1880 }
1881 }
1882 } else {
1883 /* write the frame to the FAX stack */
1884 fax->tech->write(fax, frame);
1885 fax->frames_received++;
1886 }
1887 start = ast_tvnow();
1888 }
1889 ast_frfree(frame);
1890 } else if (ofd == fax->fd) {
1891 /* read a frame from the FAX stack and send it out the channel.
1892 * the FAX stack will return a NULL if the FAX session has already completed */
1893 if (!(frame = fax->tech->read(fax))) {
1894 break;
1895 }
1896
1897 if (fax->debug_info && (frame->frametype == AST_FRAME_VOICE)) {
1898 debug_check_frame_for_silence(fax, 0, frame);
1899 }
1900
1901 ast_write(chan, frame);
1902 fax->frames_sent++;
1903 ast_frfree(frame);
1904 start = ast_tvnow();
1905 } else {
1906 if (ms && (ofd < 0)) {
1907 if ((errno == 0) || (errno == EINTR)) {
1908 remaining_time = ast_remaining_ms(start, timeout);
1909 if (remaining_time <= 0)
1910 GENERIC_FAX_EXEC_ERROR(fax, chan, "TIMEOUT", "fax session timed-out");
1911 continue;
1912 } else {
1913 ast_log(LOG_WARNING, "something bad happened while channel '%s' was polling.\n", ast_channel_name(chan));
1914 GENERIC_FAX_EXEC_ERROR(fax, chan, "UNKNOWN", "error polling data");
1915 break;
1916 }
1917 } else {
1918 /* nothing happened */
1919 remaining_time = ast_remaining_ms(start, timeout);
1920 if (remaining_time <= 0) {
1921 GENERIC_FAX_EXEC_ERROR(fax, chan, "TIMEOUT", "fax session timed-out");
1922 break;
1923 }
1924 }
1925 }
1926 }
1927 ast_debug(3, "channel '%s' - event loop stopped { timeout: %d, remaining_time: %d }\n", ast_channel_name(chan), timeout, remaining_time);
1928
1929 set_channel_variables(chan, details);
1930
1931 ast_atomic_fetchadd_int(&faxregistry.fax_complete, 1);
1932 if (!strcasecmp(details->result, "FAILED")) {
1933 ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
1934 }
1935
1936 if (fax) {
1937 ao2_unlink(faxregistry.container, fax);
1938 ao2_ref(fax, -1);
1939 }
1940
1941 /* if the channel is still alive, and we changed its read/write formats,
1942 * restore them now
1943 */
1944 if (chancount) {
1945 if (orig_read_format) {
1946 ast_set_read_format(chan, orig_read_format);
1947 }
1948 if (orig_write_format) {
1949 ast_set_write_format(chan, orig_write_format);
1950 }
1951 }
1952
1953 /* return the chancount so the calling function can determine if the channel hungup during this FAX session or not */
1954 return chancount;
1955}
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
static int chancount
Definition channel.c:97
struct ast_channel * ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
Waits for activity on a group of channels.
Definition channel.c:2992
@ AST_FORMAT_CMP_NOT_EQUAL
Definition format.h:38
int errno
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
static void debug_check_frame_for_silence(struct ast_fax_session *s, unsigned int c2s, struct ast_frame *frame)
Definition res_fax.c:678
#define GENERIC_FAX_EXEC_ERROR(fax, chan, errorstr, reason)
Definition res_fax.c:1586
#define GENERIC_FAX_EXEC_SET_VARS(fax, chan, errorstr, reason)
Definition res_fax.c:1570
#define RES_FAX_TIMEOUT
Definition res_fax.c:593
struct ast_frame * ast_smoother_read(struct ast_smoother *s)
Definition smoother.c:169
#define ast_smoother_feed(s, f)
Definition smoother.h:75
struct ast_smoother * ast_smoother_new(int bytes)
Definition smoother.c:108
unsigned long frames_received
Definition res_fax.h:210
unsigned long frames_sent
Definition res_fax.h:212
struct ast_frame *(*const read)(struct ast_fax_session *)
Definition res_fax.h:255
int(*const switch_to_t38)(struct ast_fax_session *)
Definition res_fax.h:265
int(*const generate_silence)(struct ast_fax_session *)
Definition res_fax.h:263
Definition of a media format.
Definition format.c:43

References ao2_bump, ao2_cleanup, ao2_ref, ao2_unlink, ast_atomic_fetchadd_int(), ast_channel_get_t38_state(), ast_channel_lock, ast_channel_name(), ast_channel_readformat(), ast_channel_unlock, ast_channel_writeformat(), AST_CONTROL_T38_PARAMETERS, ast_debug, AST_FAX_TECH_AUDIO, AST_FAX_TECH_T38, ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_slin, AST_FRAME_CONTROL, AST_FRAME_MODEM, AST_FRAME_VOICE, ast_frfree, ast_indicate_data(), ast_log, AST_MODEM_T38, ast_read(), ast_remaining_ms(), ast_set_read_format(), ast_set_write_format(), ast_smoother_feed, ast_smoother_free(), ast_smoother_new(), ast_smoother_read(), ast_string_field_set, ast_strlen_zero(), AST_T38_NEGOTIATED, AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, ast_tvnow(), ast_verb, ast_waitfor_nandfds(), ast_write(), ast_fax_debug_info::base_tv, c, ast_fax_tech::cancel_session, ast_fax_session_details::caps, chancount, ast_frame::data, ast_frame::datalen, debug_check_frame_for_silence(), ast_fax_session::debug_info, errno, error(), fax_session_new(), faxregistry, ast_fax_session::fd, ast_frame_subclass::format, ast_fax_session::frames_received, ast_fax_session::frames_sent, ast_frame::frametype, ast_fax_tech::generate_silence, GENERIC_FAX_EXEC_ERROR, GENERIC_FAX_EXEC_SET_VARS, ast_fax_session_details::headerinfo, ast_fax_session::id, ast_frame_subclass::integer, ast_fax_session_details::is_t38_negotiated, ast_fax_session_details::localstationid, LOG_ERROR, LOG_WARNING, NULL, ast_fax_session_details::our_t38_parameters, pbx_builtin_getvar_helper(), ast_frame::ptr, RAII_VAR, ast_fax_tech::read, report_fax_status(), ast_control_t38_parameters::request_response, RES_FAX_TIMEOUT, result, ast_fax_session_details::result, set_channel_variables(), ast_fax_session::smoother, ast_fax_tech::start_session, ast_frame::subclass, ast_fax_tech::switch_to_t38, t38_parameters_ast_to_fax(), t38_parameters_fax_to_ast(), T38_STATE_NEGOTIATED, ast_fax_session::tech, ast_fax_session_details::their_t38_parameters, and ast_fax_tech::write.

Referenced by receivefax_exec(), and sendfax_exec().

◆ get_general_options()

static void get_general_options ( struct fax_options *  options)
static

Definition at line 4525 of file res_fax.c.

4526{
4530}
#define ast_rwlock_rdlock(a)
Definition lock.h:242
#define ast_rwlock_unlock(a)
Definition lock.h:241
static ast_rwlock_t options_lock
Definition res_fax.c:649
static struct fax_options general_options
Definition res_fax.c:638

References ast_rwlock_rdlock, ast_rwlock_unlock, general_options, options, and options_lock.

Referenced by ast_fax_maxrate(), ast_fax_minrate(), cli_fax_show_settings(), and session_details_new().

◆ load_module()

static int load_module ( void  )
static

Load the module.

Module loading including tests for configuration or dependencies. This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails tests return AST_MODULE_LOAD_FAILURE. If the module can not load the configuration file or other non-critical problem return AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.

Definition at line 4916 of file res_fax.c.

4917{
4918 int res;
4919
4920 /* initialize the registry */
4921 faxregistry.active_sessions = 0;
4922 faxregistry.reserved_sessions = 0;
4925 if (!faxregistry.container) {
4927 }
4928
4929 if (set_config(0) < 0) {
4930 ast_log(LOG_ERROR, "failed to load configuration file '%s'\n", config);
4931 ao2_ref(faxregistry.container, -1);
4933 }
4934
4935 /* register CLI operations and applications */
4937 ast_log(LOG_WARNING, "failed to register '%s'.\n", app_sendfax);
4938 ao2_ref(faxregistry.container, -1);
4940 }
4942 ast_log(LOG_WARNING, "failed to register '%s'.\n", app_receivefax);
4944 ao2_ref(faxregistry.container, -1);
4946 }
4947
4949 ast_log(LOG_WARNING, "failed to register 'FAXSessions' AMI command.\n");
4952 ao2_ref(faxregistry.container, -1);
4954 }
4955
4957 ast_log(LOG_WARNING, "failed to register 'FAXSession' AMI command.\n");
4958 ast_manager_unregister("FAXSession");
4961 ao2_ref(faxregistry.container, -1);
4963 }
4964
4966 ast_log(LOG_WARNING, "failed to register 'FAXStats' AMI command.\n");
4967 ast_manager_unregister("FAXSession");
4968 ast_manager_unregister("FAXSessions");
4971 ao2_ref(faxregistry.container, -1);
4973 }
4974
4978
4979 return res;
4980}
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition astobj2.h:363
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition astobj2.h:1303
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition cli.h:265
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition manager.c:7792
int ast_logger_register_level(const char *name)
Register a new logger level.
Definition logger.c:2918
#define EVENT_FLAG_REPORTING
Definition manager.h:84
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition manager.h:193
#define EVENT_FLAG_CALL
Definition manager.h:76
int ast_unregister_application(const char *app)
Unregister an application.
Definition pbx_app.c:404
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition module.h:78
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition module.h:640
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1563
static int session_cmp_cb(void *obj, void *arg, int flags)
compare callback for ao2
Definition res_fax.c:4063
static int session_hash_cb(const void *obj, const int flags)
hash callback for ao2
Definition res_fax.c:4055
static const char app_receivefax[]
Definition res_fax.c:529
static struct ast_custom_function acf_faxopt
FAXOPT dialplan function.
Definition res_fax.c:4870
static const char * config
Definition res_fax.c:654
static int sendfax_exec(struct ast_channel *chan, const char *data)
initiate a send FAX session
Definition res_fax.c:2691
#define FAX_MAXBUCKETS
maximum buckets for res_fax ao2 containers
Definition res_fax.c:591
static int receivefax_exec(struct ast_channel *chan, const char *data)
initiate a receive FAX session
Definition res_fax.c:2183
static int set_config(int reload)
configure res_fax
Definition res_fax.c:4550
static const char app_sendfax[]
Definition res_fax.c:530
static int manager_fax_session(struct mansession *s, const struct message *m)
Definition res_fax.c:4271
static int manager_fax_stats(struct mansession *s, const struct message *m)
Definition res_fax.c:4341
static struct ast_cli_entry fax_cli[]
Definition res_fax.c:4508
static int manager_fax_sessions(struct mansession *s, const struct message *m)
Definition res_fax.c:4477
#define ARRAY_LEN(a)
Definition utils.h:706

References acf_faxopt, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_ref, app_receivefax, app_sendfax, ARRAY_LEN, ast_cli_register_multiple, ast_custom_function_register, ast_log, ast_logger_register_level(), ast_manager_register_xml, ast_manager_unregister(), AST_MODULE_LOAD_DECLINE, ast_register_application_xml, ast_unregister_application(), config, EVENT_FLAG_CALL, EVENT_FLAG_REPORTING, fax_cli, fax_logger_level, FAX_MAXBUCKETS, faxregistry, LOG_ERROR, LOG_WARNING, manager_fax_session(), manager_fax_sessions(), manager_fax_stats(), NULL, receivefax_exec(), sendfax_exec(), session_cmp_cb(), session_hash_cb(), and set_config().

◆ manager_fax_session()

static int manager_fax_session ( struct mansession *  s,
const struct message *  m 
)
static

Definition at line 4271 of file res_fax.c.

4272{
4273 const char *action_id = astman_get_header(m, "ActionID");
4274 const char *session_number = astman_get_header(m, "SessionNumber");
4275 char id_text[256] = "";
4276 struct ast_fax_session *session;
4278
4279 if (sscanf(session_number, "%30u", &find_session.id) != 1) {
4280 astman_send_error(s, m, "Invalid session ID");
4281 return 0;
4282 }
4283
4285 if (!session) {
4286 astman_send_error(s, m, "Session not found");
4287 return 0;
4288 }
4289
4290 if (!session->tech->manager_fax_session) {
4291 astman_send_error(s, m, "Fax technology doesn't provide a handler for FAXSession");
4292 ao2_ref(session, -1);
4293 return 0;
4294 }
4295
4296 if (!ast_strlen_zero(action_id)) {
4297 snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", action_id);
4298 }
4299
4300 astman_send_ack(s, m, "FAXSession event will follow");
4301
4302 session->tech->manager_fax_session(s, id_text, session);
4303 ao2_ref(session, -1);
4304
4305 return 0;
4306}
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition manager.c:1921
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition manager.c:1953
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition manager.c:1582
static struct mansession_session * find_session(uint32_t ident, int incinuse)
Definition manager.c:8030

References ao2_find, ao2_ref, ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), faxregistry, find_session(), OBJ_POINTER, and session.

Referenced by load_module().

◆ manager_fax_sessions()

static int manager_fax_sessions ( struct mansession *  s,
const struct message *  m 
)
static

Definition at line 4477 of file res_fax.c.

4478{
4479 const char *action_id = astman_get_header(m, "ActionID");
4480 char id_text[256];
4481 struct ast_fax_session *session;
4482 struct ao2_iterator iter;
4483 int session_count = 0;
4484
4485 id_text[0] = '\0';
4486 if (!ast_strlen_zero(action_id)) {
4487 snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", action_id);
4488 }
4489
4490 astman_send_listack(s, m, "FAXSessionsEntry event list will follow", "Start");
4491
4492 iter = ao2_iterator_init(faxregistry.container, 0);
4493 while ((session = ao2_iterator_next(&iter))) {
4494 if (!manager_fax_sessions_entry(s, session, id_text)) {
4495 session_count++;
4496 }
4497 ao2_ref(session, -1);
4498 }
4499 ao2_iterator_destroy(&iter);
4500
4501 astman_send_list_complete_start(s, m, "FAXSessionsComplete", session_count);
4502 astman_append(s, "Total: %d\r\n", session_count);
4504
4505 return 0;
4506}
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition manager.c:1963
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
Definition manager.c:1999
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition manager.c:2007
void astman_append(struct mansession *s, const char *fmt,...)
Definition manager.c:1842
static int manager_fax_sessions_entry(struct mansession *s, struct ast_fax_session *session, const char *id_text)
Definition res_fax.c:4445

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_list_complete_end(), astman_send_list_complete_start(), astman_send_listack(), faxregistry, manager_fax_sessions_entry(), session, and session_count.

Referenced by load_module().

◆ manager_fax_sessions_entry()

static int manager_fax_sessions_entry ( struct mansession *  s,
struct ast_fax_session *  session,
const char *  id_text 
)
static

Definition at line 4445 of file res_fax.c.

4447{
4448 char *filenames;
4449
4451 filenames = generate_filenames_string(session->details, "", ",");
4452
4453 if (!filenames) {
4454 ast_log(LOG_ERROR, "Error generating Files string");
4456 return -1;
4457 }
4458
4459 astman_append(s, "Event: FAXSessionsEntry\r\n"
4460 "%s" /* ActionID if present */
4461 "Channel: %s\r\n" /* Channel name */
4462 "Technology: %s\r\n" /* Fax session technology */
4463 "SessionNumber: %u\r\n" /* Session ID */
4464 "SessionType: %s\r\n" /* G711 or T38 */
4465 "Operation: %s\r\n"
4466 "State: %s\r\n"
4467 "Files: %s\r\n"
4468 "\r\n",
4469 id_text, session->channame, session->tech->type, session->id,
4471 ast_fax_state_to_str(session->state), S_OR(filenames, ""));
4472 ast_free(filenames);
4474 return 0;
4475}

References ao2_lock, ao2_unlock, ast_fax_session_operation_str(), ast_fax_state_to_str(), ast_free, ast_log, astman_append(), fax_session_type(), generate_filenames_string(), LOG_ERROR, S_OR, and session.

Referenced by manager_fax_sessions().

◆ manager_fax_stats()

static int manager_fax_stats ( struct mansession *  s,
const struct message *  m 
)
static

Definition at line 4341 of file res_fax.c.

4342{
4343 const char *action_id = astman_get_header(m, "ActionID");
4344
4345 char id_text[256] = "";
4346
4347 astman_send_ack(s, m, "FAXStats event will follow");
4348
4349 if (!ast_strlen_zero(action_id)) {
4350 snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", action_id);
4351 }
4352
4353 astman_append(s, "Event: FAXStats\r\n"
4354 "%s"
4355 "CurrentSessions: %d\r\n"
4356 "ReservedSessions: %d\r\n"
4357 "TransmitAttempts: %d\r\n"
4358 "ReceiveAttempts: %d\r\n"
4359 "CompletedFAXes: %d\r\n"
4360 "FailedFAXes: %d\r\n"
4361 "\r\n",
4362 id_text,
4363 faxregistry.active_sessions, faxregistry.reserved_sessions,
4364 faxregistry.fax_tx_attempts, faxregistry.fax_rx_attempts,
4365 faxregistry.fax_complete, faxregistry.fax_failures);
4366
4367 return 0;
4368}

References ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_ack(), and faxregistry.

Referenced by load_module().

◆ receivefax_exec()

static int receivefax_exec ( struct ast_channel *  chan,
const char *  data 
)
static

initiate a receive FAX session

Definition at line 2183 of file res_fax.c.

2184{
2185 char *parse, modems[128] = "";
2186 int channel_alive;
2188 RAII_VAR(struct ast_fax_session_details *, details, NULL, ao2_cleanup);
2189 struct ast_fax_tech_token *token = NULL;
2190 struct ast_fax_document *doc;
2194 );
2195 struct ast_flags opts = { 0, };
2196 enum ast_t38_state t38state;
2197
2198 /* initialize output channel variables */
2199 pbx_builtin_setvar_helper(chan, "FAXSTATUS", "FAILED");
2200 pbx_builtin_setvar_helper(chan, "REMOTESTATIONID", NULL);
2201 pbx_builtin_setvar_helper(chan, "FAXPAGES", "0");
2202 pbx_builtin_setvar_helper(chan, "FAXBITRATE", NULL);
2203 pbx_builtin_setvar_helper(chan, "FAXRESOLUTION", NULL);
2204 pbx_builtin_setvar_helper(chan, "FAXMODE", NULL);
2205
2206 /* Get a FAX session details structure from the channel's FAX datastore and create one if
2207 * it does not already exist. */
2208 if (!(details = find_or_create_details(chan))) {
2209 pbx_builtin_setvar_helper(chan, "FAXERROR", "MEMORY_ERROR");
2210 pbx_builtin_setvar_helper(chan, "FAXSTATUSSTRING", "error allocating memory");
2211 ast_log(LOG_ERROR, "System cannot provide memory for session requirements.\n");
2212 return -1;
2213 }
2214
2215 ast_string_field_set(details, result, "FAILED");
2216 ast_string_field_set(details, resultstr, "error starting fax session");
2217 ast_string_field_set(details, error, "INIT_ERROR");
2218 set_channel_variables(chan, details);
2219
2220 if (details->gateway_id > 0) {
2221 ast_string_field_set(details, resultstr, "can't receive a fax on a channel with a T.38 gateway");
2222 set_channel_variables(chan, details);
2223 ast_log(LOG_ERROR, "executing ReceiveFAX on a channel with a T.38 Gateway is not supported\n");
2224 return -1;
2225 }
2226
2227 if (details->maxrate < details->minrate) {
2228 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2229 ast_string_field_set(details, resultstr, "maxrate is less than minrate");
2230 set_channel_variables(chan, details);
2231 ast_log(LOG_ERROR, "maxrate %u is less than minrate %u\n", details->maxrate, details->minrate);
2232 return -1;
2233 }
2234
2235 if (check_modem_rate(details->modems, details->minrate)) {
2236 ast_fax_modem_to_str(details->modems, modems, sizeof(modems));
2237 ast_log(LOG_ERROR, "'modems' setting '%s' is incompatible with 'minrate' setting %u\n", modems, details->minrate);
2238 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2239 ast_string_field_set(details, resultstr, "incompatible 'modems' and 'minrate' settings");
2240 set_channel_variables(chan, details);
2241 return -1;
2242 }
2243
2244 if (check_modem_rate(details->modems, details->maxrate)) {
2245 ast_fax_modem_to_str(details->modems, modems, sizeof(modems));
2246 ast_log(LOG_ERROR, "'modems' setting '%s' is incompatible with 'maxrate' setting %u\n", modems, details->maxrate);
2247 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2248 ast_string_field_set(details, resultstr, "incompatible 'modems' and 'maxrate' settings");
2249 set_channel_variables(chan, details);
2250 return -1;
2251 }
2252
2253 if (ast_strlen_zero(data)) {
2254 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2255 ast_string_field_set(details, resultstr, "invalid arguments");
2256 set_channel_variables(chan, details);
2257 ast_log(LOG_WARNING, "%s requires an argument (filename[,options])\n", app_receivefax);
2258 return -1;
2259 }
2260 parse = ast_strdupa(data);
2262
2263 if (!ast_strlen_zero(args.options) &&
2264 ast_app_parse_options(fax_exec_options, &opts, NULL, args.options)) {
2265 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2266 ast_string_field_set(details, resultstr, "invalid arguments");
2267 set_channel_variables(chan, details);
2268 return -1;
2269 }
2270 if (ast_strlen_zero(args.filename)) {
2271 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2272 ast_string_field_set(details, resultstr, "invalid arguments");
2273 set_channel_variables(chan, details);
2274 ast_log(LOG_WARNING, "%s requires an argument (filename[,options])\n", app_receivefax);
2275 return -1;
2276 }
2277
2278 /* check for unsupported FAX application options */
2280 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2281 ast_string_field_set(details, resultstr, "invalid arguments");
2282 set_channel_variables(chan, details);
2283 ast_log(LOG_WARNING, "%s does not support polling\n", app_receivefax);
2284 return -1;
2285 }
2286
2287 ast_atomic_fetchadd_int(&faxregistry.fax_rx_attempts, 1);
2288
2289 pbx_builtin_setvar_helper(chan, "FAXERROR", "Channel Problems");
2290 pbx_builtin_setvar_helper(chan, "FAXSTATUSSTRING", "Error before FAX transmission started.");
2291
2292 if (!(doc = ast_calloc(1, sizeof(*doc) + strlen(args.filename) + 1))) {
2293 ast_string_field_set(details, error, "MEMORY_ERROR");
2294 ast_string_field_set(details, resultstr, "error allocating memory");
2295 set_channel_variables(chan, details);
2296 ast_log(LOG_ERROR, "System cannot provide memory for session requirements.\n");
2297 return -1;
2298 }
2299
2300 strcpy(doc->filename, args.filename);
2301 AST_LIST_INSERT_TAIL(&details->documents, doc, next);
2302
2303 ast_verb(3, "Channel '%s' receiving FAX '%s'\n", ast_channel_name(chan), args.filename);
2304
2305 details->caps = AST_FAX_TECH_RECEIVE;
2306 details->option.send_ced = AST_FAX_OPTFLAG_TRUE;
2307
2308 /* check for debug */
2309 if (ast_test_flag(&opts, OPT_DEBUG) || global_fax_debug) {
2310 details->option.debug = AST_FAX_OPTFLAG_TRUE;
2311 }
2312
2313 /* check for request for status events */
2314 if (ast_test_flag(&opts, OPT_STATUS)) {
2315 details->option.statusevents = AST_FAX_OPTFLAG_TRUE;
2316 }
2317
2318 t38state = ast_channel_get_t38_state(chan);
2319 if ((t38state == T38_STATE_UNAVAILABLE) || (t38state == T38_STATE_REJECTED) ||
2320 ast_test_flag(&opts, OPT_ALLOWAUDIO) ||
2322 details->option.allow_audio = AST_FAX_OPTFLAG_TRUE;
2323 }
2324
2325 if (!(s = fax_session_reserve(details, &token))) {
2326 ast_string_field_set(details, resultstr, "error reserving fax session");
2327 set_channel_variables(chan, details);
2328 ast_log(LOG_ERROR, "Unable to reserve FAX session.\n");
2329 return -1;
2330 }
2331
2332 /* make sure the channel is up */
2333 if (ast_channel_state(chan) != AST_STATE_UP) {
2334 if (ast_answer(chan)) {
2335 ast_string_field_set(details, resultstr, "error answering channel");
2336 set_channel_variables(chan, details);
2337 ast_log(LOG_WARNING, "Channel '%s' failed answer attempt.\n", ast_channel_name(chan));
2338 fax_session_release(s, token);
2339 return -1;
2340 }
2341 }
2342
2343 if (!ast_test_flag(&opts, OPT_FORCE_AUDIO)) {
2344 if (set_fax_t38_caps(chan, details)) {
2345 ast_string_field_set(details, error, "T38_NEG_ERROR");
2346 ast_string_field_set(details, resultstr, "error negotiating T.38");
2347 set_channel_variables(chan, details);
2348 fax_session_release(s, token);
2349 return -1;
2350 }
2351 } else {
2352 details->caps |= AST_FAX_TECH_AUDIO;
2353 }
2354
2355 if (!ast_test_flag(&opts, OPT_FORCE_AUDIO) && (details->caps & AST_FAX_TECH_T38)) {
2356 if (receivefax_t38_init(chan, details)) {
2357 ast_string_field_set(details, error, "T38_NEG_ERROR");
2358 ast_string_field_set(details, resultstr, "error negotiating T.38");
2359 set_channel_variables(chan, details);
2360 fax_session_release(s, token);
2361 ast_log(LOG_ERROR, "error initializing channel '%s' in T.38 mode\n", ast_channel_name(chan));
2362 return -1;
2363 }
2364 }
2365
2366 if ((channel_alive = generic_fax_exec(chan, details, s, token)) < 0) {
2367 ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
2368 }
2369
2371 if (disable_t38(chan)) {
2372 ast_debug(1, "error disabling T.38 mode on %s\n", ast_channel_name(chan));
2373 }
2374 }
2375
2376 if (report_receive_fax_status(chan, args.filename)) {
2377 ast_log(AST_LOG_ERROR, "Error publishing ReceiveFAX status message\n");
2378 }
2379
2380 /* If the channel hungup return -1; otherwise, return 0 to continue in the dialplan */
2381 return (!channel_alive) ? -1 : 0;
2382}
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition channel.c:2805
ast_channel_state
ast_channel states
@ AST_STATE_UP
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition main/app.c:3067
#define AST_LOG_ERROR
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
static int receivefax_t38_init(struct ast_channel *chan, struct ast_fax_session_details *details)
Definition res_fax.c:1957
static const struct ast_app_option fax_exec_options[128]
Definition res_fax.c:676
static int check_modem_rate(enum ast_fax_modems modems, unsigned int rate)
Definition res_fax.c:1039
static int generic_fax_exec(struct ast_channel *chan, struct ast_fax_session_details *details, struct ast_fax_session *reserved, struct ast_fax_tech_token *token)
this is the generic FAX session handling function
Definition res_fax.c:1691
static int set_fax_t38_caps(struct ast_channel *chan, struct ast_fax_session_details *details)
Definition res_fax.c:1592
static int disable_t38(struct ast_channel *chan)
Definition res_fax.c:1628
static int report_receive_fax_status(struct ast_channel *chan, const char *filename)
Report on the final state of a receive fax operation.
Definition res_fax.c:2119
static struct @523 args
Structure used to handle boolean flags.
Definition utils.h:220

References ao2_cleanup, app_receivefax, args, ast_answer(), AST_APP_ARG, ast_app_parse_options(), ast_atomic_fetchadd_int(), ast_calloc, ast_channel_get_t38_state(), ast_channel_name(), ast_debug, AST_DECLARE_APP_ARGS, ast_fax_modem_to_str(), AST_FAX_OPTFLAG_TRUE, AST_FAX_TECH_AUDIO, AST_FAX_TECH_RECEIVE, AST_FAX_TECH_T38, AST_LIST_INSERT_TAIL, ast_log, AST_LOG_ERROR, AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verb, check_modem_rate(), disable_t38(), error(), fax_exec_options, fax_session_release(), fax_session_reserve(), faxregistry, ast_fax_document::filename, find_or_create_details(), generic_fax_exec(), global_fax_debug, LOG_ERROR, LOG_WARNING, NULL, OPT_ALLOWAUDIO, OPT_CALLEDMODE, OPT_CALLERMODE, OPT_DEBUG, OPT_FORCE_AUDIO, OPT_STATUS, options, pbx_builtin_setvar_helper(), RAII_VAR, receivefax_t38_init(), report_receive_fax_status(), result, set_channel_variables(), set_fax_t38_caps(), T38_STATE_NEGOTIATED, T38_STATE_REJECTED, and T38_STATE_UNAVAILABLE.

Referenced by load_module().

◆ receivefax_t38_init()

static int receivefax_t38_init ( struct ast_channel *  chan,
struct ast_fax_session_details *  details 
)
static

Definition at line 1957 of file res_fax.c.

1958{
1959 int timeout_ms;
1960 struct ast_frame *frame = NULL;
1961 struct ast_control_t38_parameters t38_parameters;
1962 struct timeval start;
1963 int ms;
1964
1965 /* don't send any audio if we've already received a T.38 reinvite */
1967 /* generate 3 seconds of CED */
1968 if (ast_playtones_start(chan, 1024, "!2100/3000", 1)) {
1969 ast_log(LOG_ERROR, "error generating CED tone on %s\n", ast_channel_name(chan));
1970 return -1;
1971 }
1972
1973 timeout_ms = 3000;
1974 start = ast_tvnow();
1975 while ((ms = ast_remaining_ms(start, timeout_ms))) {
1976 ms = ast_waitfor(chan, ms);
1977
1978 if (ms < 0) {
1979 ast_log(LOG_ERROR, "error while generating CED tone on %s\n", ast_channel_name(chan));
1980 ast_playtones_stop(chan);
1981 return -1;
1982 }
1983
1984 if (ms == 0) { /* all done, nothing happened */
1985 break;
1986 }
1987
1988 if (!(frame = ast_read(chan))) {
1989 ast_log(LOG_ERROR, "error reading frame while generating CED tone on %s\n", ast_channel_name(chan));
1990 ast_playtones_stop(chan);
1991 return -1;
1992 }
1993
1994 if ((frame->frametype == AST_FRAME_CONTROL) &&
1996 (frame->datalen == sizeof(t38_parameters))) {
1997 struct ast_control_t38_parameters *parameters = frame->data.ptr;
1998
1999 switch (parameters->request_response) {
2001 /* the other end has requested a switch to T.38, so reply that we are willing, if we can
2002 * do T.38 as well
2003 */
2004 t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
2005 t38_parameters.request_response = (details->caps & AST_FAX_TECH_T38) ? AST_T38_NEGOTIATED : AST_T38_REFUSED;
2006 ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters));
2007 ast_playtones_stop(chan);
2008 break;
2009 case AST_T38_NEGOTIATED:
2010 ast_debug(1, "Negotiated T.38 for receive on %s\n", ast_channel_name(chan));
2011 t38_parameters_ast_to_fax(&details->their_t38_parameters, parameters);
2012 details->caps &= ~AST_FAX_TECH_AUDIO;
2013 report_fax_status(chan, details, "T.38 Negotiated");
2014 break;
2015 default:
2016 break;
2017 }
2018 }
2019 ast_frfree(frame);
2020 }
2021
2022 ast_playtones_stop(chan);
2023 }
2024
2025 /* if T.38 was negotiated, we are done initializing */
2027 return 0;
2028 }
2029
2030 /* request T.38 */
2031 ast_debug(1, "Negotiating T.38 for receive on %s\n", ast_channel_name(chan));
2032
2033 /* wait for negotiation to complete */
2034 timeout_ms = details->t38timeout;
2035
2036 /* set parameters based on the session's parameters */
2037 t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
2038 t38_parameters.request_response = AST_T38_REQUEST_NEGOTIATE;
2039 if ((ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters)) != 0)) {
2040 return -1;
2041 }
2042
2043 start = ast_tvnow();
2044 while ((ms = ast_remaining_ms(start, timeout_ms))) {
2045 int break_loop = 0;
2046
2047 ms = ast_waitfor(chan, ms);
2048 if (ms < 0) {
2049 ast_log(LOG_WARNING, "error on '%s' while waiting for T.38 negotiation.\n", ast_channel_name(chan));
2050 return -1;
2051 }
2052 if (ms == 0) { /* all done, nothing happened */
2053 ast_log(LOG_WARNING, "channel '%s' timed-out during the T.38 negotiation.\n", ast_channel_name(chan));
2054 details->caps &= ~AST_FAX_TECH_T38;
2055 break;
2056 }
2057
2058 if (!(frame = ast_read(chan))) {
2059 ast_log(LOG_WARNING, "error on '%s' while waiting for T.38 negotiation.\n", ast_channel_name(chan));
2060 return -1;
2061 }
2062
2063 if ((frame->frametype == AST_FRAME_CONTROL) &&
2065 (frame->datalen == sizeof(t38_parameters))) {
2066 struct ast_control_t38_parameters *parameters = frame->data.ptr;
2067
2068 switch (parameters->request_response) {
2070 t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
2071 t38_parameters.request_response = AST_T38_NEGOTIATED;
2072 ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters));
2073 break;
2074 case AST_T38_NEGOTIATED:
2075 ast_debug(1, "Negotiated T.38 for receive on %s\n", ast_channel_name(chan));
2076 t38_parameters_ast_to_fax(&details->their_t38_parameters, parameters);
2077 details->caps &= ~AST_FAX_TECH_AUDIO;
2078 report_fax_status(chan, details, "T.38 Negotiated");
2079 break_loop = 1;
2080 break;
2081 case AST_T38_REFUSED:
2082 ast_log(LOG_WARNING, "channel '%s' refused to negotiate T.38\n", ast_channel_name(chan));
2083 details->caps &= ~AST_FAX_TECH_T38;
2084 break_loop = 1;
2085 break;
2086 default:
2087 ast_log(LOG_ERROR, "channel '%s' failed to negotiate T.38\n", ast_channel_name(chan));
2088 details->caps &= ~AST_FAX_TECH_T38;
2089 break_loop = 1;
2090 break;
2091 }
2092 }
2093 ast_frfree(frame);
2094 if (break_loop) {
2095 break;
2096 }
2097 }
2098
2099 /* if T.38 was negotiated, we are done initializing */
2101 return 0;
2102 }
2103
2104 /* if we made it here, then T.38 failed, check the 'f' flag */
2105 if (details->option.allow_audio != AST_FAX_OPTFLAG_TRUE) {
2106 ast_log(LOG_WARNING, "Audio FAX not allowed on channel '%s' and T.38 negotiation failed; aborting.\n", ast_channel_name(chan));
2107 return -1;
2108 }
2109
2110 /* ok, audio fallback is allowed */
2111 details->caps |= AST_FAX_TECH_AUDIO;
2112
2113 return 0;
2114}
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.

References ast_fax_session_details::allow_audio, ast_channel_get_t38_state(), ast_channel_name(), AST_CONTROL_T38_PARAMETERS, ast_debug, AST_FAX_OPTFLAG_TRUE, AST_FAX_TECH_AUDIO, AST_FAX_TECH_T38, AST_FRAME_CONTROL, ast_frfree, ast_indicate_data(), ast_log, ast_playtones_start(), ast_playtones_stop(), ast_read(), ast_remaining_ms(), AST_T38_NEGOTIATED, AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, ast_tvnow(), ast_waitfor(), ast_fax_session_details::caps, ast_frame::data, ast_frame::datalen, ast_frame::frametype, ast_frame_subclass::integer, LOG_ERROR, LOG_WARNING, NULL, ast_fax_session_details::option, ast_fax_session_details::our_t38_parameters, ast_frame::ptr, report_fax_status(), ast_control_t38_parameters::request_response, ast_frame::subclass, t38_parameters_ast_to_fax(), t38_parameters_fax_to_ast(), T38_STATE_NEGOTIATED, T38_STATE_NEGOTIATING, ast_fax_session_details::t38timeout, and ast_fax_session_details::their_t38_parameters.

Referenced by receivefax_exec().

◆ reload_module()

static int reload_module ( void  )
static

Definition at line 4982 of file res_fax.c.

4983{
4984 set_config(1);
4985 return 0;
4986}

References set_config().

◆ report_fax_status()

static int report_fax_status ( struct ast_channel *  chan,
struct ast_fax_session_details *  details,
const char *  status 
)
static

send a FAX status manager event

Definition at line 1508 of file res_fax.c.

1509{
1510 RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
1512 struct ast_json *json_filenames = NULL;
1513
1514 if (!details->option.statusevents) {
1515 return 0;
1516 }
1517
1518 json_filenames = generate_filenames_json(details);
1519 if (!json_filenames) {
1520 return -1;
1521 }
1522
1523 json_object = ast_json_pack("{s: s, s: s, s: s, s: s, s: o}",
1524 "type", "status",
1525 "operation", (details->caps & AST_FAX_TECH_GATEWAY)
1526 ? "gateway"
1527 : (details->caps & AST_FAX_TECH_RECEIVE) ? "receive" : "send",
1528 "status", status,
1529 "local_station_id", AST_JSON_UTF8_VALIDATE(details->localstationid),
1530 "filenames", json_filenames);
1531 if (!json_object) {
1532 return -1;
1533 }
1534
1535 {
1536 SCOPED_CHANNELLOCK(lock, chan);
1537
1539 if (!message) {
1540 return -1;
1541 }
1543 }
1544 return 0;
1545}
jack_status_t status
Definition app_jack.c:149
ast_mutex_t lock
Definition app_sla.c:337
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
struct stasis_message * ast_channel_blob_create_from_cache(const char *uniqueid, struct stasis_message_type *type, struct ast_json *blob)
Create a ast_channel_blob message, pulling channel state from the cache.
struct stasis_message_type * ast_channel_fax_type(void)
Message type for a fax operation.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition json.c:612
#define AST_JSON_UTF8_VALIDATE(str)
Check str for UTF-8 and replace with an empty string if fails the check.
Definition json.h:224
#define SCOPED_CHANNELLOCK(varname, chan)
scoped lock specialization for channels.
Definition lock.h:626
static struct ast_json * generate_filenames_json(struct ast_fax_session_details *details)
Definition res_fax.c:1431
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition stasis.c:1589

References ao2_cleanup, ast_channel_blob_create_from_cache(), ast_channel_fax_type(), ast_channel_topic(), ast_channel_uniqueid(), AST_FAX_TECH_GATEWAY, AST_FAX_TECH_RECEIVE, ast_json_pack(), ast_json_unref(), AST_JSON_UTF8_VALIDATE, ast_fax_session_details::caps, generate_filenames_json(), ast_fax_session_details::localstationid, lock, NULL, ast_fax_session_details::option, RAII_VAR, SCOPED_CHANNELLOCK, stasis_publish(), status, and ast_fax_session_details::statusevents.

Referenced by fax_gateway_attach(), fax_gateway_detect_t38(), fax_gateway_start(), generic_fax_exec(), receivefax_t38_init(), and sendfax_t38_init().

◆ report_receive_fax_status()

static int report_receive_fax_status ( struct ast_channel *  chan,
const char *  filename 
)
static

Report on the final state of a receive fax operation.

Note
This will lock the ast_channel

Definition at line 2119 of file res_fax.c.

2120{
2121 RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
2123 RAII_VAR(struct ast_json *, json_array, ast_json_array_create(), ast_json_unref);
2124 struct ast_json *json_filename = ast_json_string_create(filename);
2125
2126 if (!json_array || !json_filename) {
2127 ast_json_unref(json_filename);
2128 return -1;
2129 }
2130 ast_json_array_append(json_array, json_filename);
2131
2132 {
2133 const char *remote_station_id;
2134 const char *local_station_id;
2135 const char *fax_pages;
2136 const char *fax_resolution;
2137 const char *fax_bitrate;
2138 SCOPED_CHANNELLOCK(lock, chan);
2139
2140 remote_station_id = AST_JSON_UTF8_VALIDATE(pbx_builtin_getvar_helper(chan, "REMOTESTATIONID"));
2141 if (!ast_strlen_zero(remote_station_id)) {
2142 remote_station_id = ast_strdupa(remote_station_id);
2143 }
2144 local_station_id = AST_JSON_UTF8_VALIDATE(pbx_builtin_getvar_helper(chan, "LOCALSTATIONID"));
2145 if (!ast_strlen_zero(local_station_id)) {
2146 local_station_id = ast_strdupa(local_station_id);
2147 }
2148 fax_pages = S_OR(pbx_builtin_getvar_helper(chan, "FAXPAGES"), "");
2149 if (!ast_strlen_zero(fax_pages)) {
2150 fax_pages = ast_strdupa(fax_pages);
2151 }
2152 fax_resolution = S_OR(pbx_builtin_getvar_helper(chan, "FAXRESOLUTION"), "");
2153 if (!ast_strlen_zero(fax_resolution)) {
2154 fax_resolution = ast_strdupa(fax_resolution);
2155 }
2156 fax_bitrate = S_OR(pbx_builtin_getvar_helper(chan, "FAXBITRATE"), "");
2157 if (!ast_strlen_zero(fax_bitrate)) {
2158 fax_bitrate = ast_strdupa(fax_bitrate);
2159 }
2160
2161 json_object = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: o}",
2162 "type", "receive",
2163 "remote_station_id", S_OR(remote_station_id, ""),
2164 "local_station_id", S_OR(local_station_id, ""),
2165 "fax_pages", S_OR(fax_pages, ""),
2166 "fax_resolution", S_OR(fax_resolution, ""),
2167 "fax_bitrate", S_OR(fax_bitrate, ""),
2168 "filenames", ast_json_ref(json_array));
2169 if (!json_object) {
2170 return -1;
2171 }
2172
2174 if (!message) {
2175 return -1;
2176 }
2178 }
2179 return 0;
2180}

References ao2_cleanup, ast_channel_blob_create_from_cache(), ast_channel_fax_type(), ast_channel_topic(), ast_channel_uniqueid(), ast_json_array_append(), ast_json_array_create(), ast_json_pack(), ast_json_ref(), ast_json_string_create(), ast_json_unref(), AST_JSON_UTF8_VALIDATE, ast_strdupa, ast_strlen_zero(), lock, NULL, pbx_builtin_getvar_helper(), RAII_VAR, S_OR, SCOPED_CHANNELLOCK, and stasis_publish().

Referenced by receivefax_exec().

◆ report_send_fax_status()

static int report_send_fax_status ( struct ast_channel *  chan,
struct ast_fax_session_details *  details 
)
static

Report on the status of a completed fax send attempt.

Note
This will lock the ast_channel

Definition at line 2628 of file res_fax.c.

2629{
2630 RAII_VAR(struct ast_json *, json_obj, NULL, ast_json_unref);
2632 struct ast_json *json_filenames;
2633
2634 json_filenames = generate_filenames_json(details);
2635 if (!json_filenames) {
2636 return -1;
2637 }
2638
2639 {
2640 const char *remote_station_id;
2641 const char *local_station_id;
2642 const char *fax_pages;
2643 const char *fax_resolution;
2644 const char *fax_bitrate;
2645 SCOPED_CHANNELLOCK(lock, chan);
2646
2647 remote_station_id = AST_JSON_UTF8_VALIDATE(pbx_builtin_getvar_helper(chan, "REMOTESTATIONID"));
2648 if (!ast_strlen_zero(remote_station_id)) {
2649 remote_station_id = ast_strdupa(remote_station_id);
2650 }
2651 local_station_id = AST_JSON_UTF8_VALIDATE(pbx_builtin_getvar_helper(chan, "LOCALSTATIONID"));
2652 if (!ast_strlen_zero(local_station_id)) {
2653 local_station_id = ast_strdupa(local_station_id);
2654 }
2655 fax_pages = S_OR(pbx_builtin_getvar_helper(chan, "FAXPAGES"), "");
2656 if (!ast_strlen_zero(fax_pages)) {
2657 fax_pages = ast_strdupa(fax_pages);
2658 }
2659 fax_resolution = S_OR(pbx_builtin_getvar_helper(chan, "FAXRESOLUTION"), "");
2660 if (!ast_strlen_zero(fax_resolution)) {
2661 fax_resolution = ast_strdupa(fax_resolution);
2662 }
2663 fax_bitrate = S_OR(pbx_builtin_getvar_helper(chan, "FAXBITRATE"), "");
2664 if (!ast_strlen_zero(fax_bitrate)) {
2665 fax_bitrate = ast_strdupa(fax_bitrate);
2666 }
2667 json_obj = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: o}",
2668 "type", "send",
2669 "remote_station_id", S_OR(remote_station_id, ""),
2670 "local_station_id", S_OR(local_station_id, ""),
2671 "fax_pages", S_OR(fax_pages, ""),
2672 "fax_resolution", S_OR(fax_resolution, ""),
2673 "fax_bitrate", S_OR(fax_bitrate, ""),
2674 "filenames", json_filenames);
2675 if (!json_obj) {
2676 return -1;
2677 }
2678
2680 if (!message) {
2681 return -1;
2682 }
2684 }
2685 return 0;
2686}

References ao2_cleanup, ast_channel_blob_create_from_cache(), ast_channel_fax_type(), ast_channel_topic(), ast_channel_uniqueid(), ast_json_pack(), ast_json_unref(), AST_JSON_UTF8_VALIDATE, ast_strdupa, ast_strlen_zero(), generate_filenames_json(), lock, NULL, pbx_builtin_getvar_helper(), RAII_VAR, S_OR, SCOPED_CHANNELLOCK, and stasis_publish().

Referenced by sendfax_exec().

◆ sendfax_exec()

static int sendfax_exec ( struct ast_channel *  chan,
const char *  data 
)
static

initiate a send FAX session

Definition at line 2691 of file res_fax.c.

2692{
2693 char *parse, *filenames, *c, modems[128] = "";
2694 int channel_alive, file_count;
2695 RAII_VAR(struct ast_fax_session_details *, details, NULL, ao2_cleanup);
2697 struct ast_fax_tech_token *token = NULL;
2698 struct ast_fax_document *doc;
2700 AST_APP_ARG(filenames);
2702 );
2703 struct ast_flags opts = { 0, };
2704 enum ast_t38_state t38state;
2705
2706 /* initialize output channel variables */
2707 pbx_builtin_setvar_helper(chan, "FAXSTATUS", "FAILED");
2708 pbx_builtin_setvar_helper(chan, "REMOTESTATIONID", NULL);
2709 pbx_builtin_setvar_helper(chan, "FAXPAGES", "0");
2710 pbx_builtin_setvar_helper(chan, "FAXBITRATE", NULL);
2711 pbx_builtin_setvar_helper(chan, "FAXRESOLUTION", NULL);
2712 pbx_builtin_setvar_helper(chan, "FAXMODE", NULL);
2713
2714 /* Get a requirement structure and set it. This structure is used
2715 * to tell the FAX technology module about the higher level FAX session */
2716 if (!(details = find_or_create_details(chan))) {
2717 pbx_builtin_setvar_helper(chan, "FAXERROR", "MEMORY_ERROR");
2718 pbx_builtin_setvar_helper(chan, "FAXSTATUSSTRING", "error allocating memory");
2719 ast_log(LOG_ERROR, "System cannot provide memory for session requirements.\n");
2720 return -1;
2721 }
2722
2723 ast_string_field_set(details, result, "FAILED");
2724 ast_string_field_set(details, resultstr, "error starting fax session");
2725 ast_string_field_set(details, error, "INIT_ERROR");
2726 set_channel_variables(chan, details);
2727
2728 if (details->gateway_id > 0) {
2729 ast_string_field_set(details, resultstr, "can't send a fax on a channel with a T.38 gateway");
2730 set_channel_variables(chan, details);
2731 ast_log(LOG_ERROR, "executing SendFAX on a channel with a T.38 Gateway is not supported\n");
2732 return -1;
2733 }
2734
2735 if (details->maxrate < details->minrate) {
2736 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2737 ast_string_field_set(details, resultstr, "maxrate is less than minrate");
2738 set_channel_variables(chan, details);
2739 ast_log(LOG_ERROR, "maxrate %u is less than minrate %u\n", details->maxrate, details->minrate);
2740 return -1;
2741 }
2742
2743 if (check_modem_rate(details->modems, details->minrate)) {
2744 ast_fax_modem_to_str(details->modems, modems, sizeof(modems));
2745 ast_log(LOG_ERROR, "'modems' setting '%s' is incompatible with 'minrate' setting %u\n", modems, details->minrate);
2746 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2747 ast_string_field_set(details, resultstr, "incompatible 'modems' and 'minrate' settings");
2748 set_channel_variables(chan, details);
2749 return -1;
2750 }
2751
2752 if (check_modem_rate(details->modems, details->maxrate)) {
2753 ast_fax_modem_to_str(details->modems, modems, sizeof(modems));
2754 ast_log(LOG_ERROR, "'modems' setting '%s' is incompatible with 'maxrate' setting %u\n", modems, details->maxrate);
2755 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2756 ast_string_field_set(details, resultstr, "incompatible 'modems' and 'maxrate' settings");
2757 set_channel_variables(chan, details);
2758 return -1;
2759 }
2760
2761 if (ast_strlen_zero(data)) {
2762 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2763 ast_string_field_set(details, resultstr, "invalid arguments");
2764 set_channel_variables(chan, details);
2765 ast_log(LOG_WARNING, "%s requires an argument (filename[&filename[&filename]][,options])\n", app_sendfax);
2766 return -1;
2767 }
2768 parse = ast_strdupa(data);
2770
2771
2772 if (!ast_strlen_zero(args.options) &&
2773 ast_app_parse_options(fax_exec_options, &opts, NULL, args.options)) {
2774 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2775 ast_string_field_set(details, resultstr, "invalid arguments");
2776 set_channel_variables(chan, details);
2777 return -1;
2778 }
2779 if (ast_strlen_zero(args.filenames)) {
2780 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2781 ast_string_field_set(details, resultstr, "invalid arguments");
2782 set_channel_variables(chan, details);
2783 ast_log(LOG_WARNING, "%s requires an argument (filename[&filename[&filename]],options])\n", app_sendfax);
2784 return -1;
2785 }
2786
2787 /* check for unsupported FAX application options */
2789 ast_string_field_set(details, error, "INVALID_ARGUMENTS");
2790 ast_string_field_set(details, resultstr, "invalid arguments");
2791 set_channel_variables(chan, details);
2792 ast_log(LOG_WARNING, "%s does not support polling\n", app_sendfax);
2793 return -1;
2794 }
2795
2796 ast_atomic_fetchadd_int(&faxregistry.fax_tx_attempts, 1);
2797
2798 file_count = 0;
2799 filenames = args.filenames;
2800 while ((c = strsep(&filenames, "&"))) {
2801 if (access(c, (F_OK | R_OK)) < 0) {
2802 ast_string_field_set(details, error, "FILE_ERROR");
2803 ast_string_field_set(details, resultstr, "error reading file");
2804 set_channel_variables(chan, details);
2805 ast_log(LOG_ERROR, "access failure. Verify '%s' exists and check permissions.\n", args.filenames);
2806 return -1;
2807 }
2808
2809 if (!(doc = ast_calloc(1, sizeof(*doc) + strlen(c) + 1))) {
2810 ast_string_field_set(details, error, "MEMORY_ERROR");
2811 ast_string_field_set(details, resultstr, "error allocating memory");
2812 set_channel_variables(chan, details);
2813 ast_log(LOG_ERROR, "System cannot provide memory for session requirements.\n");
2814 return -1;
2815 }
2816
2817 strcpy(doc->filename, c);
2818 AST_LIST_INSERT_TAIL(&details->documents, doc, next);
2819 file_count++;
2820 }
2821
2822 ast_verb(3, "Channel '%s' sending FAX:\n", ast_channel_name(chan));
2823 AST_LIST_TRAVERSE(&details->documents, doc, next) {
2824 ast_verb(3, " %s\n", doc->filename);
2825 }
2826
2827 details->caps = AST_FAX_TECH_SEND;
2828
2829 if (file_count > 1) {
2830 details->caps |= AST_FAX_TECH_MULTI_DOC;
2831 }
2832
2833 /* check for debug */
2834 if (ast_test_flag(&opts, OPT_DEBUG) || global_fax_debug) {
2835 details->option.debug = AST_FAX_OPTFLAG_TRUE;
2836 }
2837
2838 /* check for request for status events */
2839 if (ast_test_flag(&opts, OPT_STATUS)) {
2840 details->option.statusevents = AST_FAX_OPTFLAG_TRUE;
2841 }
2842
2843 t38state = ast_channel_get_t38_state(chan);
2844 if ((t38state == T38_STATE_UNAVAILABLE) || (t38state == T38_STATE_REJECTED) ||
2845 ast_test_flag(&opts, OPT_ALLOWAUDIO) ||
2847 details->option.allow_audio = AST_FAX_OPTFLAG_TRUE;
2848 }
2849
2850 if (ast_test_flag(&opts, OPT_REQUEST_T38)) {
2851 details->option.request_t38 = AST_FAX_OPTFLAG_TRUE;
2852 }
2853
2854 if (!(s = fax_session_reserve(details, &token))) {
2855 ast_string_field_set(details, resultstr, "error reserving fax session");
2856 set_channel_variables(chan, details);
2857 ast_log(LOG_ERROR, "Unable to reserve FAX session.\n");
2858 return -1;
2859 }
2860
2861 /* make sure the channel is up */
2862 if (ast_channel_state(chan) != AST_STATE_UP) {
2863 if (ast_answer(chan)) {
2864 ast_string_field_set(details, resultstr, "error answering channel");
2865 set_channel_variables(chan, details);
2866 ast_log(LOG_WARNING, "Channel '%s' failed answer attempt.\n", ast_channel_name(chan));
2867 fax_session_release(s, token);
2868 return -1;
2869 }
2870 }
2871
2872 if (!ast_test_flag(&opts, OPT_FORCE_AUDIO)) {
2873 if (set_fax_t38_caps(chan, details)) {
2874 ast_string_field_set(details, error, "T38_NEG_ERROR");
2875 ast_string_field_set(details, resultstr, "error negotiating T.38");
2876 set_channel_variables(chan, details);
2877 fax_session_release(s, token);
2878 return -1;
2879 }
2880 } else {
2881 details->caps |= AST_FAX_TECH_AUDIO;
2882 }
2883
2884 if (!ast_test_flag(&opts, OPT_FORCE_AUDIO) && (details->caps & AST_FAX_TECH_T38)) {
2885 if (sendfax_t38_init(chan, details)) {
2886 ast_string_field_set(details, error, "T38_NEG_ERROR");
2887 ast_string_field_set(details, resultstr, "error negotiating T.38");
2888 set_channel_variables(chan, details);
2889 fax_session_release(s, token);
2890 ast_log(LOG_ERROR, "error initializing channel '%s' in T.38 mode\n", ast_channel_name(chan));
2891 return -1;
2892 }
2893 } else {
2894 details->option.send_cng = 1;
2895 }
2896
2897 if ((channel_alive = generic_fax_exec(chan, details, s, token)) < 0) {
2898 ast_atomic_fetchadd_int(&faxregistry.fax_failures, 1);
2899 }
2900
2902 if (disable_t38(chan)) {
2903 ast_debug(1, "error disabling T.38 mode on %s\n", ast_channel_name(chan));
2904 }
2905 }
2906
2907 if (!(filenames = generate_filenames_string(details, "FileName: ", "\r\n"))) {
2908 ast_log(LOG_ERROR, "Error generating SendFAX manager event\n");
2909 return (!channel_alive) ? -1 : 0;
2910 }
2911
2912 /* send out the AMI completion event */
2913 if (report_send_fax_status(chan, details)) {
2914 ast_log(AST_LOG_ERROR, "Error publishing SendFAX status message\n");
2915 }
2916
2917 /* If the channel hungup return -1; otherwise, return 0 to continue in the dialplan */
2918 return (!channel_alive) ? -1 : 0;
2919}
char * strsep(char **str, const char *delims)
#define R_OK
#define F_OK
static int sendfax_t38_init(struct ast_channel *chan, struct ast_fax_session_details *details)
Definition res_fax.c:2384
static int report_send_fax_status(struct ast_channel *chan, struct ast_fax_session_details *details)
Report on the status of a completed fax send attempt.
Definition res_fax.c:2628

References ao2_cleanup, app_sendfax, args, ast_answer(), AST_APP_ARG, ast_app_parse_options(), ast_atomic_fetchadd_int(), ast_calloc, ast_channel_get_t38_state(), ast_channel_name(), ast_debug, AST_DECLARE_APP_ARGS, ast_fax_modem_to_str(), AST_FAX_OPTFLAG_TRUE, AST_FAX_TECH_AUDIO, AST_FAX_TECH_MULTI_DOC, AST_FAX_TECH_SEND, AST_FAX_TECH_T38, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log, AST_LOG_ERROR, AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verb, c, check_modem_rate(), disable_t38(), error(), F_OK, fax_exec_options, fax_session_release(), fax_session_reserve(), faxregistry, ast_fax_document::filename, find_or_create_details(), generate_filenames_string(), generic_fax_exec(), global_fax_debug, LOG_ERROR, LOG_WARNING, NULL, OPT_ALLOWAUDIO, OPT_CALLEDMODE, OPT_CALLERMODE, OPT_DEBUG, OPT_FORCE_AUDIO, OPT_REQUEST_T38, OPT_STATUS, options, pbx_builtin_setvar_helper(), R_OK, RAII_VAR, report_send_fax_status(), result, sendfax_t38_init(), set_channel_variables(), set_fax_t38_caps(), strsep(), T38_STATE_NEGOTIATED, T38_STATE_REJECTED, and T38_STATE_UNAVAILABLE.

Referenced by load_module().

◆ sendfax_t38_init()

static int sendfax_t38_init ( struct ast_channel *  chan,
struct ast_fax_session_details *  details 
)
static

Definition at line 2384 of file res_fax.c.

2385{
2386 int timeout_ms;
2387 struct ast_frame *frame = NULL;
2388 struct ast_control_t38_parameters t38_parameters;
2389 struct timeval start;
2390 int ms;
2391
2392 /* send CNG tone while listening for the receiver to initiate a switch
2393 * to T.38 mode; if they do, stop sending the CNG tone and proceed with
2394 * the switch.
2395 *
2396 * 10500 is enough time for 3 CNG tones
2397 */
2398 timeout_ms = 10500;
2399
2400 /* don't send any audio if we've already received a T.38 reinvite */
2402 if (ast_playtones_start(chan, 1024, "!1100/500,!0/3000,!1100/500,!0/3000,!1100/500,!0/3000", 1)) {
2403 ast_log(LOG_ERROR, "error generating CNG tone on %s\n", ast_channel_name(chan));
2404 return -1;
2405 }
2406 }
2407
2408 start = ast_tvnow();
2409 while ((ms = ast_remaining_ms(start, timeout_ms))) {
2410 int break_loop = 0;
2411 ms = ast_waitfor(chan, ms);
2412
2413 if (ms < 0) {
2414 ast_log(LOG_ERROR, "error while generating CNG tone on %s\n", ast_channel_name(chan));
2415 ast_playtones_stop(chan);
2416 return -1;
2417 }
2418
2419 if (ms == 0) { /* all done, nothing happened */
2420 break;
2421 }
2422
2423 if (!(frame = ast_read(chan))) {
2424 ast_log(LOG_ERROR, "error reading frame while generating CNG tone on %s\n", ast_channel_name(chan));
2425 ast_playtones_stop(chan);
2426 return -1;
2427 }
2428
2429 if ((frame->frametype == AST_FRAME_CONTROL) &&
2431 (frame->datalen == sizeof(t38_parameters))) {
2432 struct ast_control_t38_parameters *parameters = frame->data.ptr;
2433
2434 switch (parameters->request_response) {
2436 /* the other end has requested a switch to T.38, so reply that we are willing, if we can
2437 * do T.38 as well
2438 */
2439 t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
2440 t38_parameters.request_response = (details->caps & AST_FAX_TECH_T38) ? AST_T38_NEGOTIATED : AST_T38_REFUSED;
2441 ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters));
2442 ast_playtones_stop(chan);
2443 break;
2444 case AST_T38_NEGOTIATED:
2445 ast_debug(1, "Negotiated T.38 for send on %s\n", ast_channel_name(chan));
2446 t38_parameters_ast_to_fax(&details->their_t38_parameters, parameters);
2447 details->caps &= ~AST_FAX_TECH_AUDIO;
2448 report_fax_status(chan, details, "T.38 Negotiated");
2449 break_loop = 1;
2450 break;
2451 default:
2452 break;
2453 }
2454 }
2455 ast_frfree(frame);
2456 if (break_loop) {
2457 break;
2458 }
2459 }
2460
2461 ast_playtones_stop(chan);
2462
2464 return 0;
2465 }
2466
2467 /* T.38 negotiation did not happen, initiate a switch if requested */
2468 if (details->option.request_t38 == AST_FAX_OPTFLAG_TRUE) {
2469 ast_debug(1, "Negotiating T.38 for send on %s\n", ast_channel_name(chan));
2470
2471 /* wait up to five seconds for negotiation to complete */
2472 timeout_ms = 5000;
2473
2474 /* set parameters based on the session's parameters */
2475 t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
2476 t38_parameters.request_response = AST_T38_REQUEST_NEGOTIATE;
2477 if ((ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters)) != 0)) {
2478 return -1;
2479 }
2480
2481 start = ast_tvnow();
2482 while ((ms = ast_remaining_ms(start, timeout_ms))) {
2483 int break_loop = 0;
2484
2485 ms = ast_waitfor(chan, ms);
2486 if (ms < 0) {
2487 ast_log(LOG_WARNING, "error on '%s' while waiting for T.38 negotiation.\n", ast_channel_name(chan));
2488 return -1;
2489 }
2490 if (ms == 0) { /* all done, nothing happened */
2491 ast_log(LOG_WARNING, "channel '%s' timed-out during the T.38 negotiation.\n", ast_channel_name(chan));
2492 details->caps &= ~AST_FAX_TECH_T38;
2493 break;
2494 }
2495
2496 if (!(frame = ast_read(chan))) {
2497 ast_log(LOG_WARNING, "error on '%s' while waiting for T.38 negotiation.\n", ast_channel_name(chan));
2498 return -1;
2499 }
2500
2501 if ((frame->frametype == AST_FRAME_CONTROL) &&
2503 (frame->datalen == sizeof(t38_parameters))) {
2504 struct ast_control_t38_parameters *parameters = frame->data.ptr;
2505
2506 switch (parameters->request_response) {
2508 t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
2509 t38_parameters.request_response = AST_T38_NEGOTIATED;
2510 ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters));
2511 break;
2512 case AST_T38_NEGOTIATED:
2513 ast_debug(1, "Negotiated T.38 for receive on %s\n", ast_channel_name(chan));
2514 t38_parameters_ast_to_fax(&details->their_t38_parameters, parameters);
2515 details->caps &= ~AST_FAX_TECH_AUDIO;
2516 report_fax_status(chan, details, "T.38 Negotiated");
2517 break_loop = 1;
2518 break;
2519 case AST_T38_REFUSED:
2520 ast_log(LOG_WARNING, "channel '%s' refused to negotiate T.38\n", ast_channel_name(chan));
2521 details->caps &= ~AST_FAX_TECH_T38;
2522 break_loop = 1;
2523 break;
2524 default:
2525 ast_log(LOG_ERROR, "channel '%s' failed to negotiate T.38\n", ast_channel_name(chan));
2526 details->caps &= ~AST_FAX_TECH_T38;
2527 break_loop = 1;
2528 break;
2529 }
2530 }
2531 ast_frfree(frame);
2532 if (break_loop) {
2533 break;
2534 }
2535 }
2536
2537 /* if T.38 was negotiated, we are done initializing */
2539 return 0;
2540 }
2541
2542 /* send one more CNG tone to get audio going again for some
2543 * carriers if we are going to fall back to audio mode */
2544 if (details->option.allow_audio == AST_FAX_OPTFLAG_TRUE) {
2545 if (ast_playtones_start(chan, 1024, "!1100/500,!0/3000", 1)) {
2546 ast_log(LOG_ERROR, "error generating second CNG tone on %s\n", ast_channel_name(chan));
2547 return -1;
2548 }
2549
2550 timeout_ms = 3500;
2551 start = ast_tvnow();
2552 while ((ms = ast_remaining_ms(start, timeout_ms))) {
2553 int break_loop = 0;
2554
2555 ms = ast_waitfor(chan, ms);
2556 if (ms < 0) {
2557 ast_log(LOG_ERROR, "error while generating second CNG tone on %s\n", ast_channel_name(chan));
2558 ast_playtones_stop(chan);
2559 return -1;
2560 }
2561 if (ms == 0) { /* all done, nothing happened */
2562 break;
2563 }
2564
2565 if (!(frame = ast_read(chan))) {
2566 ast_log(LOG_ERROR, "error reading frame while generating second CNG tone on %s\n", ast_channel_name(chan));
2567 ast_playtones_stop(chan);
2568 return -1;
2569 }
2570
2571 if ((frame->frametype == AST_FRAME_CONTROL) &&
2573 (frame->datalen == sizeof(t38_parameters))) {
2574 struct ast_control_t38_parameters *parameters = frame->data.ptr;
2575
2576 switch (parameters->request_response) {
2578 /* the other end has requested a switch to T.38, so reply that we are willing, if we can
2579 * do T.38 as well
2580 */
2581 t38_parameters_fax_to_ast(&t38_parameters, &details->our_t38_parameters);
2582 t38_parameters.request_response = (details->caps & AST_FAX_TECH_T38) ? AST_T38_NEGOTIATED : AST_T38_REFUSED;
2583 ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, &t38_parameters, sizeof(t38_parameters));
2584 ast_playtones_stop(chan);
2585 break;
2586 case AST_T38_NEGOTIATED:
2587 ast_debug(1, "Negotiated T.38 for send on %s\n", ast_channel_name(chan));
2588 t38_parameters_ast_to_fax(&details->their_t38_parameters, parameters);
2589 details->caps &= ~AST_FAX_TECH_AUDIO;
2590 report_fax_status(chan, details, "T.38 Negotiated");
2591 break_loop = 1;
2592 break;
2593 default:
2594 break;
2595 }
2596 }
2597 ast_frfree(frame);
2598 if (break_loop) {
2599 break;
2600 }
2601 }
2602
2603 ast_playtones_stop(chan);
2604
2605 /* if T.38 was negotiated, we are done initializing */
2607 return 0;
2608 }
2609 }
2610 }
2611
2612 /* if we made it here, then T.38 failed, check the 'f' flag */
2613 if (details->option.allow_audio == AST_FAX_OPTFLAG_FALSE) {
2614 ast_log(LOG_WARNING, "Audio FAX not allowed on channel '%s' and T.38 negotiation failed; aborting.\n", ast_channel_name(chan));
2615 return -1;
2616 }
2617
2618 /* ok, audio fallback is allowed */
2619 details->caps |= AST_FAX_TECH_AUDIO;
2620
2621 return 0;
2622}

References ast_fax_session_details::allow_audio, ast_channel_get_t38_state(), ast_channel_name(), AST_CONTROL_T38_PARAMETERS, ast_debug, AST_FAX_OPTFLAG_FALSE, AST_FAX_OPTFLAG_TRUE, AST_FAX_TECH_AUDIO, AST_FAX_TECH_T38, AST_FRAME_CONTROL, ast_frfree, ast_indicate_data(), ast_log, ast_playtones_start(), ast_playtones_stop(), ast_read(), ast_remaining_ms(), AST_T38_NEGOTIATED, AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, ast_tvnow(), ast_waitfor(), ast_fax_session_details::caps, ast_frame::data, ast_frame::datalen, ast_frame::frametype, ast_frame_subclass::integer, LOG_ERROR, LOG_WARNING, NULL, ast_fax_session_details::option, ast_fax_session_details::our_t38_parameters, ast_frame::ptr, report_fax_status(), ast_control_t38_parameters::request_response, ast_fax_session_details::request_t38, ast_frame::subclass, t38_parameters_ast_to_fax(), t38_parameters_fax_to_ast(), T38_STATE_NEGOTIATED, T38_STATE_NEGOTIATING, and ast_fax_session_details::their_t38_parameters.

Referenced by sendfax_exec().

◆ session_cmp_cb()

static int session_cmp_cb ( void *  obj,
void *  arg,
int  flags 
)
static

compare callback for ao2

Definition at line 4063 of file res_fax.c.

4064{
4065 struct ast_fax_session *lhs = obj, *rhs = arg;
4066
4067 return (lhs->id == rhs->id) ? CMP_MATCH | CMP_STOP : 0;
4068}
@ CMP_MATCH
Definition astobj2.h:1027
@ CMP_STOP
Definition astobj2.h:1028

References CMP_MATCH, CMP_STOP, and ast_fax_session::id.

Referenced by load_module().

◆ session_details_new()

static struct ast_fax_session_details * session_details_new ( void  )
static

create a FAX session details structure

Definition at line 797 of file res_fax.c.

798{
800 struct fax_options options;
801
802 if (!(d = ao2_alloc(sizeof(*d), destroy_session_details))) {
803 return NULL;
804 }
805
806 if (ast_string_field_init(d, 512)) {
807 ao2_ref(d, -1);
808 return NULL;
809 }
810
812
813 AST_LIST_HEAD_INIT_NOLOCK(&d->documents);
814
815 /* These options need to be set to the configured default and may be overridden by
816 * SendFAX, ReceiveFAX, or FAXOPT */
817 d->option.request_t38 = AST_FAX_OPTFLAG_FALSE;
818 d->option.send_cng = AST_FAX_OPTFLAG_FALSE;
819 d->option.send_ced = AST_FAX_OPTFLAG_FALSE;
820 d->option.ecm = options.ecm;
821 d->option.statusevents = options.statusevents;
822 d->modems = options.modems;
823 d->minrate = options.minrate;
824 d->maxrate = options.maxrate;
825 d->t38timeout = options.t38timeout;
826 d->gateway_id = -1;
827 d->faxdetect_id = -1;
828 d->gateway_timeout = 0;
829 d->negotiate_both = 0;
830
831 return d;
832}
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
static void destroy_session_details(void *details)
destroy a FAX session details structure
Definition res_fax.c:785
#define ast_string_field_init(x, size)
Initialize a field pool and fields.

References ao2_alloc, ao2_ref, AST_FAX_OPTFLAG_FALSE, AST_LIST_HEAD_INIT_NOLOCK, ast_string_field_init, d, destroy_session_details(), get_general_options(), NULL, and options.

Referenced by fax_v21_session_new(), and find_or_create_details().

◆ session_hash_cb()

static int session_hash_cb ( const void *  obj,
const int  flags 
)
static

hash callback for ao2

Definition at line 4055 of file res_fax.c.

4056{
4057 const struct ast_fax_session *s = obj;
4058
4059 return s->id;
4060}

References ast_fax_session::id.

Referenced by load_module().

◆ set_channel_variables()

static void set_channel_variables ( struct ast_channel *  chan,
struct ast_fax_session_details *  details 
)
static

Set fax related channel variables.

Definition at line 1548 of file res_fax.c.

1549{
1550 char buf[10];
1551
1552 pbx_builtin_setvar_helper(chan, "FAXSTATUS", S_OR(details->result, NULL));
1553 pbx_builtin_setvar_helper(chan, "FAXERROR", S_OR(details->error, NULL));
1554 pbx_builtin_setvar_helper(chan, "FAXSTATUSSTRING", S_OR(details->resultstr, NULL));
1555 pbx_builtin_setvar_helper(chan, "REMOTESTATIONID", AST_JSON_UTF8_VALIDATE(details->remotestationid));
1556 pbx_builtin_setvar_helper(chan, "LOCALSTATIONID", AST_JSON_UTF8_VALIDATE(details->localstationid));
1557 pbx_builtin_setvar_helper(chan, "FAXBITRATE", S_OR(details->transfer_rate, NULL));
1558 pbx_builtin_setvar_helper(chan, "FAXRESOLUTION", S_OR(details->resolution, NULL));
1559
1560 if (details->is_t38_negotiated) {
1561 pbx_builtin_setvar_helper(chan, "FAXMODE", "T38");
1562 } else {
1563 pbx_builtin_setvar_helper(chan, "FAXMODE", "audio");
1564 }
1565
1566 snprintf(buf, sizeof(buf), "%u", details->pages_transferred);
1567 pbx_builtin_setvar_helper(chan, "FAXPAGES", buf);
1568}

References AST_JSON_UTF8_VALIDATE, buf, ast_fax_session_details::error, ast_fax_session_details::is_t38_negotiated, ast_fax_session_details::localstationid, NULL, ast_fax_session_details::pages_transferred, pbx_builtin_setvar_helper(), ast_fax_session_details::remotestationid, ast_fax_session_details::resolution, ast_fax_session_details::result, ast_fax_session_details::resultstr, S_OR, and ast_fax_session_details::transfer_rate.

Referenced by fax_gateway_attach(), fax_gateway_detect_t38(), fax_gateway_framehook(), fax_gateway_start(), generic_fax_exec(), receivefax_exec(), and sendfax_exec().

◆ set_config()

static int set_config ( int  reload)
static

configure res_fax

Definition at line 4550 of file res_fax.c.

4551{
4552 struct ast_config *cfg;
4553 struct ast_variable *v;
4554 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
4555 char modems[128] = "";
4556 struct fax_options options;
4557 int res = 0;
4558
4560
4561 /* When we're not reloading, we have to be certain to set the general options
4562 * to the defaults in case config loading goes wrong at some point. On a reload,
4563 * the general options need to stay the same as what they were prior to the
4564 * reload rather than being reset to the defaults.
4565 */
4566 if (!reload) {
4568 }
4569
4570 /* read configuration */
4571 if (!(cfg = ast_config_load2(config, "res_fax", config_flags))) {
4572 ast_log(LOG_NOTICE, "Configuration file '%s' not found, %s options.\n",
4573 config, reload ? "not changing" : "using default");
4574 return 0;
4575 }
4576
4577 if (cfg == CONFIG_STATUS_FILEINVALID) {
4578 ast_log(LOG_NOTICE, "Configuration file '%s' is invalid, %s options.\n",
4579 config, reload ? "not changing" : "using default");
4580 return 0;
4581 }
4582
4583 if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
4584 return 0;
4585 }
4586
4587 if (reload) {
4589 }
4590
4591 /* create configuration */
4592 for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
4593 int rate;
4594
4595 if (!strcasecmp(v->name, "minrate")) {
4596 ast_debug(3, "reading minrate '%s' from configuration file\n", v->value);
4597 if ((rate = fax_rate_str_to_int(v->value)) == 0) {
4598 res = -1;
4599 goto end;
4600 }
4601 options.minrate = rate;
4602 } else if (!strcasecmp(v->name, "maxrate")) {
4603 ast_debug(3, "reading maxrate '%s' from configuration file\n", v->value);
4604 if ((rate = fax_rate_str_to_int(v->value)) == 0) {
4605 res = -1;
4606 goto end;
4607 }
4608 options.maxrate = rate;
4609 } else if (!strcasecmp(v->name, "statusevents")) {
4610 ast_debug(3, "reading statusevents '%s' from configuration file\n", v->value);
4611 options.statusevents = ast_true(v->value);
4612 } else if (!strcasecmp(v->name, "ecm")) {
4613 ast_debug(3, "reading ecm '%s' from configuration file\n", v->value);
4614 options.ecm = ast_true(v->value);
4615 } else if ((!strcasecmp(v->name, "modem")) || (!strcasecmp(v->name, "modems"))) {
4616 options.modems = 0;
4617 update_modem_bits(&options.modems, v->value);
4618 } else if (!strcasecmp(v->name, "t38timeout")) {
4619 if (set_t38timeout(v->value, &options.t38timeout)) {
4620 res = -1;
4621 goto end;
4622 }
4623 }
4624 }
4625
4626 if (options.maxrate < options.minrate) {
4627 ast_log(LOG_ERROR, "maxrate %u is less than minrate %u\n", options.maxrate, options.minrate);
4628 res = -1;
4629 goto end;
4630 }
4631
4632 if (check_modem_rate(options.modems, options.minrate)) {
4633 ast_fax_modem_to_str(options.modems, modems, sizeof(modems));
4634 ast_log(LOG_ERROR, "'modems' setting '%s' is incompatible with 'minrate' setting %u\n", modems, options.minrate);
4635 res = -1;
4636 goto end;
4637 }
4638
4639 if (check_modem_rate(options.modems, options.maxrate)) {
4640 ast_fax_modem_to_str(options.modems, modems, sizeof(modems));
4641 ast_log(LOG_ERROR, "'modems' setting '%s' is incompatible with 'maxrate' setting %u\n", modems, options.maxrate);
4642 res = -1;
4643 goto end;
4644 }
4645
4647
4648end:
4649 ast_config_destroy(cfg);
4650 return res;
4651}
char * end
Definition eagi_proxy.c:73
@ CONFIG_FLAG_FILEUNCHANGED
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition extconf.c:1287
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition extconf.c:1213
static int reload(void)
static void set_general_options(const struct fax_options *options)
Definition res_fax.c:4518
static const struct fax_options default_options
Definition res_fax.c:640
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next

References ast_config_destroy(), ast_config_load2(), ast_debug, ast_fax_modem_to_str(), ast_log, ast_true(), ast_variable_browse(), check_modem_rate(), config, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, default_options, end, fax_rate_str_to_int(), LOG_ERROR, LOG_NOTICE, fax_options::modems, ast_variable::name, ast_variable::next, options, reload(), set_general_options(), set_t38timeout(), update_modem_bits(), and ast_variable::value.

Referenced by load_module(), and reload_module().

◆ set_fax_t38_caps()

static int set_fax_t38_caps ( struct ast_channel *  chan,
struct ast_fax_session_details *  details 
)
static

Definition at line 1592 of file res_fax.c.

1593{
1594 switch (ast_channel_get_t38_state(chan)) {
1595 case T38_STATE_UNKNOWN:
1596 details->caps |= AST_FAX_TECH_T38;
1597 break;
1598 case T38_STATE_REJECTED:
1600 details->caps |= AST_FAX_TECH_AUDIO;
1601 break;
1603 /* already in T.38 mode? This should not happen. */
1604 case T38_STATE_NEGOTIATING: {
1605 /* the other end already sent us a T.38 reinvite, so we need to prod the channel
1606 * driver into resending their parameters to us if it supports doing so... if
1607 * not, we can't proceed, because we can't create a proper reply without them.
1608 * if it does work, the channel driver will send an AST_CONTROL_T38_PARAMETERS
1609 * with a request of AST_T38_REQUEST_NEGOTIATE, which will be read by the function
1610 * that gets called after this one completes
1611 */
1613 if (ast_indicate_data(chan, AST_CONTROL_T38_PARAMETERS, &parameters, sizeof(parameters)) != AST_T38_REQUEST_PARMS) {
1614 ast_log(LOG_ERROR, "channel '%s' is in an unsupported T.38 negotiation state, cannot continue.\n", ast_channel_name(chan));
1615 return -1;
1616 }
1617 details->caps |= AST_FAX_TECH_T38;
1618 break;
1619 }
1620 default:
1621 ast_log(LOG_ERROR, "channel '%s' is in an unsupported T.38 negotiation state, cannot continue.\n", ast_channel_name(chan));
1622 return -1;
1623 }
1624
1625 return 0;
1626}
@ AST_T38_REQUEST_PARMS

References ast_channel_get_t38_state(), ast_channel_name(), AST_CONTROL_T38_PARAMETERS, AST_FAX_TECH_AUDIO, AST_FAX_TECH_T38, ast_indicate_data(), ast_log, AST_T38_REQUEST_PARMS, ast_fax_session_details::caps, LOG_ERROR, ast_control_t38_parameters::request_response, T38_STATE_NEGOTIATED, T38_STATE_NEGOTIATING, T38_STATE_REJECTED, T38_STATE_UNAVAILABLE, and T38_STATE_UNKNOWN.

Referenced by receivefax_exec(), and sendfax_exec().

◆ set_general_options()

static void set_general_options ( const struct fax_options *  options)
static

Definition at line 4518 of file res_fax.c.

4519{
4523}
#define ast_rwlock_wrlock(a)
Definition lock.h:243

References ast_rwlock_unlock, ast_rwlock_wrlock, general_options, options, and options_lock.

Referenced by set_config().

◆ set_t38timeout()

static int set_t38timeout ( const char *  value,
unsigned int *  t38timeout 
)
static

Definition at line 4532 of file res_fax.c.

4533{
4534 unsigned int timeout;
4535
4536 if (sscanf(value, "%u", &timeout) != 1) {
4537 ast_log(LOG_ERROR, "Unable to get timeout from '%s'\n", value);
4538 return -1;
4539 } else if (timeout) {
4540 *t38timeout = timeout;
4541 } else {
4542 ast_log(LOG_ERROR, "T.38 negotiation timeout must be non-zero\n");
4543 return -1;
4544 }
4545
4546 return 0;
4547}

References ast_log, LOG_ERROR, and value.

Referenced by acf_faxopt_write(), and set_config().

◆ t38_parameters_ast_to_fax()

static void t38_parameters_ast_to_fax ( struct ast_fax_t38_parameters *  dst,
const struct ast_control_t38_parameters *  src 
)
static

Definition at line 841 of file res_fax.c.

842{
843 dst->version = src->version;
844 dst->max_ifp = src->max_ifp;
845 dst->rate = src->rate;
850}
enum ast_control_t38_rate rate
enum ast_control_t38_rate_management rate_management
unsigned int transcoding_jbig
Definition res_fax.h:99
enum ast_control_t38_rate rate
Definition res_fax.h:95
unsigned int version
Definition res_fax.h:93
unsigned int max_ifp
Definition res_fax.h:94
unsigned int transcoding_mmr
Definition res_fax.h:98
enum ast_control_t38_rate_management rate_management
Definition res_fax.h:96
unsigned int fill_bit_removal
Definition res_fax.h:97

References ast_control_t38_parameters::fill_bit_removal, ast_fax_t38_parameters::fill_bit_removal, ast_control_t38_parameters::max_ifp, ast_fax_t38_parameters::max_ifp, ast_control_t38_parameters::rate, ast_fax_t38_parameters::rate, ast_control_t38_parameters::rate_management, ast_fax_t38_parameters::rate_management, ast_control_t38_parameters::transcoding_jbig, ast_fax_t38_parameters::transcoding_jbig, ast_control_t38_parameters::transcoding_mmr, ast_fax_t38_parameters::transcoding_mmr, ast_control_t38_parameters::version, and ast_fax_t38_parameters::version.

Referenced by fax_gateway_detect_t38(), find_or_create_details(), generic_fax_exec(), receivefax_t38_init(), and sendfax_t38_init().

◆ t38_parameters_fax_to_ast()

static void t38_parameters_fax_to_ast ( struct ast_control_t38_parameters *  dst,
const struct ast_fax_t38_parameters *  src 
)
static

◆ unload_module()

static int unload_module ( void  )
static

unload res_fax

Definition at line 4877 of file res_fax.c.

4878{
4880
4882 ast_log(LOG_WARNING, "failed to unregister function '%s'\n", acf_faxopt.name);
4883 }
4884
4886 ast_log(LOG_WARNING, "failed to unregister '%s'\n", app_sendfax);
4887 }
4888
4890 ast_log(LOG_WARNING, "failed to unregister '%s'\n", app_receivefax);
4891 }
4892
4893 ast_manager_unregister("FAXSessions");
4894 ast_manager_unregister("FAXSession");
4895 ast_manager_unregister("FAXStats");
4896
4897 if (fax_logger_level != -1) {
4899 }
4900
4901 ao2_ref(faxregistry.container, -1);
4902
4903 return 0;
4904}
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408
void ast_logger_unregister_level(const char *name)
Unregister a previously registered logger level.
Definition logger.c:2976
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
const char * name
Definition pbx.h:119

References acf_faxopt, ao2_ref, app_receivefax, app_sendfax, ARRAY_LEN, ast_cli_unregister_multiple(), ast_custom_function_unregister(), ast_log, ast_logger_unregister_level(), ast_manager_unregister(), ast_unregister_application(), fax_cli, fax_logger_level, faxregistry, LOG_WARNING, and ast_custom_function::name.

◆ update_modem_bits()

static int update_modem_bits ( enum ast_fax_modems *  bits,
const char *  value 
)
static

Definition at line 913 of file res_fax.c.

914{
915 char *m[5], *tok, *v = (char *) value, *rest;
916 int i = 0, j;
917
918 if (!strchr(v, ',')) {
919 m[i++] = v;
920 m[i] = NULL;
921 } else {
922 tok = strtok_r(v, ", ", &rest);
923 while (tok && i < ARRAY_LEN(m) - 1) {
924 m[i++] = tok;
925 tok = strtok_r(NULL, ", ", &rest);
926 }
927 m[i] = NULL;
928 }
929
930 *bits = 0;
931 for (j = 0; j < i; j++) {
932 if (!strcasecmp(m[j], "v17")) {
933 *bits |= AST_FAX_MODEM_V17;
934 } else if (!strcasecmp(m[j], "v27")) {
935 *bits |= AST_FAX_MODEM_V27TER;
936 } else if (!strcasecmp(m[j], "v29")) {
937 *bits |= AST_FAX_MODEM_V29;
938 } else if (!strcasecmp(m[j], "v34")) {
939 *bits |= AST_FAX_MODEM_V34;
940 } else {
941 ast_log(LOG_WARNING, "ignoring invalid modem setting: '%s', valid options {v17 | v27 | v29 | v34}\n", m[j]);
942 }
943 }
944 return 0;
945}

References ARRAY_LEN, AST_FAX_MODEM_V17, AST_FAX_MODEM_V27TER, AST_FAX_MODEM_V29, AST_FAX_MODEM_V34, ast_log, LOG_WARNING, NULL, and value.

Referenced by acf_faxopt_write(), and set_config().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Generic FAX Applications" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_APP_DEPEND, }
static

Definition at line 4995 of file res_fax.c.

◆ acf_faxopt

struct ast_custom_function acf_faxopt
static
Initial value:
= {
.name = "FAXOPT",
.read = acf_faxopt_read,
.write = acf_faxopt_write,
}
static int acf_faxopt_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
FAXOPT write function modifies the contents of a FAX option.
Definition res_fax.c:4729
static int acf_faxopt_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
FAXOPT read function returns the contents of a FAX option.
Definition res_fax.c:4654

FAXOPT dialplan function.

Definition at line 4870 of file res_fax.c.

4870 {
4871 .name = "FAXOPT",
4872 .read = acf_faxopt_read,
4873 .write = acf_faxopt_write,
4874};

Referenced by load_module(), and unload_module().

◆ active_sessions

int active_sessions

The number of active FAX sessions

Definition at line 599 of file res_fax.c.

◆ app_receivefax

const char app_receivefax[] = "ReceiveFAX"
static

Definition at line 529 of file res_fax.c.

Referenced by load_module(), receivefax_exec(), and unload_module().

◆ app_sendfax

const char app_sendfax[] = "SendFAX"
static

Definition at line 530 of file res_fax.c.

Referenced by load_module(), sendfax_exec(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 4995 of file res_fax.c.

◆ config

const char* config = "res_fax.conf"
static

Definition at line 654 of file res_fax.c.

Referenced by load_module(), and set_config().

◆ container

struct ao2_container* container

active sessions are astobj2 objects

Definition at line 603 of file res_fax.c.

Referenced by __container_unlink_node_debug(), aeap_tab_complete_name(), ast_aeap_client_configs_get(), ast_sip_cli_traverse_objects(), AST_TEST_DEFINE(), bridge_profile_find(), cli_aor_get_container(), cli_aor_iterate(), cli_contact_iterate(), cli_contact_retrieve_by_id(), cli_endpoint_get_container(), cli_eprofile_show_all(), cli_get_container(), cli_get_container(), cli_get_container(), cli_get_container(), cli_iterate(), cli_iterator(), cli_iterator(), cli_iterator(), cli_profile_show_all(), cli_tn_show_all(), cli_unid_iterate(), client_config_show_all(), complete_app(), complete_session(), complete_show_sorcery_object(), complete_sorcery_object(), config_object_tab_complete_name(), gather_contacts_for_aor(), get_publishes_and_update_state(), handle_cli_ao2_string_hash(), handle_cli_ao2_string_list(), handle_cli_ao2_string_rbtree(), handle_export_primitives(), has_mwi_subscription(), insert_test_duplicates(), insert_test_vector(), load_module(), load_module(), menu_find(), named_acl_find(), named_item_find(), notify_option_find(), populate_transport_states(), proxy_dtor(), registrar_add_non_permanent(), registrar_add_unreachable(), speech_observer_loaded(), test_ao2_callback_traversal(), test_ao2_iteration(), test_expected_duplicates(), test_item_find(), test_make_nonsorted(), test_make_sorted(), unload_module(), user_profile_find(), var_list_from_loc_info(), var_list_from_node(), and xmpp_client_create_buddy().

◆ default_options

const struct fax_options default_options
static

Definition at line 640 of file res_fax.c.

640 {
641 .minrate = RES_FAX_MINRATE,
642 .maxrate = RES_FAX_MAXRATE,
643 .statusevents = RES_FAX_STATUSEVENTS,
644 .modems = RES_FAX_MODEM,
646 .t38timeout = RES_FAX_T38TIMEOUT,
647};
#define RES_FAX_MAXRATE
Definition res_fax.c:624
#define RES_FAX_MODEM
Definition res_fax.c:626
#define RES_FAX_MINRATE
Definition res_fax.c:623
#define RES_FAX_STATUSEVENTS
Definition res_fax.c:625
#define RES_FAX_T38TIMEOUT
Definition res_fax.c:627

Referenced by set_config().

◆ fax_cli

struct ast_cli_entry fax_cli[]
static

Definition at line 4508 of file res_fax.c.

4508 {
4509 AST_CLI_DEFINE(cli_fax_show_version, "Show versions of FAX For Asterisk components"),
4510 AST_CLI_DEFINE(cli_fax_set_debug, "Enable/Disable FAX debugging on new FAX sessions"),
4511 AST_CLI_DEFINE(cli_fax_show_capabilities, "Show the capabilities of the registered FAX technology modules"),
4512 AST_CLI_DEFINE(cli_fax_show_settings, "Show the global settings and defaults of both the FAX core and technology modules"),
4513 AST_CLI_DEFINE(cli_fax_show_session, "Show the status of the named FAX sessions"),
4514 AST_CLI_DEFINE(cli_fax_show_sessions, "Show the current FAX sessions"),
4515 AST_CLI_DEFINE(cli_fax_show_stats, "Summarize FAX session history"),
4516};
#define AST_CLI_DEFINE(fn, txt,...)
Definition cli.h:197
static char * cli_fax_show_session(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
display details of a specified fax session
Definition res_fax.c:4235
static char * cli_fax_show_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
display fax stats
Definition res_fax.c:4309
static char * cli_fax_show_capabilities(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
display registered FAX capabilities
Definition res_fax.c:4166
static char * cli_fax_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
display global defaults and settings
Definition res_fax.c:4196
static char * cli_fax_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
enable FAX debugging
Definition res_fax.c:4131
static char * cli_fax_show_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition res_fax.c:4099
static char * cli_fax_show_sessions(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
display fax sessions
Definition res_fax.c:4401

Referenced by load_module(), and unload_module().

◆ fax_complete

int fax_complete

Number of successful FAX transmissions

Definition at line 609 of file res_fax.c.

◆ fax_datastore

const struct ast_datastore_info fax_datastore
static
Initial value:
= {
.type = "res_fax",
.destroy = destroy_callback,
.chan_fixup = fixup_callback,
}
static void fixup_callback(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
Copies fax detection and gateway framehooks during masquerades.
Definition res_fax.c:737
static void destroy_callback(void *data)
Definition res_fax.c:711

Definition at line 720 of file res_fax.c.

720 {
721 .type = "res_fax",
722 .destroy = destroy_callback,
723 .chan_fixup = fixup_callback,
724};

Referenced by find_details(), find_or_create_details(), and fixup_callback().

◆ fax_exec_options

const struct ast_app_option fax_exec_options[128] = { [ 'a' ] = { .flag = OPT_CALLEDMODE }, [ 'c' ] = { .flag = OPT_CALLERMODE }, [ 'd' ] = { .flag = OPT_DEBUG }, [ 'f' ] = { .flag = OPT_ALLOWAUDIO }, [ 'F' ] = { .flag = OPT_FORCE_AUDIO }, [ 's' ] = { .flag = OPT_STATUS }, [ 'z' ] = { .flag = OPT_REQUEST_T38 }, }
static

Definition at line 676 of file res_fax.c.

Referenced by receivefax_exec(), and sendfax_exec().

◆ fax_failures

int fax_failures

Number of failed FAX transmissions

Definition at line 611 of file res_fax.c.

◆ fax_logger_level

int fax_logger_level = -1
static

Definition at line 588 of file res_fax.c.

Referenced by ast_fax_log(), load_module(), and unload_module().

◆ fax_rx_attempts

int fax_rx_attempts

Total number of Rx FAX attempts

Definition at line 607 of file res_fax.c.

◆ fax_tx_attempts

int fax_tx_attempts

Total number of Tx FAX attempts

Definition at line 605 of file res_fax.c.

◆ faxmodules

◆ [struct]

struct { ... } faxregistry

◆ general_options

struct fax_options general_options
static

Definition at line 638 of file res_fax.c.

Referenced by get_general_options(), and set_general_options().

◆ global_fax_debug

int global_fax_debug = 0
static

Definition at line 656 of file res_fax.c.

Referenced by cli_fax_set_debug(), fax_gateway_attach(), receivefax_exec(), and sendfax_exec().

◆ nextsessionname

int nextsessionname

the next unique session name

Definition at line 613 of file res_fax.c.

◆ options_lock

ast_rwlock_t options_lock = AST_RWLOCK_INIT_VALUE
static

Definition at line 649 of file res_fax.c.

Referenced by get_general_options(), and set_general_options().

◆ our_t38_parameters

struct ast_control_t38_parameters our_t38_parameters
static

Definition at line 834 of file res_fax.c.

834 {
835 .version = 0,
836 .max_ifp = 400,
837 .rate = AST_T38_RATE_14400,
839};
@ AST_T38_RATE_14400
@ AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF

Referenced by find_or_create_details().

◆ reserved_sessions

int reserved_sessions

The number of reserved FAX sessions

Definition at line 601 of file res_fax.c.