#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <tiffio.h>
#include "spandsp/telephony.h"
#include "spandsp/logging.h"
#include "spandsp/bit_operations.h"
#include "spandsp/queue.h"
#include "spandsp/power_meter.h"
#include "spandsp/complex.h"
#include "spandsp/tone_generate.h"
#include "spandsp/async.h"
#include "spandsp/hdlc.h"
#include "spandsp/fsk.h"
#include "spandsp/v29rx.h"
#include "spandsp/v29tx.h"
#include "spandsp/v27ter_rx.h"
#include "spandsp/v27ter_tx.h"
#include "spandsp/t4.h"
#include "spandsp/t30_fcf.h"
#include "spandsp/t35.h"
#include "spandsp/t30.h"
Classes | |
struct | value_string_t |
Defines | |
#define | MAX_MESSAGE_TRIES 3 |
#define | ms_to_samples(t) (((t)*SAMPLE_RATE)/1000) |
#define | DISBIT1 0x01 |
#define | DISBIT2 0x02 |
#define | DISBIT3 0x04 |
#define | DISBIT4 0x08 |
#define | DISBIT5 0x10 |
#define | DISBIT6 0x20 |
#define | DISBIT7 0x40 |
#define | DISBIT8 0x80 |
#define | DEFAULT_TIMER_T0 60000 |
#define | DEFAULT_TIMER_T1 35000 |
#define | DEFAULT_TIMER_T2 7000 |
#define | DEFAULT_TIMER_T3 15000 |
#define | DEFAULT_TIMER_T4 3450 |
#define | DEFAULT_TIMER_T5 65000 |
#define | DEFAULT_TIMER_T6 5000 |
#define | DEFAULT_TIMER_T7 6000 |
#define | DEFAULT_TIMER_T8 10000 |
#define | FINAL_FLUSH_TIME 1000 |
#define | T30_V17_FALLBACK_START 0 |
#define | T30_V29_FALLBACK_START 3 |
#define | T30_V27TER_FALLBACK_START 6 |
Enumerations | |
enum | { T30_PHASE_IDLE = 0, T30_PHASE_A_CED, T30_PHASE_A_CNG, T30_PHASE_B_RX, T30_PHASE_B_TX, T30_PHASE_C_NON_ECM_RX, T30_PHASE_C_NON_ECM_TX, T30_PHASE_C_ECM_RX, T30_PHASE_C_ECM_TX, T30_PHASE_D_RX, T30_PHASE_D_TX, T30_PHASE_E, T30_PHASE_CALL_FINISHED } |
enum | { T30_STATE_ANSWERING = 1, T30_STATE_B, T30_STATE_C, T30_STATE_D, T30_STATE_D_TCF, T30_STATE_D_POST_TCF, T30_STATE_F_TCF, T30_STATE_F_CFR, T30_STATE_F_FTT, T30_STATE_F_DOC_NON_ECM, T30_STATE_F_POST_DOC_NON_ECM, T30_STATE_F_DOC_ECM, T30_STATE_F_POST_DOC_ECM, T30_STATE_F_POST_RCP_MCF, T30_STATE_F_POST_RCP_PPR, T30_STATE_F_POST_RCP_RNR, T30_STATE_R, T30_STATE_T, T30_STATE_I, T30_STATE_II, T30_STATE_II_Q, T30_STATE_III_Q_MCF, T30_STATE_III_Q_RTP, T30_STATE_III_Q_RTN, T30_STATE_IV, T30_STATE_IV_PPS_NULL, T30_STATE_IV_PPS_Q, T30_STATE_IV_PPS_RNR, T30_STATE_IV_CTC, T30_STATE_IV_EOR, T30_STATE_IV_EOR_RNR, T30_STATE_CALL_FINISHED } |
enum | { T30_MODE_SEND_DOC = 1, T30_MODE_RECEIVE_DOC } |
enum | { T30_COPY_QUALITY_GOOD = 0, T30_COPY_QUALITY_POOR, T30_COPY_QUALITY_BAD } |
Functions | |
const char * | t30_completion_code_to_str (int result) |
Convert a phase E completion code to a short text description. | |
void | t30_non_ecm_put_bit (void *user_data, int bit) |
Process a bit of received non-ECM image data. | |
void | t30_non_ecm_put_byte (void *user_data, int byte) |
Process a byte of received non-ECM image data. | |
void | t30_non_ecm_put_chunk (void *user_data, const uint8_t buf[], int len) |
Process a chunk of received non-ECM image data. | |
int | t30_non_ecm_get_bit (void *user_data) |
Get a bit of received non-ECM image data. | |
int | t30_non_ecm_get_byte (void *user_data) |
Get a byte of received non-ECM image data. | |
int | t30_non_ecm_get_chunk (void *user_data, uint8_t buf[], int max_len) |
Get a bit of received non-ECM image data. | |
void | t30_hdlc_accept (void *user_data, int ok, const uint8_t *msg, int len) |
Process a received HDLC frame. | |
void | t30_front_end_status (void *user_data, int status) |
Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.). | |
void | t30_timer_update (t30_state_t *s, int samples) |
Report the passage of time to the T.30 engine. | |
const char * | t30_frametype (uint8_t x) |
Return a text name for a T.30 frame type. | |
void | t30_decode_dis_dtc_dcs (t30_state_t *s, const uint8_t *pkt, int len) |
Decode a DIS, DTC or DCS frame, and log the contents. | |
int | t30_restart (t30_state_t *s) |
Restart a T.30 context. | |
int | t30_init (t30_state_t *s, int calling_party, t30_set_handler_t *set_rx_type_handler, void *set_rx_type_user_data, t30_set_handler_t *set_tx_type_handler, void *set_tx_type_user_data, t30_send_hdlc_handler_t *send_hdlc_handler, void *send_hdlc_user_data) |
Initialise a T.30 context. | |
void | t30_release (t30_state_t *s) |
Release a T.30 context. | |
t30_state_t * | t30_create (int calling_party, t30_set_handler_t *set_rx_type_handler, void *set_rx_type_user_data, t30_set_handler_t *set_tx_type_handler, void *set_tx_type_user_data, t30_send_hdlc_handler_t *send_hdlc_handler, void *send_hdlc_user_data) |
Create and initialise a T.30 context. | |
void | t30_free (t30_state_t *s) |
Free a T.30 context. | |
void | t30_terminate (t30_state_t *s) |
Cleanup a T.30 context if the call terminates. | |
void | t30_set_iaf_mode (t30_state_t *s, int iaf) |
Set Internet aware FAX (IAF) mode. | |
int | t30_set_header_info (t30_state_t *s, const char *info) |
Set the header information associated with a T.30 context. | |
int | t30_set_local_ident (t30_state_t *s, const char *id) |
Set the local identifier associated with a T.30 context. | |
int | t30_set_local_nsf (t30_state_t *s, const uint8_t *nsf, int len) |
int | t30_set_local_sub_address (t30_state_t *s, const char *sub_address) |
Set the sub-address associated with a T.30 context. | |
size_t | t30_get_sub_address (t30_state_t *s, char *sub_address) |
Get the sub-address associated with a T.30 context. | |
size_t | t30_get_header_info (t30_state_t *s, char *info) |
Get the header information associated with a T.30 context. | |
size_t | t30_get_local_ident (t30_state_t *s, char *id) |
Get the local identifier associated with a T.30 context. | |
size_t | t30_get_far_ident (t30_state_t *s, char *id) |
Get the remote identifier associated with a T.30 context. | |
const char * | t30_get_far_country (t30_state_t *s) |
Get the country of origin of the remote FAX machine associated with a T.30 context. | |
const char * | t30_get_far_vendor (t30_state_t *s) |
Get the name of the vendor of the remote FAX machine associated with a T.30 context. | |
const char * | t30_get_far_model (t30_state_t *s) |
Get the name of the model of the remote FAX machine associated with a T.30 context. | |
void | t30_get_transfer_statistics (t30_state_t *s, t30_stats_t *t) |
Get the current transfer statistics. | |
void | t30_set_phase_b_handler (t30_state_t *s, t30_phase_b_handler_t *handler, void *user_data) |
Set a callback function for T.30 phase B handling. | |
void | t30_set_phase_d_handler (t30_state_t *s, t30_phase_d_handler_t *handler, void *user_data) |
Set a callback function for T.30 phase D handling. | |
void | t30_set_phase_e_handler (t30_state_t *s, t30_phase_e_handler_t *handler, void *user_data) |
Set a callback function for T.30 phase E handling. | |
void | t30_set_document_handler (t30_state_t *s, t30_document_handler_t *handler, void *user_data) |
Set a callback function for T.30 end of document handling. | |
void | t30_set_rx_file (t30_state_t *s, const char *file, int stop_page) |
Set next receive file name. | |
void | t30_set_tx_file (t30_state_t *s, const char *file, int start_page, int stop_page) |
Set next transmit file name. | |
void | t30_set_supported_modems (t30_state_t *s, int supported_modems) |
Specify supported modems. | |
void | t30_set_receiver_not_ready (t30_state_t *s, int count) |
Specify a period of responding with receiver not ready. | |
void | t30_set_supported_compressions (t30_state_t *s, int supported_compressions) |
Specify supported compression types. | |
void | t30_set_supported_resolutions (t30_state_t *s, int supported_resolutions) |
Specify supported resolutions. | |
void | t30_set_supported_image_sizes (t30_state_t *s, int supported_image_sizes) |
Specify supported image sizes. | |
void | t30_set_ecm_capability (t30_state_t *s, int enabled) |
Select ECM capability. | |
void | t30_local_interrupt_request (t30_state_t *s, int state) |
Request a local interrupt of FAX exchange. |
const char* t30_completion_code_to_str | ( | int | result | ) |
Convert a phase E completion code to a short text description.
Convert a phase E completion code to a short text description.
result | The result code. |
t30_state_t* t30_create | ( | int | calling_party, | |
t30_set_handler_t * | set_rx_type_handler, | |||
void * | set_rx_type_user_data, | |||
t30_set_handler_t * | set_tx_type_handler, | |||
void * | set_tx_type_user_data, | |||
t30_send_hdlc_handler_t * | send_hdlc_handler, | |||
void * | send_hdlc_user_data | |||
) |
Create and initialise a T.30 context.
Create and initialise a T.30 context.
calling_party | TRUE if the context is for a calling party. FALSE if the context is for an answering party. |
void t30_decode_dis_dtc_dcs | ( | t30_state_t * | s, | |
const uint8_t * | dis, | |||
int | len | |||
) |
Decode a DIS, DTC or DCS frame, and log the contents.
Decode a DIS, DTC or DCS frame, and log the contents.
s | The T.30 context. | |
dis | A pointer to the frame to be decoded. | |
len | The length of the frame. |
const char* t30_frametype | ( | uint8_t | x | ) |
Return a text name for a T.30 frame type.
Return a text name for a T.30 frame type.
x | The frametype octet. |
void t30_free | ( | t30_state_t * | s | ) |
Free a T.30 context.
Free a T.30 context.
s | The T.30 context. |
void t30_front_end_status | ( | void * | user_data, | |
int | status | |||
) |
Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.).
Inform the T.30 engine of a status change in the front end (end of tx, rx signal change, etc.).
user_data | The T.30 context. | |
status | The type of status change which occured. |
const char* t30_get_far_country | ( | t30_state_t * | s | ) |
Get the country of origin of the remote FAX machine associated with a T.30 context.
Get the country of origin of the remote FAX machine associated with a T.30 context.
s | The T.30 context. |
size_t t30_get_far_ident | ( | t30_state_t * | s, | |
char * | id | |||
) |
Get the remote identifier associated with a T.30 context.
Get the remote FAX machine identifier associated with a T.30 context.
s | The T.30 context. | |
id | A pointer to a buffer for the identifier. The buffer should be at least 21 bytes long. |
const char* t30_get_far_model | ( | t30_state_t * | s | ) |
Get the name of the model of the remote FAX machine associated with a T.30 context.
Get the name of the model of the remote FAX machine associated with a T.30 context.
s | The T.30 context. |
const char* t30_get_far_vendor | ( | t30_state_t * | s | ) |
Get the name of the vendor of the remote FAX machine associated with a T.30 context.
Get the name of the vendor of the remote FAX machine associated with a T.30 context.
s | The T.30 context. |
size_t t30_get_header_info | ( | t30_state_t * | s, | |
char * | info | |||
) |
Get the header information associated with a T.30 context.
Get the header information associated with a T.30 context.
s | The T.30 context. | |
sub_address | A pointer to a buffer for the header information. The buffer should be at least 51 bytes long. |
size_t t30_get_local_ident | ( | t30_state_t * | s, | |
char * | id | |||
) |
Get the local identifier associated with a T.30 context.
Get the local FAX machine identifier associated with a T.30 context.
s | The T.30 context. | |
id | A pointer to a buffer for the identifier. The buffer should be at least 21 bytes long. |
size_t t30_get_sub_address | ( | t30_state_t * | s, | |
char * | sub_address | |||
) |
Get the sub-address associated with a T.30 context.
Get the sub-address associated with a T.30 context.
s | The T.30 context. | |
sub_address | A pointer to a buffer for the sub-address. The buffer should be at least 21 bytes long. |
void t30_get_transfer_statistics | ( | t30_state_t * | s, | |
t30_stats_t * | t | |||
) |
Get the current transfer statistics.
Get the current transfer statistics for the file being sent or received.
s | The T.30 context. | |
t | A pointer to a buffer for the statistics. |
void t30_hdlc_accept | ( | void * | user_data, | |
int | ok, | |||
const uint8_t * | msg, | |||
int | len | |||
) |
Process a received HDLC frame.
Process a received HDLC frame.
s | The T.30 context. | |
ok | TRUE if the frame was received without error. | |
msg | The HDLC message. | |
int | The length of the message, in octets. |
int t30_init | ( | t30_state_t * | s, | |
int | calling_party, | |||
t30_set_handler_t * | set_rx_type_handler, | |||
void * | set_rx_type_user_data, | |||
t30_set_handler_t * | set_tx_type_handler, | |||
void * | set_tx_type_user_data, | |||
t30_send_hdlc_handler_t * | send_hdlc_handler, | |||
void * | send_hdlc_user_data | |||
) |
Initialise a T.30 context.
Initialise a T.30 context.
s | The T.30 context. | |
calling_party | TRUE if the context is for a calling party. FALSE if the context is for an answering party. |
void t30_local_interrupt_request | ( | t30_state_t * | s, | |
int | state | |||
) |
Request a local interrupt of FAX exchange.
Request a local interrupt of FAX exchange.
s | The T.30 context. | |
state | TRUE to enable interrupt request, else FALSE. |
int t30_non_ecm_get_bit | ( | void * | user_data | ) |
Get a bit of received non-ECM image data.
Get a bit of received non-ECM image data.
user_data | An opaque pointer, which must point to the T.30 context. |
int t30_non_ecm_get_byte | ( | void * | user_data | ) |
Get a byte of received non-ECM image data.
Get a byte of received non-ECM image data.
user_data | An opaque pointer, which must point to the T.30 context. |
int t30_non_ecm_get_chunk | ( | void * | user_data, | |
uint8_t | buf[], | |||
int | max_len | |||
) |
Get a bit of received non-ECM image data.
Get a chunk of received non-ECM image data.
user_data | An opaque pointer, which must point to the T.30 context. | |
buf | The buffer to contain the data. | |
max_len | The maximum length of the chunk. |
void t30_non_ecm_put_bit | ( | void * | user_data, | |
int | bit | |||
) |
Process a bit of received non-ECM image data.
Process a bit of received non-ECM image data.
user_data | An opaque pointer, which must point to the T.30 context. | |
bit | The received bit. |
void t30_non_ecm_put_byte | ( | void * | user_data, | |
int | byte | |||
) |
Process a byte of received non-ECM image data.
Process a byte of received non-ECM image data.
user_data | An opaque pointer, which must point to the T.30 context. | |
byte | The received byte. |
void t30_non_ecm_put_chunk | ( | void * | user_data, | |
const uint8_t | buf[], | |||
int | len | |||
) |
Process a chunk of received non-ECM image data.
Process a chunk of received non-ECM image data.
user_data | An opaque pointer, which must point to the T.30 context. | |
buf | The buffer containing the received data. | |
len | The length of the data in buf. |
void t30_release | ( | t30_state_t * | s | ) |
Release a T.30 context.
Release a T.30 context.
s | The T.30 context. |
int t30_restart | ( | t30_state_t * | s | ) |
Restart a T.30 context.
Restart a T.30 context.
s | The T.30 context. |
void t30_set_document_handler | ( | t30_state_t * | s, | |
t30_document_handler_t * | handler, | |||
void * | user_data | |||
) |
Set a callback function for T.30 end of document handling.
Set a callback function for T.30 end of document handling.
s | The T.30 context. | |
handler | The callback function | |
user_data | An opaque pointer passed to the callback function. |
void t30_set_ecm_capability | ( | t30_state_t * | s, | |
int | enabled | |||
) |
Select ECM capability.
Specify if error correction mode (ECM) is allowed by a T.30 context.
s | The T.30 context. | |
enabled | TRUE for ECM capable, FALSE for not ECM capable. |
int t30_set_header_info | ( | t30_state_t * | s, | |
const char * | info | |||
) |
Set the header information associated with a T.30 context.
Set the header information associated with a T.30 context.
s | The T.30 context. | |
info | A pointer to the information string. |
void t30_set_iaf_mode | ( | t30_state_t * | s, | |
int | iaf | |||
) |
Set Internet aware FAX (IAF) mode.
Set Internet aware FAX (IAF) mode.
s | The T.30 context. | |
iaf | TRUE for IAF, or FALSE for non-IAF. |
int t30_set_local_ident | ( | t30_state_t * | s, | |
const char * | id | |||
) |
Set the local identifier associated with a T.30 context.
Set the local identifier associated with a T.30 context.
s | The T.30 context. | |
id | A pointer to the identifier. |
int t30_set_local_sub_address | ( | t30_state_t * | s, | |
const char * | sub_address | |||
) |
Set the sub-address associated with a T.30 context.
Set the sub-address associated with a T.30 context.
s | The T.30 context. | |
sub_address | A pointer to the sub-address. |
void t30_set_phase_b_handler | ( | t30_state_t * | s, | |
t30_phase_b_handler_t * | handler, | |||
void * | user_data | |||
) |
Set a callback function for T.30 phase B handling.
Set a callback function for T.30 phase B handling.
s | The T.30 context. | |
handler | The callback function | |
user_data | An opaque pointer passed to the callback function. |
void t30_set_phase_d_handler | ( | t30_state_t * | s, | |
t30_phase_d_handler_t * | handler, | |||
void * | user_data | |||
) |
Set a callback function for T.30 phase D handling.
Set a callback function for T.30 phase D handling.
s | The T.30 context. | |
handler | The callback function | |
user_data | An opaque pointer passed to the callback function. |
void t30_set_phase_e_handler | ( | t30_state_t * | s, | |
t30_phase_e_handler_t * | handler, | |||
void * | user_data | |||
) |
Set a callback function for T.30 phase E handling.
Set a callback function for T.30 phase E handling.
s | The T.30 context. | |
handler | The callback function | |
user_data | An opaque pointer passed to the callback function. |
void t30_set_receiver_not_ready | ( | t30_state_t * | s, | |
int | count | |||
) |
Specify a period of responding with receiver not ready.
Specify a period of responding with receiver not ready.
s | The T.30 context. | |
count | The number of times to report receiver not ready. |
void t30_set_rx_file | ( | t30_state_t * | s, | |
const char * | file, | |||
int | stop_page | |||
) |
Set next receive file name.
Specify the file name of the next TIFF file to be received by a T.30 context.
s | The T.30 context. | |
file | The file name | |
stop_page | The maximum page to receive. -1 for no restriction. |
void t30_set_supported_compressions | ( | t30_state_t * | s, | |
int | supported_compressions | |||
) |
Specify supported compression types.
Specify which compression types are supported by a T.30 context.
s | The T.30 context. | |
supported_compressions | Bit field list of the supported compression types. |
void t30_set_supported_image_sizes | ( | t30_state_t * | s, | |
int | supported_image_sizes | |||
) |
Specify supported image sizes.
Specify which images sizes are supported by a T.30 context.
s | The T.30 context. | |
supported_image_sizes | Bit field list of the supported widths and lengths. |
void t30_set_supported_modems | ( | t30_state_t * | s, | |
int | supported_modems | |||
) |
Specify supported modems.
Specify which modem types are supported by a T.30 context.
s | The T.30 context. | |
supported_modems | Bit field list of the supported modems. |
void t30_set_supported_resolutions | ( | t30_state_t * | s, | |
int | supported_resolutions | |||
) |
Specify supported resolutions.
Specify which resolutions are supported by a T.30 context.
s | The T.30 context. | |
supported_compressions | Bit field list of the supported resolutions. |
void t30_set_tx_file | ( | t30_state_t * | s, | |
const char * | file, | |||
int | start_page, | |||
int | stop_page | |||
) |
Set next transmit file name.
Specify the file name of the next TIFF file to be transmitted by a T.30 context.
s | The T.30 context. | |
file | The file name | |
start_page | The first page to send. -1 for no restriction. | |
stop_page | The last page to send. -1 for no restriction. |
void t30_terminate | ( | t30_state_t * | s | ) |
Cleanup a T.30 context if the call terminates.
Cleanup a T.30 context if the call terminates.
s | The T.30 context. |
void t30_timer_update | ( | t30_state_t * | s, | |
int | samples | |||
) |
Report the passage of time to the T.30 engine.
Report the passage of time to the T.30 engine.
s | The T.30 context. | |
samples | The time change in 1/8000th second steps. |