root/src/include/freetdm.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. FTDM_STR2ENUM_P
  2. FTDM_STR2ENUM_P
  3. FTDM_STR2ENUM_P
  4. FTDM_STR2ENUM_P
  5. FTDM_STR2ENUM_P
  6. FTDM_STR2ENUM_P
  7. FTDM_STR2ENUM_P
  8. FTDM_STR2ENUM_P
  9. FTDM_STR2ENUM_P
  10. FTDM_STR2ENUM_P
  11. FTDM_STR2ENUM_P
  12. FTDM_STR2ENUM_P
  13. FTDM_STR2ENUM_P

   1 /*
   2  * Copyright (c) 2007, Anthony Minessale II
   3  * All rights reserved.
   4  * 
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  * 
   9  * * Redistributions of source code must retain the above copyright
  10  * notice, this list of conditions and the following disclaimer.
  11  * 
  12  * * Redistributions in binary form must reproduce the above copyright
  13  * notice, this list of conditions and the following disclaimer in the
  14  * documentation and/or other materials provided with the distribution.
  15  * 
  16  * * Neither the name of the original author; nor the names of any contributors
  17  * may be used to endorse or promote products derived from this software
  18  * without specific prior written permission.
  19  * 
  20  * 
  21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
  25  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  *
  33  * Contributors: 
  34  *
  35  * Moises Silva <moy@sangoma.com>
  36  *
  37  */
  38 
  39 #ifndef FREETDM_H
  40 #define FREETDM_H
  41 
  42 
  43 #include "ftdm_declare.h"
  44 #include "ftdm_call_utils.h"
  45 
  46 /*! \brief Max number of channels per physical span */
  47 #define FTDM_MAX_CHANNELS_PHYSICAL_SPAN 32
  48 
  49 /*! \brief Max number of physical spans per logical span */
  50 #define FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN 32
  51 
  52 /*! \brief Max number of channels a logical span can contain */
  53 #define FTDM_MAX_CHANNELS_SPAN FTDM_MAX_CHANNELS_PHYSICAL_SPAN * FTDM_MAX_PHYSICAL_SPANS_PER_LOGICAL_SPAN
  54 
  55 /*! \brief Max number of logical spans */
  56 #define FTDM_MAX_SPANS_INTERFACE 128
  57 
  58 /*! \brief Max number of channels per hunting group */
  59 #define FTDM_MAX_CHANNELS_GROUP 1024
  60 
  61 /*! \brief Max number of groups */
  62 #define FTDM_MAX_GROUPS_INTERFACE FTDM_MAX_SPANS_INTERFACE
  63 
  64 #define FTDM_INVALID_INT_PARM 0xFF
  65 
  66 /*! \brief Thread/Mutex OS abstraction API. */
  67 #include "ftdm_os.h"
  68 
  69 #ifdef __cplusplus
  70 extern "C" {
  71 #endif
  72 
  73 /*! \brief Limit to span names */
  74 #define FTDM_MAX_NAME_STR_SZ 80
  75 
  76 /*! \brief Limit to channel number strings */
  77 #define FTDM_MAX_NUMBER_STR_SZ 20
  78 
  79 /*! \brief Hangup cause codes */
  80 typedef enum {
  81         FTDM_CAUSE_NONE = 0,
  82         FTDM_CAUSE_UNALLOCATED = 1,
  83         FTDM_CAUSE_NO_ROUTE_TRANSIT_NET = 2,
  84         FTDM_CAUSE_NO_ROUTE_DESTINATION = 3,
  85         FTDM_CAUSE_CHANNEL_UNACCEPTABLE = 6,
  86         FTDM_CAUSE_CALL_AWARDED_DELIVERED = 7,
  87         FTDM_CAUSE_NORMAL_CLEARING = 16,
  88         FTDM_CAUSE_USER_BUSY = 17,
  89         FTDM_CAUSE_NO_USER_RESPONSE = 18,
  90         FTDM_CAUSE_NO_ANSWER = 19,
  91         FTDM_CAUSE_SUBSCRIBER_ABSENT = 20,
  92         FTDM_CAUSE_CALL_REJECTED = 21,
  93         FTDM_CAUSE_NUMBER_CHANGED = 22,
  94         FTDM_CAUSE_REDIRECTION_TO_NEW_DESTINATION = 23,
  95         FTDM_CAUSE_EXCHANGE_ROUTING_ERROR = 25,
  96         FTDM_CAUSE_DESTINATION_OUT_OF_ORDER = 27,
  97         FTDM_CAUSE_INVALID_NUMBER_FORMAT = 28,
  98         FTDM_CAUSE_FACILITY_REJECTED = 29,
  99         FTDM_CAUSE_RESPONSE_TO_STATUS_ENQUIRY = 30,
 100         FTDM_CAUSE_NORMAL_UNSPECIFIED = 31,
 101         FTDM_CAUSE_NORMAL_CIRCUIT_CONGESTION = 34,
 102         FTDM_CAUSE_NETWORK_OUT_OF_ORDER = 38,
 103         FTDM_CAUSE_NORMAL_TEMPORARY_FAILURE = 41,
 104         FTDM_CAUSE_SWITCH_CONGESTION = 42,
 105         FTDM_CAUSE_ACCESS_INFO_DISCARDED = 43,
 106         FTDM_CAUSE_REQUESTED_CHAN_UNAVAIL = 44,
 107         FTDM_CAUSE_PRE_EMPTED = 45,
 108         FTDM_CAUSE_FACILITY_NOT_SUBSCRIBED = 50,
 109         FTDM_CAUSE_OUTGOING_CALL_BARRED = 52,
 110         FTDM_CAUSE_INCOMING_CALL_BARRED = 54,
 111         FTDM_CAUSE_BEARERCAPABILITY_NOTAUTH = 57,
 112         FTDM_CAUSE_BEARERCAPABILITY_NOTAVAIL = 58,
 113         FTDM_CAUSE_SERVICE_UNAVAILABLE = 63,
 114         FTDM_CAUSE_BEARERCAPABILITY_NOTIMPL = 65,
 115         FTDM_CAUSE_CHAN_NOT_IMPLEMENTED = 66,
 116         FTDM_CAUSE_FACILITY_NOT_IMPLEMENTED = 69,
 117         FTDM_CAUSE_SERVICE_NOT_IMPLEMENTED = 79,
 118         FTDM_CAUSE_INVALID_CALL_REFERENCE = 81,
 119         FTDM_CAUSE_INCOMPATIBLE_DESTINATION = 88,
 120         FTDM_CAUSE_INVALID_MSG_UNSPECIFIED = 95,
 121         FTDM_CAUSE_MANDATORY_IE_MISSING = 96,
 122         FTDM_CAUSE_MESSAGE_TYPE_NONEXIST = 97,
 123         FTDM_CAUSE_WRONG_MESSAGE = 98,
 124         FTDM_CAUSE_IE_NONEXIST = 99,
 125         FTDM_CAUSE_INVALID_IE_CONTENTS = 100,
 126         FTDM_CAUSE_WRONG_CALL_STATE = 101,
 127         FTDM_CAUSE_RECOVERY_ON_TIMER_EXPIRE = 102,
 128         FTDM_CAUSE_MANDATORY_IE_LENGTH_ERROR = 103,
 129         FTDM_CAUSE_PROTOCOL_ERROR = 111,
 130         FTDM_CAUSE_INTERWORKING = 127,
 131         FTDM_CAUSE_SUCCESS = 142,
 132         FTDM_CAUSE_ORIGINATOR_CANCEL = 487,
 133         FTDM_CAUSE_CRASH = 500,
 134         FTDM_CAUSE_SYSTEM_SHUTDOWN = 501,
 135         FTDM_CAUSE_LOSE_RACE = 502,
 136         FTDM_CAUSE_MANAGER_REQUEST = 503,
 137         FTDM_CAUSE_BLIND_TRANSFER = 600,
 138         FTDM_CAUSE_ATTENDED_TRANSFER = 601,
 139         FTDM_CAUSE_ALLOTTED_TIMEOUT = 602,
 140         FTDM_CAUSE_USER_CHALLENGE = 603,
 141         FTDM_CAUSE_MEDIA_TIMEOUT = 604
 142 } ftdm_call_cause_t;
 143 
 144 /*! \brief Hunting direction (when hunting for free channels) */
 145 typedef enum {
 146         FTDM_TOP_DOWN,
 147         FTDM_BOTTOM_UP,
 148         FTDM_RR_DOWN,
 149         FTDM_RR_UP,
 150 } ftdm_direction_t;
 151 
 152 /*! \brief I/O channel type */
 153 typedef enum {
 154         FTDM_CHAN_TYPE_B, /*!< Bearer channel */
 155         FTDM_CHAN_TYPE_DQ921, /*< DQ921 channel (D-channel) */
 156         FTDM_CHAN_TYPE_DQ931, /*!< DQ931 channel */
 157         FTDM_CHAN_TYPE_FXS, /*!< FXS analog channel */
 158         FTDM_CHAN_TYPE_FXO, /*!< FXO analog channel */
 159         FTDM_CHAN_TYPE_EM, /*!< E & M channel */
 160         FTDM_CHAN_TYPE_CAS, /*!< CAS channel */
 161         FTDM_CHAN_TYPE_COUNT /*!< Count of channel types */
 162 } ftdm_chan_type_t;
 163 #define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID"
 164 /*! \brief transform from channel type to string and from string to channel type 
 165  * ftdm_str2ftdm_chan_type transforms a channel string (ie: "FXO" to FTDM_CHAN_TYPE_FXO) 
 166  * ftdm_chan_type2str transforms a channel type to string (ie: FTDM_CHAN_TYPE_B to "B")
 167  */
 168 FTDM_STR2ENUM_P(ftdm_str2ftdm_chan_type, ftdm_chan_type2str, ftdm_chan_type_t)
 169 
 170 /*! \brief Test if a channel is a voice channel */
 171 #define FTDM_IS_VOICE_CHANNEL(ftdm_chan) ((ftdm_chan)->type != FTDM_CHAN_TYPE_DQ921 && (ftdm_chan)->type != FTDM_CHAN_TYPE_DQ931)
 172 
 173 /*! \brief Test if a channel is a D-channel */
 174 #define FTDM_IS_DCHAN(ftdm_chan) ((ftdm_chan)->type == FTDM_CHAN_TYPE_DQ921 || (ftdm_chan)->type == FTDM_CHAN_TYPE_DQ931)
 175 
 176 /*! \brief Logging function prototype to be used for all FreeTDM logs 
 177  *  you should use ftdm_global_set_logger to set your own logger
 178  */
 179 typedef void (*ftdm_logger_t)(const char *file, const char *func, int line, int level, const char *fmt, ...);
 180 
 181 /*! \brief Data queue operation functions
 182  *  you can use ftdm_global_set_queue_handler if you want to override the default implementation (not recommended)
 183  */
 184 typedef ftdm_status_t (*ftdm_queue_create_func_t)(ftdm_queue_t **queue, ftdm_size_t capacity);
 185 typedef ftdm_status_t (*ftdm_queue_enqueue_func_t)(ftdm_queue_t *queue, void *obj);
 186 typedef void *(*ftdm_queue_dequeue_func_t)(ftdm_queue_t *queue);
 187 typedef ftdm_status_t (*ftdm_queue_wait_func_t)(ftdm_queue_t *queue, int ms);
 188 typedef ftdm_status_t (*ftdm_queue_get_interrupt_func_t)(ftdm_queue_t *queue, ftdm_interrupt_t **interrupt);
 189 typedef ftdm_status_t (*ftdm_queue_destroy_func_t)(ftdm_queue_t **queue);
 190 typedef struct ftdm_queue_handler {
 191         ftdm_queue_create_func_t create;
 192         ftdm_queue_enqueue_func_t enqueue;
 193         ftdm_queue_dequeue_func_t dequeue;
 194         ftdm_queue_wait_func_t wait;
 195         ftdm_queue_get_interrupt_func_t get_interrupt;
 196         ftdm_queue_destroy_func_t destroy;
 197 } ftdm_queue_handler_t;
 198 
 199 
 200 /*! \brief Type Of Number (TON) */
 201 typedef enum {
 202         FTDM_TON_UNKNOWN = 0,
 203         FTDM_TON_INTERNATIONAL,
 204         FTDM_TON_NATIONAL,
 205         FTDM_TON_NETWORK_SPECIFIC,
 206         FTDM_TON_SUBSCRIBER_NUMBER,
 207         FTDM_TON_ABBREVIATED_NUMBER,
 208         FTDM_TON_RESERVED,
 209         FTDM_TON_INVALID
 210 } ftdm_ton_t;
 211 #define TON_STRINGS "unknown", "international", "national", "network-specific", "subscriber-number", "abbreviated-number", "reserved", "invalid"
 212 FTDM_STR2ENUM_P(ftdm_str2ftdm_ton, ftdm_ton2str, ftdm_ton_t)
 213 
 214 /*! Numbering Plan Identification (NPI) */
 215 typedef enum {
 216         FTDM_NPI_UNKNOWN = 0,
 217         FTDM_NPI_ISDN = 1,
 218         FTDM_NPI_DATA = 3,
 219         FTDM_NPI_TELEX = 4,
 220         FTDM_NPI_NATIONAL = 8,
 221         FTDM_NPI_PRIVATE = 9,
 222         FTDM_NPI_RESERVED = 10,
 223         FTDM_NPI_INVALID
 224 } ftdm_npi_t;
 225 #define NPI_STRINGS "unknown", "ISDN", "data", "telex", "national", "private", "reserved", "invalid"
 226 FTDM_STR2ENUM_P(ftdm_str2ftdm_npi, ftdm_npi2str, ftdm_npi_t)
 227 
 228 /*! Presentation Ind */
 229 typedef enum {
 230         FTDM_PRES_ALLOWED,
 231         FTDM_PRES_RESTRICTED,
 232         FTDM_PRES_NOT_AVAILABLE,
 233         FTDM_PRES_RESERVED,
 234         FTDM_PRES_INVALID
 235 } ftdm_presentation_t;
 236 #define PRESENTATION_STRINGS "presentation-allowed", "presentation-restricted", "number-not-available", "reserved", "Invalid"
 237 FTDM_STR2ENUM_P(ftdm_str2ftdm_presentation, ftdm_presentation2str, ftdm_presentation_t)
 238 
 239 /*! Screening Ind */
 240 typedef enum {
 241         FTDM_SCREENING_NOT_SCREENED,
 242         FTDM_SCREENING_VERIFIED_PASSED,
 243         FTDM_SCREENING_VERIFIED_FAILED,
 244         FTDM_SCREENING_NETWORK_PROVIDED,
 245         FTDM_SCREENING_INVALID
 246 } ftdm_screening_t;
 247 #define SCREENING_STRINGS "user-provided-not-screened", "user-provided-verified-and-passed", "user-provided-verified-and-failed", "network-provided", "invalid"
 248 FTDM_STR2ENUM_P(ftdm_str2ftdm_screening, ftdm_screening2str, ftdm_screening_t)
 249 
 250 /*! \brief bearer capability */
 251 typedef enum {
 252         FTDM_BEARER_CAP_SPEECH = 0x00,
 253         FTDM_BEARER_CAP_64K_UNRESTRICTED = 0x02,
 254         FTDM_BEARER_CAP_3_1KHZ_AUDIO = 0x03,
 255         FTDM_BEARER_CAP_INVALID
 256 } ftdm_bearer_cap_t;
 257 #define BEARER_CAP_STRINGS "speech", "unrestricted-digital-information", "3.1-Khz-audio", "invalid"
 258 FTDM_STR2ENUM_P(ftdm_str2ftdm_bearer_cap, ftdm_bearer_cap2str, ftdm_bearer_cap_t)
 259 
 260 /*! \brief user information layer 1 protocol */
 261 typedef enum {
 262         FTDM_USER_LAYER1_PROT_V110 = 0x01,
 263         FTDM_USER_LAYER1_PROT_ULAW = 0x02,
 264         FTDM_USER_LAYER1_PROT_ALAW = 0x03,
 265         FTDM_USER_LAYER1_PROT_INVALID
 266 } ftdm_user_layer1_prot_t;
 267 #define USER_LAYER1_PROT_STRINGS "V.110", "u-law", "a-law", "Invalid"
 268 FTDM_STR2ENUM_P(ftdm_str2ftdm_usr_layer1_prot, ftdm_user_layer1_prot2str, ftdm_user_layer1_prot_t)
 269 
 270 /*! Calling Party Category */
 271 typedef enum {
 272         FTDM_CPC_UNKNOWN,
 273         FTDM_CPC_OPERATOR,
 274         FTDM_CPC_ORDINARY,
 275         FTDM_CPC_PRIORITY,
 276         FTDM_CPC_DATA,
 277         FTDM_CPC_TEST,
 278         FTDM_CPC_PAYPHONE,
 279         FTDM_CPC_INVALID
 280 } ftdm_calling_party_category_t;
 281 #define CALLING_PARTY_CATEGORY_STRINGS "unknown", "operator", "ordinary", "priority", "data-call", "test-call", "payphone", "invalid"
 282 FTDM_STR2ENUM_P(ftdm_str2ftdm_calling_party_category, ftdm_calling_party_category2str, ftdm_calling_party_category_t)
 283 
 284 /*! \brief Digit limit used in DNIS/ANI */
 285 #define FTDM_DIGITS_LIMIT 25
 286 
 287 /*! \brief Number abstraction */
 288 typedef struct {
 289         char digits[FTDM_DIGITS_LIMIT];
 290         uint8_t type;
 291         uint8_t plan;
 292 } ftdm_number_t;
 293 
 294 typedef void * ftdm_variable_container_t; 
 295 
 296 /*! \brief Caller information */
 297 typedef struct ftdm_caller_data {
 298         char cid_date[8]; /*!< Caller ID date */
 299         char cid_name[80]; /*!< Caller ID name */
 300         ftdm_number_t cid_num; /*!< Caller ID number */
 301         ftdm_number_t ani; /*!< ANI (Automatic Number Identification) */
 302         ftdm_number_t dnis; /*!< DNIS (Dialed Number Identification Service) */
 303         ftdm_number_t rdnis; /*!< RDNIS (Redirected Dialed Number Identification Service) */
 304         char aniII[FTDM_DIGITS_LIMIT]; /*! ANI II */
 305         uint8_t screen; /*!< Screening */
 306         uint8_t pres; /*!< Presentation*/
 307         char collected[FTDM_DIGITS_LIMIT]; /*!< Collected digits so far */
 308         int hangup_cause; /*!< Hangup cause */
 309         char raw_data[1024]; /*!< Protocol specific raw caller data */
 310         uint32_t raw_data_len; /*!< Raw data length */
 311         /* these 2 are undocumented right now, only used by boost: */
 312         /* bearer capability */
 313         ftdm_bearer_cap_t bearer_capability;
 314         /* user information layer 1 protocol */
 315         ftdm_user_layer1_prot_t bearer_layer1;
 316         ftdm_calling_party_category_t cpc; /*!< Calling party category */
 317         ftdm_variable_container_t variables; /*!< Variables attached to this call */
 318         /* We need call_id inside caller_data for the user to be able to retrieve 
 319          * the call_id when ftdm_channel_call_place is called. This is the only time
 320          * that the user can use caller_data.call_id to obtain the call_id. The user
 321          * should use the call_id from sigmsg otherwise */
 322         uint32_t call_id; /*!< Unique call ID for this call */
 323         ftdm_channel_t *fchan; /*!< FreeTDM channel associated (can be NULL) */
 324         void *priv; /*!< Private data for the FreeTDM user */
 325 } ftdm_caller_data_t;
 326 
 327 /*! \brief Hunting mode */
 328 typedef enum {
 329         FTDM_HUNT_SPAN, /*!< Hunt channels in a given span */
 330         FTDM_HUNT_GROUP, /*!< Hunt channels in a given group */
 331         FTDM_HUNT_CHAN, /*!< Hunt for a specific channel */
 332 } ftdm_hunt_mode_t;
 333 
 334 /*! \brief Structure used for FTDM_HUNT_SPAN mode */
 335 typedef struct {
 336         uint32_t span_id;
 337         ftdm_direction_t direction;
 338 } ftdm_span_hunt_t;
 339 
 340 /*! \brief Structure used for FTDM_HUNT_GROUP mode */
 341 typedef struct {
 342         uint32_t group_id;
 343         ftdm_direction_t direction;
 344 } ftdm_group_hunt_t;
 345 
 346 /*! \brief Structure used for FTDM_HUNT_CHAN mode */
 347 typedef struct {
 348         uint32_t span_id;
 349         uint32_t chan_id;
 350 } ftdm_chan_hunt_t;
 351 
 352 /*! \brief Function called before placing the call in the hunted channel
 353  *         The user can have a last saying in whether to proceed or abort 
 354  *         the call attempt. Be aware that this callback will be called with 
 355  *         the channel lock and you must not do any blocking operations during 
 356  *         its execution.
 357  *  \param fchan The channel that will be used to place the call
 358  *  \param caller_data The caller data provided to ftdm_call_place
 359  *  \return FTDM_SUCCESS to proceed or FTDM_BREAK to abort the hunting
 360  */
 361 typedef ftdm_status_t (*ftdm_hunt_result_cb_t)(ftdm_channel_t *fchan, ftdm_caller_data_t *caller_data);
 362 
 363 /*! \brief Channel Hunting provided to ftdm_call_place() */
 364 typedef struct {
 365         ftdm_hunt_mode_t mode;
 366         union {
 367                 ftdm_span_hunt_t span;
 368                 ftdm_group_hunt_t group;
 369                 ftdm_chan_hunt_t chan;
 370         } mode_data;
 371         ftdm_hunt_result_cb_t result_cb; 
 372 } ftdm_hunting_scheme_t;
 373 
 374 
 375 /*! \brief Tone type */
 376 typedef enum {
 377         FTDM_TONE_DTMF = (1 << 0)
 378 } ftdm_tone_type_t;
 379 
 380 /*! \brief Signaling messages sent by the stacks */
 381 typedef enum {
 382         FTDM_SIGEVENT_START,/*!< Incoming call (ie: incoming SETUP msg or Ring) */
 383         FTDM_SIGEVENT_STOP, /*!< Hangup */
 384         FTDM_SIGEVENT_RELEASED, /*!< Channel is completely released and available */
 385         FTDM_SIGEVENT_UP, /*!< Outgoing call has been answered */
 386         FTDM_SIGEVENT_FLASH, /*!< Flash event  (typically on-hook/off-hook for analog devices) */
 387         FTDM_SIGEVENT_PROCEED, /*!< Outgoing call got an initial positive response from the other end */
 388         FTDM_SIGEVENT_RINGING, /*!< Remote side is in ringing state */
 389         FTDM_SIGEVENT_PROGRESS, /*!< Outgoing call is making progress */
 390         FTDM_SIGEVENT_PROGRESS_MEDIA, /*!< Outgoing call is making progress and there is media available */
 391         FTDM_SIGEVENT_ALARM_TRAP, /*!< Hardware alarm ON */
 392         FTDM_SIGEVENT_ALARM_CLEAR, /*!< Hardware alarm OFF */
 393         FTDM_SIGEVENT_COLLECTED_DIGIT, /*!< Digit collected (in signalings where digits are collected one by one) */
 394         FTDM_SIGEVENT_ADD_CALL, /*!< New call should be added to the channel */
 395         FTDM_SIGEVENT_RESTART, /*!< Restart has been requested. Typically you hangup your call resources here */
 396         FTDM_SIGEVENT_SIGSTATUS_CHANGED, /*!< Signaling protocol status changed (ie: D-chan up), see new status in raw_data ftdm_sigmsg_t member */
 397         FTDM_SIGEVENT_COLLISION, /*!< Outgoing call was dropped because an incoming call arrived at the same time */
 398         FTDM_SIGEVENT_FACILITY, /*!< In call facility event */
 399         FTDM_SIGEVENT_TRACE, /*!<Interpreted trace event */
 400         FTDM_SIGEVENT_TRACE_RAW, /*!<Raw trace event */
 401         FTDM_SIGEVENT_INDICATION_COMPLETED, /*!< Last requested indication was completed */
 402         FTDM_SIGEVENT_DIALING, /* Outgoing call just started */
 403         FTDM_SIGEVENT_INVALID, /*!<Invalid */
 404 } ftdm_signal_event_t;
 405 #define SIGNAL_STRINGS "START", "STOP", "RELEASED", "UP", "FLASH", "PROCEED", "RINGING", "PROGRESS", \
 406                 "PROGRESS_MEDIA", "ALARM_TRAP", "ALARM_CLEAR", \
 407                 "COLLECTED_DIGIT", "ADD_CALL", "RESTART", "SIGSTATUS_CHANGED", "COLLISION", "FACILITY", \
 408                 "TRACE", "TRACE_RAW", "INDICATION_COMPLETED", "DIALING", "INVALID"
 409 /*! \brief Move from string to ftdm_signal_event_t and viceversa */
 410 FTDM_STR2ENUM_P(ftdm_str2ftdm_signal_event, ftdm_signal_event2str, ftdm_signal_event_t)
 411 
 412 /*! \brief Span trunk types */
 413 typedef enum {
 414         FTDM_TRUNK_E1,
 415         FTDM_TRUNK_T1,
 416         FTDM_TRUNK_J1,
 417         FTDM_TRUNK_BRI,
 418         FTDM_TRUNK_BRI_PTMP,
 419         FTDM_TRUNK_FXO,
 420         FTDM_TRUNK_FXS,
 421         FTDM_TRUNK_EM,
 422         FTDM_TRUNK_NONE
 423 } ftdm_trunk_type_t;
 424 #define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "BRI_PTMP", "FXO", "FXS", "EM", "NONE"
 425 
 426 /*! \brief Move from string to ftdm_trunk_type_t and viceversa */
 427 FTDM_STR2ENUM_P(ftdm_str2ftdm_trunk_type, ftdm_trunk_type2str, ftdm_trunk_type_t)
 428 
 429 /*! \brief Basic channel configuration provided to ftdm_configure_span_channels */
 430 typedef struct ftdm_channel_config {    
 431         char name[FTDM_MAX_NAME_STR_SZ];
 432         char number[FTDM_MAX_NUMBER_STR_SZ];
 433         char group_name[FTDM_MAX_NAME_STR_SZ];
 434         ftdm_chan_type_t type;
 435         float rxgain;
 436         float txgain;
 437         uint8_t debugdtmf;
 438 } ftdm_channel_config_t;
 439 
 440 /*!
 441   \brief Signaling status on a given span or specific channel on protocols that support it
 442   \note see docs/sigstatus.txt for more extensive documentation on signaling status
 443  */
 444 typedef enum {
 445         /* The signaling link is down (no d-chans up in the span/group, MFC-R2 bit pattern unidentified) */
 446         FTDM_SIG_STATE_DOWN,
 447         /* The signaling link is suspended (MFC-R2 bit pattern blocked, ss7 blocked?) */
 448         FTDM_SIG_STATE_SUSPENDED,
 449         /* The signaling link is ready and calls can be placed (ie: d-chan up) */
 450         FTDM_SIG_STATE_UP,
 451         /* Invalid status */
 452         FTDM_SIG_STATE_INVALID
 453 } ftdm_signaling_status_t;
 454 #define SIGSTATUS_STRINGS "DOWN", "SUSPENDED", "UP", "INVALID"
 455 
 456 /*! \brief Move from string to ftdm_signaling_status_t and viceversa */
 457 FTDM_STR2ENUM_P(ftdm_str2ftdm_signaling_status, ftdm_signaling_status2str, ftdm_signaling_status_t)
 458 
 459 
 460 typedef struct {
 461         ftdm_signaling_status_t status;
 462 } ftdm_event_sigstatus_t;
 463 
 464 typedef enum {
 465         /* This is an received frame */
 466         FTDM_TRACE_DIR_INCOMING,
 467         /* This is a transmitted frame */
 468         FTDM_TRACE_DIR_OUTGOING,
 469         /* Invalid */
 470         FTDM_TRACE_DIR_INVALID,
 471 } ftdm_trace_dir_t;
 472 #define TRACE_DIR_STRINGS "INCOMING", "OUTGOING", "INVALID"
 473 
 474 /*! \brief Move string to ftdm_trace_dir_t and viceversa */
 475 FTDM_STR2ENUM_P(ftdm_str2ftdm_trace_dir, ftdm_trace_dir2str, ftdm_trace_dir_t)
 476 
 477 typedef enum {
 478         FTDM_TRACE_TYPE_Q931,
 479         FTDM_TRACE_TYPE_Q921,
 480         FTDM_TRACE_TYPE_INVALID,
 481 } ftdm_trace_type_t;
 482 #define TRACE_TYPE_STRINGS "Q931", "Q921", "INVALID"
 483 
 484 /*! \brief Move string to ftdm_trace_type_t and viceversa */
 485 FTDM_STR2ENUM_P(ftdm_str2ftdm_trace_type, ftdm_trace_type2str, ftdm_trace_type_t)
 486 
 487 typedef struct {
 488         /* Direction - incoming or outgoing */
 489         ftdm_trace_dir_t dir;
 490         ftdm_trace_type_t type;
 491 } ftdm_event_trace_t;
 492 
 493 typedef struct {
 494         /* Digits collected */
 495         char digits[FTDM_DIGITS_LIMIT];
 496 } ftdm_event_collected_t;
 497 
 498 /*! \brief FreeTDM supported indications.
 499  * This is used during incoming calls when you want to request the signaling stack
 500  * to notify about indications occurring locally. See ftdm_channel_call_indicate for more info */
 501 typedef enum {
 502         FTDM_CHANNEL_INDICATE_NONE,
 503         FTDM_CHANNEL_INDICATE_RINGING,
 504         FTDM_CHANNEL_INDICATE_PROCEED,
 505         FTDM_CHANNEL_INDICATE_PROGRESS,
 506         FTDM_CHANNEL_INDICATE_PROGRESS_MEDIA,
 507         FTDM_CHANNEL_INDICATE_BUSY,
 508         /* Using this indication is equivalent to call ftdm_channel_call_answer API */
 509         FTDM_CHANNEL_INDICATE_ANSWER,
 510         FTDM_CHANNEL_INDICATE_INVALID,
 511 } ftdm_channel_indication_t;
 512 #define INDICATION_STRINGS "NONE", "RINGING", "PROCEED", "PROGRESS", "PROGRESS_MEDIA", "BUSY", "ANSWER", "INVALID"
 513 
 514 /*! \brief Move from string to ftdm_channel_indication_t and viceversa */
 515 FTDM_STR2ENUM_P(ftdm_str2channel_indication, ftdm_channel_indication2str, ftdm_channel_indication_t)
 516 
 517 typedef struct {
 518         /* The indication that was completed */
 519         ftdm_channel_indication_t indication;
 520         /* Completion status of the indication */
 521         ftdm_status_t status;
 522 } ftdm_event_indication_completed_t;
 523 
 524 /*! \brief Generic signaling message */
 525 struct ftdm_sigmsg {
 526         ftdm_signal_event_t event_id; /*!< The type of message */
 527         ftdm_channel_t *channel; /*!< Related channel */
 528         uint32_t chan_id; /*!< easy access to chan id */
 529         uint32_t span_id; /*!< easy access to span_id */
 530         uint32_t call_id; /*!< unique call id for this call */
 531         union {
 532                 ftdm_event_sigstatus_t sigstatus; /*!< valid if event_id is FTDM_SIGEVENT_SIGSTATUS_CHANGED */
 533                 ftdm_event_trace_t trace;       /*!< valid if event_id is FTDM_SIGEVENT_TRACE or FTDM_SIGEVENT_TRACE_RAW */
 534                 ftdm_event_collected_t collected; /*!< valid if event_id is FTDM_SIGEVENT_COLLECTED_DIGIT */
 535                 ftdm_event_indication_completed_t indication_completed; /*!< valid if the event_id is FTDM_SIGEVENT_INDICATION_COMPLETED */
 536         } ev_data;
 537         struct {
 538                 uint8_t autofree; /*!< Whether the freetdm core will free it after message delivery */
 539                 uint32_t len; /*!< Data len */
 540                 void *data; /*!< Signaling module specific data */
 541         } raw;
 542 };
 543 
 544 /*! \brief Crash policy 
 545  *  Useful for debugging only, default policy is never, if you wish to crash on asserts then use ftdm_global_set_crash_policy */
 546 typedef enum {
 547         FTDM_CRASH_NEVER = 0,
 548         FTDM_CRASH_ON_ASSERT
 549 } ftdm_crash_policy_t;
 550 
 551 /*! \brief I/O waiting flags */
 552 typedef enum {
 553         FTDM_NO_FLAGS = 0,
 554         FTDM_READ =  (1 << 0),
 555         FTDM_WRITE = (1 << 1),
 556         FTDM_EVENTS = (1 << 2)
 557 } ftdm_wait_flag_t;
 558 
 559 /*! \brief Signaling configuration parameter for the stacks (variable=value pair) */
 560 typedef struct ftdm_conf_parameter {
 561         const char *var;
 562         const char *val;
 563         void *ptr;
 564 } ftdm_conf_parameter_t;
 565 
 566 /*! \brief Opaque general purpose iterator */
 567 typedef struct ftdm_iterator ftdm_iterator_t;
 568 
 569 /*! \brief Channel commands that can be executed through ftdm_channel_command() */
 570 typedef enum {
 571         FTDM_COMMAND_NOOP,
 572         FTDM_COMMAND_SET_INTERVAL,
 573         FTDM_COMMAND_GET_INTERVAL,
 574         FTDM_COMMAND_SET_CODEC,
 575         FTDM_COMMAND_GET_CODEC,
 576         FTDM_COMMAND_SET_NATIVE_CODEC,
 577         FTDM_COMMAND_GET_NATIVE_CODEC,
 578         FTDM_COMMAND_ENABLE_DTMF_DETECT,
 579         FTDM_COMMAND_DISABLE_DTMF_DETECT,
 580         FTDM_COMMAND_SEND_DTMF,
 581         FTDM_COMMAND_SET_DTMF_ON_PERIOD,
 582         FTDM_COMMAND_GET_DTMF_ON_PERIOD,
 583         FTDM_COMMAND_SET_DTMF_OFF_PERIOD,
 584         FTDM_COMMAND_GET_DTMF_OFF_PERIOD,
 585         FTDM_COMMAND_GENERATE_RING_ON,
 586         FTDM_COMMAND_GENERATE_RING_OFF,
 587         FTDM_COMMAND_OFFHOOK,
 588         FTDM_COMMAND_ONHOOK,
 589         FTDM_COMMAND_FLASH,
 590         FTDM_COMMAND_WINK,
 591         FTDM_COMMAND_ENABLE_PROGRESS_DETECT,
 592         FTDM_COMMAND_DISABLE_PROGRESS_DETECT,
 593 
 594         /*!< Start tracing input and output from channel to the given file */
 595         FTDM_COMMAND_TRACE_INPUT,
 596         FTDM_COMMAND_TRACE_OUTPUT,
 597 
 598         /*!< Stop both Input and Output trace, closing the files */
 599         FTDM_COMMAND_TRACE_END_ALL,
 600 
 601         /*!< Enable DTMF debugging */
 602         FTDM_COMMAND_ENABLE_DEBUG_DTMF,
 603 
 604         /*!< Disable DTMF debugging (if not disabled explicitly, it is disabled automatically when calls hangup) */
 605         FTDM_COMMAND_DISABLE_DEBUG_DTMF,
 606 
 607         /*!< Start dumping all input to a circular buffer. The size of the circular buffer can be specified, default used otherwise */
 608         FTDM_COMMAND_ENABLE_INPUT_DUMP,
 609 
 610         /*!< Stop dumping all input to a circular buffer. */
 611         FTDM_COMMAND_DISABLE_INPUT_DUMP,
 612 
 613         /*!< Start dumping all output to a circular buffer. The size of the circular buffer can be specified, default used otherwise */
 614         FTDM_COMMAND_ENABLE_OUTPUT_DUMP,
 615 
 616         /*!< Stop dumping all output to a circular buffer. */
 617         FTDM_COMMAND_DISABLE_OUTPUT_DUMP,
 618 
 619         /*!< Dump the current input circular buffer to the specified FILE* structure */
 620         FTDM_COMMAND_DUMP_INPUT,
 621 
 622         /*!< Dump the current output circular buffer to the specified FILE* structure */
 623         FTDM_COMMAND_DUMP_OUTPUT,
 624 
 625         FTDM_COMMAND_ENABLE_CALLERID_DETECT,
 626         FTDM_COMMAND_DISABLE_CALLERID_DETECT,
 627         FTDM_COMMAND_ENABLE_ECHOCANCEL,
 628         FTDM_COMMAND_DISABLE_ECHOCANCEL,
 629         FTDM_COMMAND_ENABLE_ECHOTRAIN,
 630         FTDM_COMMAND_DISABLE_ECHOTRAIN,
 631         FTDM_COMMAND_SET_CAS_BITS,
 632         FTDM_COMMAND_GET_CAS_BITS,
 633         FTDM_COMMAND_SET_RX_GAIN,
 634         FTDM_COMMAND_GET_RX_GAIN,
 635         FTDM_COMMAND_SET_TX_GAIN,
 636         FTDM_COMMAND_GET_TX_GAIN,
 637         FTDM_COMMAND_FLUSH_TX_BUFFERS,
 638         FTDM_COMMAND_FLUSH_RX_BUFFERS,
 639         FTDM_COMMAND_FLUSH_BUFFERS,
 640         FTDM_COMMAND_FLUSH_IOSTATS,
 641         FTDM_COMMAND_SET_PRE_BUFFER_SIZE,
 642         FTDM_COMMAND_SET_LINK_STATUS,
 643         FTDM_COMMAND_GET_LINK_STATUS,
 644         FTDM_COMMAND_ENABLE_LOOP,
 645         FTDM_COMMAND_DISABLE_LOOP,
 646         FTDM_COMMAND_SET_RX_QUEUE_SIZE,
 647         FTDM_COMMAND_SET_TX_QUEUE_SIZE,
 648         FTDM_COMMAND_SET_POLARITY,
 649         FTDM_COMMAND_COUNT,
 650 } ftdm_command_t;
 651 
 652 typedef enum {
 653         FTDM_POLARITY_FORWARD = 0,
 654         FTDM_POLARITY_REVERSE = 1
 655 } ftdm_polarity_t;
 656 
 657 /*! \brief Custom memory handler hooks. Not recommended to use unless you need memory allocation customizations */
 658 typedef void *(*ftdm_malloc_func_t)(void *pool, ftdm_size_t len);
 659 typedef void *(*ftdm_calloc_func_t)(void *pool, ftdm_size_t elements, ftdm_size_t len);
 660 typedef void *(*ftdm_realloc_func_t)(void *pool, void *buff, ftdm_size_t len);
 661 typedef void (*ftdm_free_func_t)(void *pool, void *ptr);
 662 struct ftdm_memory_handler {
 663         void *pool;
 664         ftdm_malloc_func_t malloc;
 665         ftdm_calloc_func_t calloc;
 666         ftdm_realloc_func_t realloc;
 667         ftdm_free_func_t free;
 668 };
 669 
 670 /*! \brief FreeTDM I/O layer interface argument macros 
 671  * You don't need these unless your implementing an I/O interface module (most users don't) */
 672 #define FIO_CHANNEL_REQUEST_ARGS (ftdm_span_t *span, uint32_t chan_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan)
 673 #define FIO_CHANNEL_OUTGOING_CALL_ARGS (ftdm_channel_t *ftdmchan)
 674 #define FIO_CHANNEL_SEND_MSG_ARGS (ftdm_channel_t *ftdmchan, ftdm_sigmsg_t *sigmsg)
 675 #define FIO_CHANNEL_SET_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status)
 676 #define FIO_CHANNEL_GET_SIG_STATUS_ARGS (ftdm_channel_t *ftdmchan, ftdm_signaling_status_t *status)
 677 #define FIO_SPAN_SET_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t status)
 678 #define FIO_SPAN_GET_SIG_STATUS_ARGS (ftdm_span_t *span, ftdm_signaling_status_t *status)
 679 #define FIO_SPAN_POLL_EVENT_ARGS (ftdm_span_t *span, uint32_t ms, short *poll_events)
 680 #define FIO_SPAN_NEXT_EVENT_ARGS (ftdm_span_t *span, ftdm_event_t **event)
 681 #define FIO_CHANNEL_NEXT_EVENT_ARGS (ftdm_channel_t *ftdmchan, ftdm_event_t **event)
 682 #define FIO_SIGNAL_CB_ARGS (ftdm_sigmsg_t *sigmsg)
 683 #define FIO_EVENT_CB_ARGS (ftdm_channel_t *ftdmchan, ftdm_event_t *event)
 684 #define FIO_CONFIGURE_SPAN_ARGS (ftdm_span_t *span, const char *str, ftdm_chan_type_t type, char *name, char *number)
 685 #define FIO_CONFIGURE_ARGS (const char *category, const char *var, const char *val, int lineno)
 686 #define FIO_OPEN_ARGS (ftdm_channel_t *ftdmchan)
 687 #define FIO_CLOSE_ARGS (ftdm_channel_t *ftdmchan)
 688 #define FIO_CHANNEL_DESTROY_ARGS (ftdm_channel_t *ftdmchan)
 689 #define FIO_SPAN_DESTROY_ARGS (ftdm_span_t *span)
 690 #define FIO_COMMAND_ARGS (ftdm_channel_t *ftdmchan, ftdm_command_t command, void *obj)
 691 #define FIO_WAIT_ARGS (ftdm_channel_t *ftdmchan, ftdm_wait_flag_t *flags, int32_t to)
 692 #define FIO_GET_ALARMS_ARGS (ftdm_channel_t *ftdmchan)
 693 #define FIO_READ_ARGS (ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen)
 694 #define FIO_WRITE_ARGS (ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen)
 695 #define FIO_IO_LOAD_ARGS (ftdm_io_interface_t **fio)
 696 #define FIO_IO_UNLOAD_ARGS (void)
 697 #define FIO_SIG_LOAD_ARGS (void)
 698 #define FIO_SIG_CONFIGURE_ARGS (ftdm_span_t *span, fio_signal_cb_t sig_cb, va_list ap)
 699 #define FIO_CONFIGURE_SPAN_SIGNALING_ARGS (ftdm_span_t *span, fio_signal_cb_t sig_cb, ftdm_conf_parameter_t *ftdm_parameters)
 700 #define FIO_SIG_UNLOAD_ARGS (void)
 701 #define FIO_API_ARGS (ftdm_stream_handle_t *stream, const char *data)
 702 
 703 /*! \brief FreeTDM I/O layer interface function typedefs
 704  * You don't need these unless your implementing an I/O interface module (most users don't) */
 705 typedef ftdm_status_t (*fio_channel_request_t) FIO_CHANNEL_REQUEST_ARGS ;
 706 typedef ftdm_status_t (*fio_channel_outgoing_call_t) FIO_CHANNEL_OUTGOING_CALL_ARGS ;
 707 typedef ftdm_status_t (*fio_channel_send_msg_t) FIO_CHANNEL_SEND_MSG_ARGS;
 708 typedef ftdm_status_t (*fio_channel_set_sig_status_t) FIO_CHANNEL_SET_SIG_STATUS_ARGS;
 709 typedef ftdm_status_t (*fio_channel_get_sig_status_t) FIO_CHANNEL_GET_SIG_STATUS_ARGS;
 710 typedef ftdm_status_t (*fio_span_set_sig_status_t) FIO_SPAN_SET_SIG_STATUS_ARGS;
 711 typedef ftdm_status_t (*fio_span_get_sig_status_t) FIO_SPAN_GET_SIG_STATUS_ARGS;
 712 typedef ftdm_status_t (*fio_span_poll_event_t) FIO_SPAN_POLL_EVENT_ARGS ;
 713 typedef ftdm_status_t (*fio_span_next_event_t) FIO_SPAN_NEXT_EVENT_ARGS ;
 714 typedef ftdm_status_t (*fio_channel_next_event_t) FIO_CHANNEL_NEXT_EVENT_ARGS ;
 715 
 716 /*! \brief Callback for signal delivery (FTDM_SIGEVENT_START and friends) 
 717  *  \note This callback is provided by the user during ftdm_configure_span_signaling
 718  *
 719  *  \note You must NOT do any blocking during this callback since this function is
 720  *        most likely called in an internal signaling thread that can potentially be
 721  *        shared for all the channels in a span and blocking will delay processing
 722  *        (sometimes even audio processing) for other channels
 723  *
 724  *  \note Although some simple FreeTDM APIs can work (ie: ftdm_span_get_id etc), the
 725  *        use of any FreeTDM call API (ie ftdm_channel_call_answer) is discouraged
 726  */
 727 typedef ftdm_status_t (*fio_signal_cb_t) FIO_SIGNAL_CB_ARGS ;
 728 
 729 typedef ftdm_status_t (*fio_event_cb_t) FIO_EVENT_CB_ARGS ;
 730 typedef ftdm_status_t (*fio_configure_span_t) FIO_CONFIGURE_SPAN_ARGS ;
 731 typedef ftdm_status_t (*fio_configure_t) FIO_CONFIGURE_ARGS ;
 732 typedef ftdm_status_t (*fio_open_t) FIO_OPEN_ARGS ;
 733 typedef ftdm_status_t (*fio_close_t) FIO_CLOSE_ARGS ;
 734 typedef ftdm_status_t (*fio_channel_destroy_t) FIO_CHANNEL_DESTROY_ARGS ;
 735 typedef ftdm_status_t (*fio_span_destroy_t) FIO_SPAN_DESTROY_ARGS ;
 736 typedef ftdm_status_t (*fio_get_alarms_t) FIO_GET_ALARMS_ARGS ;
 737 typedef ftdm_status_t (*fio_command_t) FIO_COMMAND_ARGS ;
 738 typedef ftdm_status_t (*fio_wait_t) FIO_WAIT_ARGS ;
 739 typedef ftdm_status_t (*fio_read_t) FIO_READ_ARGS ;
 740 typedef ftdm_status_t (*fio_write_t) FIO_WRITE_ARGS ;
 741 typedef ftdm_status_t (*fio_io_load_t) FIO_IO_LOAD_ARGS ;
 742 typedef ftdm_status_t (*fio_sig_load_t) FIO_SIG_LOAD_ARGS ;
 743 typedef ftdm_status_t (*fio_sig_configure_t) FIO_SIG_CONFIGURE_ARGS ;
 744 typedef ftdm_status_t (*fio_configure_span_signaling_t) FIO_CONFIGURE_SPAN_SIGNALING_ARGS ;
 745 typedef ftdm_status_t (*fio_io_unload_t) FIO_IO_UNLOAD_ARGS ;
 746 typedef ftdm_status_t (*fio_sig_unload_t) FIO_SIG_UNLOAD_ARGS ;
 747 typedef ftdm_status_t (*fio_api_t) FIO_API_ARGS ;
 748 
 749 
 750 /*! \brief FreeTDM I/O layer interface function prototype wrapper macros
 751  * You don't need these unless your implementing an I/O interface module (most users don't) */
 752 #define FIO_CHANNEL_REQUEST_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_REQUEST_ARGS
 753 #define FIO_CHANNEL_OUTGOING_CALL_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_OUTGOING_CALL_ARGS
 754 #define FIO_CHANNEL_SEND_MSG_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_SEND_MSG_ARGS
 755 #define FIO_CHANNEL_SET_SIG_STATUS_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_SET_SIG_STATUS_ARGS
 756 #define FIO_CHANNEL_GET_SIG_STATUS_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_GET_SIG_STATUS_ARGS
 757 #define FIO_SPAN_SET_SIG_STATUS_FUNCTION(name) ftdm_status_t name FIO_SPAN_SET_SIG_STATUS_ARGS
 758 #define FIO_SPAN_GET_SIG_STATUS_FUNCTION(name) ftdm_status_t name FIO_SPAN_GET_SIG_STATUS_ARGS
 759 #define FIO_SPAN_POLL_EVENT_FUNCTION(name) ftdm_status_t name FIO_SPAN_POLL_EVENT_ARGS
 760 #define FIO_SPAN_NEXT_EVENT_FUNCTION(name) ftdm_status_t name FIO_SPAN_NEXT_EVENT_ARGS
 761 #define FIO_CHANNEL_NEXT_EVENT_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_NEXT_EVENT_ARGS
 762 #define FIO_SIGNAL_CB_FUNCTION(name) ftdm_status_t name FIO_SIGNAL_CB_ARGS
 763 #define FIO_EVENT_CB_FUNCTION(name) ftdm_status_t name FIO_EVENT_CB_ARGS
 764 #define FIO_CONFIGURE_SPAN_FUNCTION(name) ftdm_status_t name FIO_CONFIGURE_SPAN_ARGS
 765 #define FIO_CONFIGURE_FUNCTION(name) ftdm_status_t name FIO_CONFIGURE_ARGS
 766 #define FIO_OPEN_FUNCTION(name) ftdm_status_t name FIO_OPEN_ARGS
 767 #define FIO_CLOSE_FUNCTION(name) ftdm_status_t name FIO_CLOSE_ARGS
 768 #define FIO_CHANNEL_DESTROY_FUNCTION(name) ftdm_status_t name FIO_CHANNEL_DESTROY_ARGS
 769 #define FIO_SPAN_DESTROY_FUNCTION(name) ftdm_status_t name FIO_SPAN_DESTROY_ARGS
 770 #define FIO_GET_ALARMS_FUNCTION(name) ftdm_status_t name FIO_GET_ALARMS_ARGS
 771 #define FIO_COMMAND_FUNCTION(name) ftdm_status_t name FIO_COMMAND_ARGS
 772 #define FIO_WAIT_FUNCTION(name) ftdm_status_t name FIO_WAIT_ARGS
 773 #define FIO_READ_FUNCTION(name) ftdm_status_t name FIO_READ_ARGS
 774 #define FIO_WRITE_FUNCTION(name) ftdm_status_t name FIO_WRITE_ARGS
 775 #define FIO_IO_LOAD_FUNCTION(name) ftdm_status_t name FIO_IO_LOAD_ARGS
 776 #define FIO_SIG_LOAD_FUNCTION(name) ftdm_status_t name FIO_SIG_LOAD_ARGS
 777 #define FIO_SIG_CONFIGURE_FUNCTION(name) ftdm_status_t name FIO_SIG_CONFIGURE_ARGS
 778 #define FIO_CONFIGURE_SPAN_SIGNALING_FUNCTION(name) ftdm_status_t name FIO_CONFIGURE_SPAN_SIGNALING_ARGS
 779 #define FIO_IO_UNLOAD_FUNCTION(name) ftdm_status_t name FIO_IO_UNLOAD_ARGS
 780 #define FIO_SIG_UNLOAD_FUNCTION(name) ftdm_status_t name FIO_SIG_UNLOAD_ARGS
 781 #define FIO_API_FUNCTION(name) ftdm_status_t name FIO_API_ARGS
 782 
 783 /*! \brief FreeTDM I/O layer function prototype wrapper macros
 784  * You don't need these unless your implementing an I/O interface module (most users don't) */
 785 struct ftdm_io_interface {
 786         const char *name; /*!< I/O module name */
 787         fio_configure_span_t configure_span; /*!< Configure span I/O */
 788         fio_configure_t configure; /*!< Configure the module */
 789         fio_open_t open; /*!< Open I/O channel */
 790         fio_close_t close; /*!< Close I/O channel */
 791         fio_channel_destroy_t channel_destroy; /*!< Destroy I/O channel */
 792         fio_span_destroy_t span_destroy; /*!< Destroy span I/O */
 793         fio_get_alarms_t get_alarms; /*!< Get hardware alarms */
 794         fio_command_t command; /*!< Execute an I/O command on the channel */
 795         fio_wait_t wait; /*!< Wait for events on the channel */
 796         fio_read_t read; /*!< Read data from the channel */
 797         fio_write_t write; /*!< Write data to the channel */
 798         fio_span_poll_event_t poll_event; /*!< Poll for events on the whole span */
 799         fio_span_next_event_t next_event; /*!< Retrieve an event from the span */
 800         fio_channel_next_event_t channel_next_event; /*!< Retrieve an event from channel */
 801         fio_api_t api; /*!< Execute a text command */
 802 };
 803 
 804 /*! \brief FreeTDM supported I/O codecs */
 805 typedef enum {
 806         FTDM_CODEC_ULAW = 0,
 807         FTDM_CODEC_ALAW = 8,
 808         FTDM_CODEC_SLIN = 10,
 809         FTDM_CODEC_NONE = (1 << 30)
 810 } ftdm_codec_t;
 811 
 812 /*! \brief FreeTDM supported hardware alarms. */
 813 typedef enum {
 814         FTDM_ALARM_NONE    = 0,
 815         FTDM_ALARM_RED     = (1 << 1),
 816         FTDM_ALARM_YELLOW  = (1 << 2),
 817         FTDM_ALARM_RAI     = (1 << 3),
 818         FTDM_ALARM_BLUE    = (1 << 4),
 819         FTDM_ALARM_AIS     = (1 << 5),
 820         FTDM_ALARM_GENERAL = (1 << 30)
 821 } ftdm_alarm_flag_t;
 822 
 823 /*! \brief Override the default queue handler */
 824 FT_DECLARE(ftdm_status_t) ftdm_global_set_queue_handler(ftdm_queue_handler_t *handler);
 825 
 826 /*! \brief Return the availability rate for a channel 
 827  * \param ftdmchan Channel to get the availability from
 828  *
 829  * \retval > 0 if availability is supported
 830  * \retval -1 if availability is not supported
 831  */
 832 FT_DECLARE(int) ftdm_channel_get_availability(ftdm_channel_t *ftdmchan);
 833 
 834 /*! \brief Answer call. This can also be accomplished by ftdm_channel_call_indicate with FTDM_CHANNEL_INDICATE_ANSWER, in both
 835  *         cases you will get a FTDM_SIGEVENT_INDICATION_COMPLETED when the indication is sent (or an error occurs).
 836  *         Just as with ftdm_channel_call_indicate you won't receive FTDM_SIGEVENT_INDICATION_COMPLETED when this function
 837  *         returns anything else than FTDM_SUCCESS
 838  *  \note Although this API may result in FTDM_SIGEVENT_INDICATION_COMPLETED event being delivered,
 839  *        there is no guarantee of whether the event will arrive after or before your execution thread returns
 840  *        from ftdm_channel_call_answer 
 841  */
 842 #define ftdm_channel_call_answer(ftdmchan) _ftdm_channel_call_answer(__FILE__, __FUNCTION__, __LINE__, (ftdmchan))
 843 
 844 /*! \brief Answer call recording the source code point where the it was called (see ftdm_channel_call_answer for an easy to use macro) */
 845 FT_DECLARE(ftdm_status_t) _ftdm_channel_call_answer(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan);
 846 
 847 /*! \brief Place an outgoing call in the given channel 
 848  *  \deprecated This macro is deprecated since leaves the door open to glare issues, use ftdm_call_place instead
 849  */
 850 #define ftdm_channel_call_place(ftdmchan) _ftdm_channel_call_place(__FILE__, __FUNCTION__, __LINE__, (ftdmchan))
 851 
 852 /*! \brief Place an outgoing call recording the source code point where it was called (see ftdm_channel_call_place for an easy to use macro) 
 853  *  \deprecated This function is deprecated since leaves the door open to glare issues, use ftdm_call_place instead
 854  */
 855 FT_DECLARE(ftdm_status_t) _ftdm_channel_call_place(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan);
 856 
 857 /*! \brief Place an outgoing call with the given caller data in a channel according to the hunting scheme provided */
 858 #define ftdm_call_place(callerdata, hunting) _ftdm_call_place(__FILE__, __FUNCTION__, __LINE__, (callerdata), (hunting))
 859 
 860 /*! \brief Place an outgoing call with the given caller data in a channel according to the hunting scheme provided and records
 861  *         the place where it was called. See ftdm_call_place for an easy to use macro
 862  *  \return FTDM_SUCCESS if the call attempt was successful 
 863  *          FTDM_FAIL if there was an unspecified error
 864  *          FTDM_EBUSY if the channel was busy 
 865  *          FTDM_BREAK if glare was detected and you must try again
 866  *  \note Even when FTDM_SUCCESS is returned, the call may still fail later on due to glare, in such case FTDM_SIGEVENT_STOP
 867  *        will be sent with the hangup cause field set to FTDM_CAUSE_REQUESTED_CHAN_UNAVAIL
 868  *
 869  *  \note When this function returns FTDM_SUCCESS, the member .fchan from caller_data will be set to the channel used to place the call
 870  *        and .call_id to the generated call id for that call
 871  *
 872  *  \note When this function is successful you are guaranteed to receive FTDM_SIGEVENT_DIALING, this event could even be delivered
 873  *        before your execution thread returns from this function
 874  */
 875 FT_DECLARE(ftdm_status_t) _ftdm_call_place(const char *file, const char *func, int line, ftdm_caller_data_t *caller_data, ftdm_hunting_scheme_t *hunting);
 876 
 877 /*! \brief Indicate a new condition in an incoming call 
 878  *
 879  *  \note Every indication request will result in FTDM_SIGEVENT_INDICATION_COMPLETED event being delivered with
 880  *        the proper status that will inform you if the request was successful or not. The exception is if this
 881  *        function returns something different to FTDM_SUCCESS, in which case the request failed right away and no
 882  *        further FTDM_SIGEVENT_INDICATION_COMPLETED will be delivered
 883  *        Be aware there is no guarantee of whether the completion event will arrive after or before your execution 
 884  *        thread returns from ftdm_channel_call_indicate. This means you could get FTDM_SIGEVENT_INDICATION_COMPLETED 
 885  *        even before your execution thread returns from the ftdm_channel_call_indicate() API
 886  *
 887  * \note  You cannot send more than one indication at the time. You must wait for the completed event before 
 888  *        calling this function again (unless the return code was different than FTDM_SUCCESS)
 889  */
 890 #define ftdm_channel_call_indicate(ftdmchan, indication) _ftdm_channel_call_indicate(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (indication))
 891 
 892 /*! \brief Indicate a new condition in an incoming call recording the source code point where it was called (see ftdm_channel_call_indicate for an easy to use macro) */
 893 FT_DECLARE(ftdm_status_t) _ftdm_channel_call_indicate(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_channel_indication_t indication);
 894 
 895 /*! \brief Send a message on a call */
 896 #define ftdm_channel_call_send_msg(ftdmchan, sigmsg) _ftdm_channel_call_send_msg(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (sigmsg))
 897 
 898 /*! \brief Send a signal on a call recording the source code point where it was called (see ftdm_channel_call_send_msg for an easy to use macro) */
 899 FT_DECLARE(ftdm_status_t) _ftdm_channel_call_send_msg(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_sigmsg_t *sigmsg);
 900 
 901 /*! \brief Hangup the call without cause */
 902 #define ftdm_channel_call_hangup(ftdmchan) _ftdm_channel_call_hangup(__FILE__, __FUNCTION__, __LINE__, (ftdmchan))
 903 
 904 /*! \brief Hangup the call without cause recording the source code point where it was called (see ftdm_channel_call_hangup for an easy to use macro)*/
 905 FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hangup(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan);
 906 
 907 /*! \brief Hangup the call with cause */
 908 #define ftdm_channel_call_hangup_with_cause(ftdmchan, cause) _ftdm_channel_call_hangup_with_cause(__FILE__, __FUNCTION__, __LINE__, (ftdmchan), (cause))
 909 
 910 /*! \brief Hangup the call with cause recording the source code point where it was called (see ftdm_channel_call_hangup_with_cause for an easy to use macro) */
 911 FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hangup_with_cause(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan, ftdm_call_cause_t);
 912 
 913 /*! \brief Reset the channel */
 914 #define ftdm_channel_reset(ftdmchan) _ftdm_channel_reset(__FILE__, __FUNCTION__, __LINE__, (ftdmchan))
 915 
 916 /*! \brief Reset the channel (see _ftdm_channel_reset for an easy to use macro) 
 917  *  \note if there was a call on this channel, call will be cleared without any notifications to the user
 918  */
 919 FT_DECLARE(ftdm_status_t) _ftdm_channel_reset(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan);
 920 
 921 /*! \brief Put a call on hold (if supported by the signaling stack) */
 922 #define ftdm_channel_call_hold(ftdmchan) _ftdm_channel_call_hold(__FILE__, __FUNCTION__, __LINE__, (ftdmchan))
 923 
 924 /*! \brief Put a call on hold recording the source code point where it was called (see ftdm_channel_call_hold for an easy to use macro) */
 925 FT_DECLARE(ftdm_status_t) _ftdm_channel_call_hold(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan);
 926 
 927 /*! \brief Unhold a call */
 928 #define ftdm_channel_call_unhold(ftdmchan) _ftdm_channel_call_unhold(__FILE__, __FUNCTION__, __LINE__, (ftdmchan))
 929 
 930 /*! \brief Unhold a call recording the source code point where it was called (see ftdm_channel_call_unhold for an easy to use macro) */
 931 FT_DECLARE(ftdm_status_t) _ftdm_channel_call_unhold(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan);
 932 
 933 /*! \brief Check if the call is answered already */
 934 FT_DECLARE(ftdm_bool_t) ftdm_channel_call_check_answered(const ftdm_channel_t *ftdmchan);
 935 
 936 /*! \brief Check if the call is busy */
 937 FT_DECLARE(ftdm_bool_t) ftdm_channel_call_check_busy(const ftdm_channel_t *ftdmchan);
 938 
 939 /*! \brief Check if the call is hangup */
 940 FT_DECLARE(ftdm_bool_t) ftdm_channel_call_check_hangup(const ftdm_channel_t *ftdmchan);
 941 
 942 /*! \brief Check if the call is done (final state for a call, just after hangup) */
 943 FT_DECLARE(ftdm_bool_t) ftdm_channel_call_check_done(const ftdm_channel_t *ftdmchan);
 944 
 945 /*! \brief Check if the call is in hold */
 946 FT_DECLARE(ftdm_bool_t) ftdm_channel_call_check_hold(const ftdm_channel_t *ftdmchan);
 947 
 948 /*! \brief Set channel signaling status (ie: put specific circuit down) only if supported by the signaling */
 949 FT_DECLARE(ftdm_status_t) ftdm_channel_set_sig_status(ftdm_channel_t *ftdmchan, ftdm_signaling_status_t status);
 950 
 951 /*! \brief Get channel signaling status (ie: whether protocol layer is up or down) */
 952 FT_DECLARE(ftdm_status_t) ftdm_channel_get_sig_status(ftdm_channel_t *ftdmchan, ftdm_signaling_status_t *status);
 953 
 954 /*! \brief Set span signaling status (ie: put the whole span protocol layer down) only if supported by the signaling */
 955 FT_DECLARE(ftdm_status_t) ftdm_span_set_sig_status(ftdm_span_t *span, ftdm_signaling_status_t status);
 956 
 957 /*! \brief Get span signaling status (ie: whether protocol layer is up or down) */
 958 FT_DECLARE(ftdm_status_t) ftdm_span_get_sig_status(ftdm_span_t *span, ftdm_signaling_status_t *status);
 959 
 960 
 961 /*! 
 962  * \brief Set user private data in the channel
 963  *
 964  * \param ftdmchan The channel where the private data will be stored
 965  * \param pvt The private pointer to store
 966  *
 967  */
 968 FT_DECLARE(void) ftdm_channel_set_private(ftdm_channel_t *ftdmchan, void *pvt);
 969 
 970 /*! 
 971  * \brief Get user private data in the channel
 972  *
 973  * \param ftdmchan The channel to retrieve the private data
 974  * \retval The private data (if any or NULL if no data has been stored)
 975  *
 976  */
 977 FT_DECLARE(void *) ftdm_channel_get_private(const ftdm_channel_t *ftdmchan);
 978 
 979 /*! 
 980  * \brief Remove the given token from the channel
 981  *
 982  * \param ftdmchan The channel where the token is
 983  * \param token The token string. If NULL, all tokens in the channel are cleared
 984  *
 985  * \retval FTDM_SUCCESS success
 986  * \retval FTDM_FAIL failure
 987  */
 988 FT_DECLARE(ftdm_status_t) ftdm_channel_clear_token(ftdm_channel_t *ftdmchan, const char *token);
 989 
 990 /*! 
 991  * \brief Replace the given token with the new token
 992  *
 993  * \param ftdmchan The channel where the token is
 994  * \param old_token The token to replace
 995  * \param new_token The token to put in place
 996  */
 997 FT_DECLARE(void) ftdm_channel_replace_token(ftdm_channel_t *ftdmchan, const char *old_token, const char *new_token);
 998 
 999 /*! 
1000  * \brief Add a new token to the channel
1001  *
1002  * \param ftdmchan The channel where the token will be added
1003  * \param token The token string to add
1004  * \param end if 0, the token will be added at the beginning of the token list, to the end otherwise
1005  *
1006  * \retval FTDM_SUCCESS success
1007  * \retval FTDM_FAIL failure
1008  */
1009 FT_DECLARE(ftdm_status_t) ftdm_channel_add_token(ftdm_channel_t *ftdmchan, char *token, int end);
1010 
1011 /*! 
1012  * \brief Get the requested token
1013  *
1014  * \param ftdmchan The channel where the token is
1015  * \param tokenid The id of the token
1016  *
1017  * \retval The token character string
1018  * \retval NULL token not found
1019  */
1020 FT_DECLARE(const char *) ftdm_channel_get_token(const ftdm_channel_t *ftdmchan, uint32_t tokenid);
1021 
1022 /*! 
1023  * \brief Get the token count
1024  *
1025  * \param ftdmchan The channel to get the token count from
1026  *
1027  * \retval The token count
1028  */
1029 FT_DECLARE(uint32_t) ftdm_channel_get_token_count(const ftdm_channel_t *ftdmchan);
1030 
1031 /*! 
1032  * \brief Get the I/O read/write interval
1033  *
1034  * \param ftdmchan The channel to get the interval from
1035  *
1036  * \retval The interval in milliseconds
1037  */
1038 FT_DECLARE(uint32_t) ftdm_channel_get_io_interval(const ftdm_channel_t *ftdmchan);
1039 
1040 /*! 
1041  * \brief Get the I/O read/write packet length per interval
1042  *
1043  * \param ftdmchan The channel to get the packet length from
1044  *
1045  * \retval The packet length interval in bytes
1046  */
1047 FT_DECLARE(uint32_t) ftdm_channel_get_io_packet_len(const ftdm_channel_t *ftdmchan);
1048 
1049 /*! 
1050  * \brief Get the I/O read/write codec
1051  *
1052  * \param ftdmchan The channel to get the codec from
1053  *
1054  * \retval The codec type
1055  */
1056 FT_DECLARE(ftdm_codec_t) ftdm_channel_get_codec(const ftdm_channel_t *ftdmchan);
1057 
1058 /*! 
1059  * \brief Get the last error string for the channel
1060  *
1061  * \param ftdmchan The channel to get the error from
1062  *
1063  * \retval The error string (not thread-safe, the string is per channel, not per thread)
1064  */
1065 FT_DECLARE(const char *) ftdm_channel_get_last_error(const ftdm_channel_t *ftdmchan);
1066 
1067 /*! 
1068  * \brief Get the current alarm bitmask for the channel
1069  *
1070  * \param ftdmchan The channel to get the alarm bitmask from
1071  * \param alarmbits The alarm bitmask pointer to store the current alarms (you are responsible for allocation/deallocation)
1072  *
1073  * \retval FTDM_SUCCESS success
1074  * \retval FTDM_FAIL failure
1075  */
1076 FT_DECLARE(ftdm_status_t) ftdm_channel_get_alarms(ftdm_channel_t *ftdmchan, ftdm_alarm_flag_t *alarmbits);
1077 
1078 /*! 
1079  * \brief Get the channel type
1080  *
1081  * \param ftdmchan The channel to get the type from
1082  *
1083  * \retval channel type (FXO, FXS, B-channel, D-channel, etc)
1084  */
1085 FT_DECLARE(ftdm_chan_type_t) ftdm_channel_get_type(const ftdm_channel_t *ftdmchan);
1086 
1087 /*! 
1088  * \brief Dequeue DTMF from the given channel
1089  * \note To transmit DTMF use ftdm_channel_command with command FTDM_COMMAND_SEND_DTMF
1090  *
1091  * \param ftdmchan The channel to dequeue DTMF from
1092  * \param dtmf DTMF buffer to store the dtmf (you are responsible for its allocation and deallocation)
1093  * \param len The size of the provided DTMF buffer
1094  *
1095  * \retval The size of the dequeued DTMF (it might be zero if there is no DTMF in the queue)
1096  */
1097 FT_DECLARE(ftdm_size_t) ftdm_channel_dequeue_dtmf(ftdm_channel_t *ftdmchan, char *dtmf, ftdm_size_t len);
1098 
1099 /*! 
1100  * \brief Flush the DTMF queue
1101  *
1102  * \param ftdmchan The channel to flush the dtmf queue of
1103  */
1104 FT_DECLARE(void) ftdm_channel_flush_dtmf(ftdm_channel_t *ftdmchan);
1105 
1106 /*! 
1107  * \brief Wait for an event in the span
1108  *
1109  * \param span The span to wait events for
1110  * \param ms Milliseconds timeout
1111  * \param poll_events Array of events to poll for, for each channel on the span
1112  *
1113  * \retval FTDM_SUCCESS success (at least one event available)
1114  * \retval FTDM_TIMEOUT Timed out waiting for events
1115  * \retval FTDM_FAIL failure
1116  */
1117 FT_DECLARE(ftdm_status_t) ftdm_span_poll_event(ftdm_span_t *span, uint32_t ms, short *poll_events);
1118 
1119 /*! 
1120  * \brief Find a span by its id
1121  *
1122  * \param id The span id 
1123  * \param span Pointer to store the span if found
1124  *
1125  * \retval FTDM_SUCCESS success (span is valid)
1126  * \retval FTDM_FAIL failure (span is not valid)
1127  */
1128 FT_DECLARE(ftdm_status_t) ftdm_span_find(uint32_t id, ftdm_span_t **span);
1129 
1130 /*! 
1131  * \brief Get the last error string for the given span
1132  *
1133  * \param span The span to get the last error from
1134  *
1135  * \retval character string for the last error
1136  */
1137 FT_DECLARE(const char *) ftdm_span_get_last_error(const ftdm_span_t *span);
1138 
1139 /*! 
1140  * \brief Create a new span (not needed if you are using freetdm.conf)
1141  *
1142  * \param iotype The I/O interface type this span will use. 
1143  *               This depends on the available I/O modules 
1144  *               ftmod_wanpipe = "wanpipe" (Sangoma)
1145  *               ftmod_zt = "zt" (DAHDI or Zaptel)
1146  *               ftmod_pika "pika" (this one is most likely broken)
1147  * \param name Name for the span
1148  * \param span Pointer to store the create span
1149  *
1150  * \retval FTDM_SUCCESS success (the span was created)
1151  * \retval FTDM_FAIL failure (span was not created)
1152  */
1153 FT_DECLARE(ftdm_status_t) ftdm_span_create(const char *iotype, const char *name, ftdm_span_t **span);
1154 
1155 /*! 
1156  * \brief Add a new channel to a span
1157  *
1158  * \param span Where to add the new channel
1159  * \param sockfd The socket device associated to the channel (ie: sangoma device, dahdi device etc)
1160  * \param type Channel type
1161  * \param chan Pointer to store the newly allocated channel
1162  *
1163  * \retval FTDM_SUCCESS success (the channel was created)
1164  * \retval FTDM_FAIL failure (span was not created)
1165  */
1166 FT_DECLARE(ftdm_status_t) ftdm_span_add_channel(ftdm_span_t *span, ftdm_socket_t sockfd, ftdm_chan_type_t type, ftdm_channel_t **chan);
1167 
1168 /*! \brief Add the channel to a hunt group */
1169 FT_DECLARE(ftdm_status_t) ftdm_channel_add_to_group(const char* name, ftdm_channel_t* ftdmchan);
1170 
1171 /*! \brief Remove the channel from a hunt group */
1172 FT_DECLARE(ftdm_status_t) ftdm_channel_remove_from_group(ftdm_group_t* group, ftdm_channel_t* ftdmchan);
1173 
1174 /*! 
1175  * \brief Retrieves an event from the span
1176  *
1177  * \note
1178  *      This function is non-reentrant and not thread-safe. 
1179  *      The event returned may be modified if the function is called again 
1180  *      from a different thread or even the same. It is recommended to
1181  *      handle events from the same span in a single thread.
1182  *
1183  * \param ftdmchan The channel to retrieve the event from
1184  * \param event Pointer to store the pointer to the event
1185  *
1186  * \retval FTDM_SUCCESS success (at least one event available)
1187  * \retval FTDM_FAIL failure
1188  */
1189 FT_DECLARE(ftdm_status_t) ftdm_channel_read_event(ftdm_channel_t *ftdmchan, ftdm_event_t **event);
1190 
1191 /*! \brief Find a hunt group by id */
1192 FT_DECLARE(ftdm_status_t) ftdm_group_find(uint32_t id, ftdm_group_t **group);
1193 
1194 /*! \brief Find a hunt group by name */
1195 FT_DECLARE(ftdm_status_t) ftdm_group_find_by_name(const char *name, ftdm_group_t **group);
1196 
1197 /*! \brief Create a group with the given name */
1198 FT_DECLARE(ftdm_status_t) ftdm_group_create(ftdm_group_t **group, const char *name);
1199 
1200 /*! \brief Get the number of channels in use on a span */
1201 FT_DECLARE(ftdm_status_t) ftdm_span_channel_use_count(ftdm_span_t *span, uint32_t *count);
1202 
1203 /*! \brief Get the number of channels in use on a group */
1204 FT_DECLARE(ftdm_status_t) ftdm_group_channel_use_count(ftdm_group_t *group, uint32_t *count);
1205 
1206 /*! \brief Get the id of a group */
1207 FT_DECLARE(uint32_t) ftdm_group_get_id(const ftdm_group_t *group);
1208 
1209 /*! 
1210  * \brief Open a channel specifying the span id and chan id (required before placing a call on the channel)
1211  *
1212  * \warning Try using ftdm_call_place instead if you plan to place a call after opening the channel
1213  *
1214  * \note You must call ftdm_channel_close() or ftdm_channel_call_hangup() to release the channel afterwards
1215  *      Only use ftdm_channel_close if there is no call (incoming or outgoing) in the channel
1216  *
1217  * \param span_id The span id the channel belongs to
1218  * \param chan_id Channel id of the channel you want to open
1219  * \param ftdmchan Pointer to store the channel once is open
1220  *
1221  * \retval FTDM_SUCCESS success (the channel was found and is available)
1222  * \retval FTDM_FAIL failure (channel was not found or not available)
1223  */
1224 FT_DECLARE(ftdm_status_t) ftdm_channel_open(uint32_t span_id, uint32_t chan_id, ftdm_channel_t **ftdmchan);
1225 
1226 /*! 
1227  * \brief Hunts and opens a channel specifying the span id only
1228  *
1229  * \warning Try using ftdm_call_place instead if you plan to place a call after opening the channel
1230  *
1231  * \note You must call ftdm_channel_close() or ftdm_channel_call_hangup() to release the channel afterwards
1232  *      Only use ftdm_channel_close if there is no call (incoming or outgoing) in the channel
1233  *
1234  * \param span_id The span id to hunt for a channel
1235  * \param direction The hunting direction
1236  * \param caller_data The calling party information
1237  * \param ftdmchan The channel pointer to store the available channel
1238  *
1239  * \retval FTDM_SUCCESS success (a suitable channel was found available)
1240  * \retval FTDM_FAIL failure (no suitable channel was found available)
1241  */
1242 FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan);
1243 
1244 /*! 
1245  * \brief Hunts and opens a channel specifying group id
1246  *
1247  * \warning Try using ftdm_call_place instead if you plan to place a call after opening the channel
1248  *
1249  * \note You must call ftdm_channel_close() or ftdm_channel_call_hangup() to release the channel afterwards
1250  *      Only use ftdm_channel_close if there is no call (incoming or outgoing) in the channel
1251  *
1252  * \param group_id The group id to hunt for a channel
1253  * \param direction The hunting direction
1254  * \param caller_data The calling party information
1255  * \param ftdmchan The channel pointer to store the available channel
1256  *
1257  * \retval FTDM_SUCCESS success (a suitable channel was found available)
1258  * \retval FTDM_FAIL failure (no suitable channel was found available)
1259  */
1260 FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_direction_t direction, ftdm_caller_data_t *caller_data, ftdm_channel_t **ftdmchan);
1261 
1262 /*! 
1263  * \brief Close a previously open channel
1264  *
1265  * \warning FreeTDM is more and more a signaling API rather than just a plane IO API, unless you are using
1266  *          FreeTDM as a pure IO API without its signaling modules, you should not use this function
1267  *
1268  * \note If you placed a call in this channel use ftdm_channel_call_hangup(), you MUST NOT call this function, 
1269  *       the signaling stack will close the channel when the call is done.
1270  *
1271  * \param ftdmchan pointer to the channel to close
1272  *
1273  * \retval FTDM_SUCCESS success (a suitable channel was found available)
1274  * \retval FTDM_FAIL failure (no suitable channel was found available)
1275  */
1276 FT_DECLARE(ftdm_status_t) ftdm_channel_close(ftdm_channel_t **ftdmchan);
1277 
1278 /*! 
1279  * \brief Execute a command in a channel (same semantics as the ioctl() unix system call)
1280  *
1281  * \param ftdmchan The channel to execute the command
1282  * \param command The command to execute
1283  * \param arg The argument for the command
1284  *
1285  * \retval FTDM_SUCCESS success (a suitable channel was found available)
1286  * \retval FTDM_FAIL failure (no suitable channel was found available)
1287  */
1288 FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_command_t command, void *arg);
1289 
1290 /*! 
1291  * \brief Wait for I/O events in a channel
1292  *
1293  * \param ftdmchan The channel to wait I/O for
1294  * \param flags The wait I/O flags
1295  * \param timeout The timeout in milliseconds
1296  *
1297  * \retval FTDM_SUCCESS success (a suitable channel was found available)
1298  * \retval FTDM_FAIL failure (no suitable channel was found available)
1299  */
1300 FT_DECLARE(ftdm_status_t) ftdm_channel_wait(ftdm_channel_t *ftdmchan, ftdm_wait_flag_t *flags, int32_t timeout);
1301 
1302 /*! 
1303  * \brief Read data from a channel
1304  *
1305  * \param ftdmchan The channel to read data from
1306  * \param data The pointer to the buffer to store the read data
1307  * \param datalen The size in bytes of the provided buffer
1308  *
1309  * \retval FTDM_SUCCESS success (a suitable channel was found available)
1310  * \retval FTDM_FAIL failure (no suitable channel was found available)
1311  */
1312 FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data, ftdm_size_t *datalen);
1313 
1314 /*! 
1315  * \brief Write data to a channel
1316  *
1317  * \note The difference between data and datasize is subtle but important.
1318  *
1319  *       datalen is a pointer to the size of the actual data that you want to write. This pointer
1320  *       will be updated with the number of bytes actually written.
1321  *       
1322  *       datasize on the other hand is the size of the entire buffer provided in data, whether 
1323  *       all of that buffer is in use or not is a different matter. The difference becomes
1324  *       important only if you are using FreeTDM doing transcoding, for example, providing
1325  *       a ulaw frame of 160 bytes but where the I/O device accepts input in signed linear,
1326  *       the data to write will be 320 bytes, therefore datasize is expected to be at least
1327  *       320 where datalen would be just 160.
1328  *
1329  * \param ftdmchan The channel to write data to
1330  * \param data The pointer to the buffer to write
1331  * \param datasize The maximum number of bytes in data that can be used (in case transcoding is necessary)
1332  * \param datalen The size of the actual data
1333  *
1334  * \retval FTDM_SUCCESS success (a suitable channel was found available)
1335  * \retval FTDM_FAIL failure (no suitable channel was found available)
1336  */
1337 FT_DECLARE(ftdm_status_t) ftdm_channel_write(ftdm_channel_t *ftdmchan, void *data, ftdm_size_t datasize, ftdm_size_t *datalen);
1338 
1339 /*! \brief Add a custom variable to the channel
1340  *  \note This variables may be used by signaling modules to override signaling parameters
1341  *  \todo Document which signaling variables are available
1342  * */
1343 FT_DECLARE(ftdm_status_t) ftdm_channel_add_var(ftdm_channel_t *ftdmchan, const char *var_name, const char *value);
1344 
1345 /*! \brief Get a custom variable from the channel. 
1346  *  \note The variable pointer returned is only valid while the channel is open and it'll be destroyed when the channel is closed. */
1347 FT_DECLARE(const char *) ftdm_channel_get_var(ftdm_channel_t *ftdmchan, const char *var_name);
1348 
1349 /*! \brief Get an iterator to iterate over the channel variables
1350  *  \param ftdmchan The channel structure containing the variables
1351  *  \param iter Optional iterator. You can reuse an old iterator (not previously freed) to avoid the extra allocation of a new iterator.
1352  *  \note The iterator pointer returned is only valid while the channel is open and it'll be destroyed when the channel is closed. 
1353  *        This iterator is completely non-thread safe, if you are adding variables or removing variables while iterating 
1354  *        results are unpredictable
1355  */
1356 FT_DECLARE(ftdm_iterator_t *) ftdm_channel_get_var_iterator(const ftdm_channel_t *ftdmchan, ftdm_iterator_t *iter);
1357 
1358 /*! \brief Get iterator current value (depends on the iterator type)
1359  *  \note Channel iterators return a pointer to ftdm_channel_t
1360  *        Variable iterators return a pointer to the variable name (not the variable value)
1361  */
1362 FT_DECLARE(void *) ftdm_iterator_current(ftdm_iterator_t *iter);
1363 
1364 /*! \brief Get variable name and value for the current iterator position */
1365 FT_DECLARE(ftdm_status_t) ftdm_channel_get_current_var(ftdm_iterator_t *iter, const char **var_name, const char **var_val);
1366 
1367 /*! \brief Advance iterator */
1368 FT_DECLARE(ftdm_iterator_t *) ftdm_iterator_next(ftdm_iterator_t *iter);
1369 
1370 /*! \brief Free iterator 
1371  *  \note You must free an iterator after using it unless you plan to reuse it
1372  */
1373 FT_DECLARE(ftdm_status_t) ftdm_iterator_free(ftdm_iterator_t *iter);
1374 
1375 /*! \brief Add a custom variable to the call
1376  *  \note This variables may be used by signaling modules to override signaling parameters
1377  *  \todo Document which signaling variables are available
1378  * */
1379 FT_DECLARE(ftdm_status_t) ftdm_call_add_var(ftdm_caller_data_t *caller_data, const char *var_name, const char *value);
1380 
1381 /*! \brief Get a custom variable from the call.
1382  *  \note The variable pointer returned is only valid during the callback receiving SIGEVENT. */
1383 FT_DECLARE(const char *) ftdm_call_get_var(ftdm_caller_data_t *caller_data, const char *var_name);
1384 
1385 /*! \brief Get an iterator to iterate over the channel variables
1386  *  \param caller_data The signal msg structure containing the variables
1387  *  \param iter Optional iterator. You can reuse an old iterator (not previously freed) to avoid the extra allocation of a new iterator.
1388  *  \note The iterator pointer returned is only valid while the signal message and it'll be destroyed when the signal message is processed.
1389  *        This iterator is completely non-thread safe, if you are adding variables or removing variables while iterating
1390  *        results are unpredictable
1391  */
1392 FT_DECLARE(ftdm_iterator_t *) ftdm_call_get_var_iterator(const ftdm_caller_data_t *caller_data, ftdm_iterator_t *iter);
1393 
1394 /*! \brief Get variable name and value for the current iterator position */
1395 FT_DECLARE(ftdm_status_t) ftdm_call_get_current_var(ftdm_iterator_t *iter, const char **var_name, const char **var_val);
1396 
1397 /*! \brief Clear all variables  attached to the call
1398  *  \note Variables are cleared at the end of each call back, so it is not necessary for the user to call this function.
1399  *  \todo Document which signaling variables are available
1400  * */
1401 FT_DECLARE(ftdm_status_t) ftdm_call_clear_vars(ftdm_caller_data_t *caller_data);
1402 
1403 /*! \brief Remove a variable attached to the call
1404  *  \note Removes a variable that was attached to the call.
1405  *  \todo Document which call variables are available
1406  * */
1407 FT_DECLARE(ftdm_status_t) ftdm_call_remove_var(ftdm_caller_data_t *caller_data, const char *var_name);
1408 
1409 /*! \brief Clears all the temporary data attached to this call
1410  *  \note Clears caller_data->variables and caller_data->raw_data.
1411  * */
1412 FT_DECLARE(void) ftdm_call_clear_data(ftdm_caller_data_t *caller_data);
1413                 
1414 /*! \brief Get the span pointer associated to the channel */
1415 FT_DECLARE(ftdm_span_t *) ftdm_channel_get_span(const ftdm_channel_t *ftdmchan);
1416 
1417 /*! \brief Get the span pointer associated to the channel */
1418 FT_DECLARE(uint32_t) ftdm_channel_get_span_id(const ftdm_channel_t *ftdmchan);
1419 
1420 /*! \brief Get the physical span id associated to the channel */
1421 FT_DECLARE(uint32_t) ftdm_channel_get_ph_span_id(const ftdm_channel_t *ftdmchan);
1422 
1423 /*! \brief Get the span name associated to the channel */
1424 FT_DECLARE(const char *) ftdm_channel_get_span_name(const ftdm_channel_t *ftdmchan);
1425 
1426 /*! \brief Get the id associated to the channel */
1427 FT_DECLARE(uint32_t) ftdm_channel_get_id(const ftdm_channel_t *ftdmchan);
1428 
1429 /*! \brief Get the name associated to the channel */
1430 FT_DECLARE(const char *) ftdm_channel_get_name(const ftdm_channel_t *ftdmchan);
1431 
1432 /*! \brief Get the number associated to the channel */
1433 FT_DECLARE(const char *) ftdm_channel_get_number(const ftdm_channel_t *ftdmchan);
1434 
1435 /*! \brief Get the number physical id associated to the channel */
1436 FT_DECLARE(uint32_t) ftdm_channel_get_ph_id(const ftdm_channel_t *ftdmchan);
1437 
1438 /*! 
1439  * \brief Configure span with a signaling type 
1440  *
1441  * \deprecated use ftdm_configure_span_signaling instead
1442  *
1443  * \note This function does the same as ftdm_configure_span_signaling
1444  *
1445  * \param span The span to configure
1446  * \param type The signaling type ("boost", "isdn" and others, this depends on the available signaling modules)
1447  * \param sig_cb The callback that the signaling stack will use to notify about events
1448  * \param ... variable argument list with "var", value sequence, the variable and values are signaling type dependant
1449  *        the last argument must be FTDM_TAG_END
1450  *
1451  * \retval FTDM_SUCCESS success 
1452  * \retval FTDM_FAIL failure 
1453  */
1454 FT_DECLARE(ftdm_status_t) ftdm_configure_span(ftdm_span_t *span, const char *type, fio_signal_cb_t sig_cb, ...);
1455 #define FTDM_TAG_END NULL
1456 
1457 
1458 /*! 
1459  * \brief Configure span with a signaling type
1460  *
1461  * \param span The span to configure
1462  * \param type The signaling type ("boost", "isdn" and others, this depends on the available signaling modules)
1463  * \param sig_cb The callback that the signaling stack will use to notify about events
1464  * \param parameters The array if signaling-specific parameters (the last member of the array MUST have its var member set to NULL, ie: .var = NULL)
1465  *
1466  * \retval FTDM_SUCCESS success 
1467  * \retval FTDM_FAIL failure 
1468  */
1469 FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(ftdm_span_t *span, const char *type, fio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters);
1470 
1471 /*! 
1472  * \brief Start the span signaling (must call ftdm_configure_span_signaling first)
1473  *
1474  * \note Even before this function returns you may receive signaling events!
1475  *       Never block in the signaling callback since it might be called in a thread
1476  *       that handles more than 1 call and therefore you would be blocking all the
1477  *       calls handled by that thread!
1478  *
1479  * \param span The span to start
1480  *
1481  * \retval FTDM_SUCCESS success 
1482  * \retval FTDM_FAIL failure 
1483  */
1484 FT_DECLARE(ftdm_status_t) ftdm_span_start(ftdm_span_t *span);
1485 
1486 
1487 /*! 
1488  * \brief Stop the span signaling (must call ftdm_span_start first)
1489  * \note certain signalings (boost signaling) does not support granular span start/stop
1490  * so it is recommended to always configure all spans and then starting them all and finally
1491  * stop them all (or call ftdm_global_destroy which takes care of stopping and destroying the spans at once).
1492  *
1493  * \param span The span to stop
1494  *
1495  * \retval FTDM_SUCCESS success 
1496  * \retval FTDM_FAIL failure 
1497  */
1498 FT_DECLARE(ftdm_status_t) ftdm_span_stop(ftdm_span_t *span);
1499 
1500 /*! 
1501  * \brief Register a custom I/O interface with the FreeTDM core
1502  *
1503  * \param io_interface the Interface to register
1504  *
1505  * \retval FTDM_SUCCESS success 
1506  * \retval FTDM_FAIL failure 
1507  */
1508 FT_DECLARE(ftdm_status_t) ftdm_global_add_io_interface(ftdm_io_interface_t *io_interface);
1509 
1510 /*! \brief Find a span by name */
1511 FT_DECLARE(ftdm_status_t) ftdm_span_find_by_name(const char *name, ftdm_span_t **span);
1512 
1513 /*! \brief Get the span id */
1514 FT_DECLARE(uint32_t) ftdm_span_get_id(const ftdm_span_t *span);
1515 
1516 /*! \brief Get the span name */
1517 FT_DECLARE(const char *) ftdm_span_get_name(const ftdm_span_t *span);
1518 
1519 /*! \brief Get iterator for the span channels
1520  *  \param span The span containing the channels
1521  *  \param iter Optional iterator. You can reuse an old iterator (not previously freed) to avoid the extra allocation of a new iterator.
1522  */
1523 FT_DECLARE(ftdm_iterator_t *) ftdm_span_get_chan_iterator(const ftdm_span_t *span, ftdm_iterator_t *iter);
1524 
1525 /*! 
1526  * \brief Execute a text command. The text command output will be returned and must be free'd 
1527  *
1528  * \param cmd The command to execute
1529  *
1530  * \retval FTDM_SUCCESS success 
1531  * \retval FTDM_FAIL failure 
1532  */
1533 FT_DECLARE(char *) ftdm_api_execute(const char *cmd);
1534 
1535 /*! 
1536  * \brief Create a configuration node
1537  *
1538  * \param name The name of the configuration node
1539  * \param node The node pointer to store the new node
1540  * \param parent The parent node if any, or NULL if no parent
1541  *
1542  * \return FTDM_SUCCESS success
1543  * \return FTDM_FAIL failure
1544  */
1545 FT_DECLARE(ftdm_status_t) ftdm_conf_node_create(const char *name, ftdm_conf_node_t **node, ftdm_conf_node_t *parent);
1546 
1547 /*! 
1548  * \brief Adds a new parameter to the specified configuration node
1549  *
1550  * \param node The configuration node to add the param-val pair to
1551  * \param param The parameter name
1552  * \param val The parameter value
1553  *
1554  * \return FTDM_SUCCESS success
1555  * \return FTDM_FAIL failure
1556  */
1557 FT_DECLARE(ftdm_status_t) ftdm_conf_node_add_param(ftdm_conf_node_t *node, const char *param, const char *val);
1558 
1559 /*! 
1560  * \brief Destroy the memory allocated for a configuration node (and all of its descendance)
1561  *
1562  * \param node The node to destroy
1563  *
1564  * \return FTDM_SUCCESS success
1565  * \return FTDM_FAIL failure
1566  */
1567 FT_DECLARE(ftdm_status_t) ftdm_conf_node_destroy(ftdm_conf_node_t *node);
1568 
1569 /*! 
1570  * \brief Create and configure channels in the given span
1571  *
1572  * \param span The span container
1573  * \param str The channel range null terminated string. "1-10", "24" etc
1574  * \param chan_config The basic channel configuration for each channel within the range
1575  * \param configured Pointer where the number of channels configured will be stored
1576  *
1577  * \return FTDM_SUCCESS success
1578  * \return FTDM_FAIL failure
1579  */
1580 FT_DECLARE(ftdm_status_t) ftdm_configure_span_channels(ftdm_span_t *span, const char *str, ftdm_channel_config_t *chan_config, unsigned *configured);
1581 
1582 /*! 
1583  * \brief Set the trunk type for a span
1584  *        This must be called before configuring any channels within the span
1585  *
1586  * \param span The span 
1587  * \param type The trunk type
1588  *
1589  */
1590 FT_DECLARE(void) ftdm_span_set_trunk_type(ftdm_span_t *span, ftdm_trunk_type_t type);
1591 
1592 /*! 
1593  * \brief Get the trunk type for a span
1594  *
1595  * \param span The span 
1596  *
1597  * \return The span trunk type
1598  */
1599 FT_DECLARE(ftdm_trunk_type_t) ftdm_span_get_trunk_type(const ftdm_span_t *span);
1600 
1601 /*! \brief For display debugging purposes you can display this string which describes the trunk type of a span */
1602 FT_DECLARE(const char *) ftdm_span_get_trunk_type_str(const ftdm_span_t *span);
1603 
1604 /*! 
1605  * \brief Return the channel identified by the provided id
1606  *
1607  * \param span The span where the channel belongs
1608  * \param chanid The channel id within the span
1609  *
1610  * \return The channel pointer if found, NULL otherwise
1611  */
1612 FT_DECLARE(ftdm_channel_t *) ftdm_span_get_channel(const ftdm_span_t *span, uint32_t chanid);
1613 
1614 /*! \brief Return the channel count number for the given span */
1615 FT_DECLARE(uint32_t) ftdm_span_get_chan_count(const ftdm_span_t *span);
1616 
1617 /*! \brief Set the caller data for a channel. Be sure to call this before ftdm_channel_call_place() */
1618 FT_DECLARE(ftdm_status_t) ftdm_channel_set_caller_data(ftdm_channel_t *ftdmchan, ftdm_caller_data_t *caller_data);
1619 
1620 /*! \brief Get the caller data for a channel, typically you need this when receiving FTDM_SIGEVENT_START */
1621 FT_DECLARE(ftdm_caller_data_t *) ftdm_channel_get_caller_data(ftdm_channel_t *channel);
1622 
1623 /*! \brief Get current state of a channel */
1624 FT_DECLARE(int) ftdm_channel_get_state(const ftdm_channel_t *ftdmchan);
1625 
1626 /*! \brief Get last state of a channel */
1627 FT_DECLARE(int) ftdm_channel_get_last_state(const ftdm_channel_t *ftdmchan);
1628 
1629 /*! \brief For display debugging purposes you can display this string which describes the current channel internal state */
1630 FT_DECLARE(const char *) ftdm_channel_get_state_str(const ftdm_channel_t *channel);
1631 
1632 /*! \brief For display debugging purposes you can display this string which describes the last channel internal state */
1633 FT_DECLARE(const char *) ftdm_channel_get_last_state_str(const ftdm_channel_t *channel);
1634 
1635 /*! \brief For display debugging purposes you can display this string which describes the history of the channel 
1636  *  \param channel The channel to get the history from
1637  *  \return History string for the channel. You must free the string with ftdm_free
1638  */
1639 FT_DECLARE(char *) ftdm_channel_get_history_str(const ftdm_channel_t *channel);
1640 
1641 /*! \brief Initialize channel state for an outgoing call
1642  *  \deprecated This API is only used for boost signaling
1643  */
1644 FT_DECLARE(ftdm_status_t) ftdm_channel_init(ftdm_channel_t *ftdmchan);
1645 
1646 /*! \brief Enable/disable blocking mode in the channels for this span */
1647 FT_DECLARE(ftdm_status_t) ftdm_span_set_blocking_mode(const ftdm_span_t *span, ftdm_bool_t enabled);
1648 
1649 /*! \brief Initialize the library */
1650 FT_DECLARE(ftdm_status_t) ftdm_global_init(void);
1651 
1652 /*! \brief Create spans and channels reading the freetdm.conf file */
1653 FT_DECLARE(ftdm_status_t) ftdm_global_configuration(void);
1654 
1655 /*! \brief Shutdown the library */
1656 FT_DECLARE(ftdm_status_t) ftdm_global_destroy(void);
1657 
1658 /*! \brief Set memory handler for the library */
1659 FT_DECLARE(ftdm_status_t) ftdm_global_set_memory_handler(ftdm_memory_handler_t *handler);
1660 
1661 /*! \brief Set the crash policy for the library */
1662 FT_DECLARE(void) ftdm_global_set_crash_policy(ftdm_crash_policy_t policy);
1663 
1664 /*! \brief Set the logger handler for the library */
1665 FT_DECLARE(void) ftdm_global_set_logger(ftdm_logger_t logger);
1666 
1667 /*! \brief Set the default logger level */
1668 FT_DECLARE(void) ftdm_global_set_default_logger(int level);
1669 
1670 /*! \brief Set the directory to look for modules */
1671 FT_DECLARE(void) ftdm_global_set_mod_directory(const char *path);
1672 
1673 /*! \brief Set the directory to look for configs */
1674 FT_DECLARE(void) ftdm_global_set_config_directory(const char *path);
1675 
1676 /*! \brief Check if the FTDM library is initialized and running */
1677 FT_DECLARE(ftdm_bool_t) ftdm_running(void);
1678 
1679 FT_DECLARE_DATA extern ftdm_logger_t ftdm_log;
1680 
1681 /*! \brief Basic transcoding function prototype */
1682 #define FIO_CODEC_ARGS (void *data, ftdm_size_t max, ftdm_size_t *datalen)
1683 #define FIO_CODEC_FUNCTION(name) FT_DECLARE_NONSTD(ftdm_status_t) name FIO_CODEC_ARGS
1684 typedef ftdm_status_t (*fio_codec_t) FIO_CODEC_ARGS ;
1685 
1686 /*! \brief Basic transcoding functions */
1687 FIO_CODEC_FUNCTION(fio_slin2ulaw);
1688 FIO_CODEC_FUNCTION(fio_ulaw2slin);
1689 FIO_CODEC_FUNCTION(fio_slin2alaw);
1690 FIO_CODEC_FUNCTION(fio_alaw2slin);
1691 FIO_CODEC_FUNCTION(fio_ulaw2alaw);
1692 FIO_CODEC_FUNCTION(fio_alaw2ulaw);
1693 
1694 #define FTDM_PRE __FILE__, __FUNCTION__, __LINE__
1695 #define FTDM_LOG_LEVEL_DEBUG 7
1696 #define FTDM_LOG_LEVEL_INFO 6
1697 #define FTDM_LOG_LEVEL_NOTICE 5
1698 #define FTDM_LOG_LEVEL_WARNING 4
1699 #define FTDM_LOG_LEVEL_ERROR 3
1700 #define FTDM_LOG_LEVEL_CRIT 2
1701 #define FTDM_LOG_LEVEL_ALERT 1
1702 #define FTDM_LOG_LEVEL_EMERG 0
1703 
1704 /*! \brief Log levels  */
1705 #define FTDM_LOG_DEBUG FTDM_PRE, FTDM_LOG_LEVEL_DEBUG
1706 #define FTDM_LOG_INFO FTDM_PRE, FTDM_LOG_LEVEL_INFO
1707 #define FTDM_LOG_NOTICE FTDM_PRE, FTDM_LOG_LEVEL_NOTICE
1708 #define FTDM_LOG_WARNING FTDM_PRE, FTDM_LOG_LEVEL_WARNING
1709 #define FTDM_LOG_ERROR FTDM_PRE, FTDM_LOG_LEVEL_ERROR
1710 #define FTDM_LOG_CRIT FTDM_PRE, FTDM_LOG_LEVEL_CRIT
1711 #define FTDM_LOG_ALERT FTDM_PRE, FTDM_LOG_LEVEL_ALERT
1712 #define FTDM_LOG_EMERG FTDM_PRE, FTDM_LOG_LEVEL_EMERG
1713 
1714 #ifdef __cplusplus
1715 } /* extern C */
1716 #endif
1717 
1718 #endif
1719 
1720 /* For Emacs:
1721  * Local Variables:
1722  * mode:c
1723  * indent-tabs-mode:t
1724  * tab-width:4
1725  * c-basic-offset:4
1726  * End:
1727  * For VIM:
1728  * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
1729  */

/* [<][>][^][v][top][bottom][index][help] */