📄 message.c
字号:
/* * Copyright (c) Eicon Networks, 2002. * This source file is supplied for the use with Eicon Networks range of DIVA Server Adapters. * Eicon File Revision : 2.1 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */#include "platform.h"#include "di_defs.h"#include "pc.h"#include "capi20.h"#include "divacapi.h"#include "mdm_msg.h"#include "divasync.h"#define FILE_ "MESSAGE.C"#define dprintf/*------------------------------------------------------------------*//* This is options supported for all adapters that are server by *//* XDI driver. Allo it is not necessary to ask it from every adapter*//* and it is not necessary to save it separate for every adapter *//* Macrose defined here have only local meaning *//*------------------------------------------------------------------*/static dword diva_xdi_extended_features = 0;#define DIVA_CAPI_USE_CMA 0x00000001#define DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR 0x00000002#define DIVA_CAPI_XDI_PROVIDES_NO_CANCEL 0x00000004#define DIVA_CAPI_XDI_PROVIDES_RX_DMA 0x00000008/* CAPI can request to process all return codes self only if: protocol code supports this && xdi supports this */#define DIVA_CAPI_SUPPORTS_NO_CANCEL(__a__) (((__a__)->manufacturer_features&MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)&& ((__a__)->manufacturer_features & MANUFACTURER_FEATURE_OK_FC_LABEL) && (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_NO_CANCEL))/*------------------------------------------------------------------*//* local function prototypes *//*------------------------------------------------------------------*/static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci);static void set_group_ind_mask (PLCI *plci);static void clear_group_ind_mask_bit (PLCI *plci, word b);static byte test_group_ind_mask_bit (PLCI *plci, word b);void AutomaticLaw(DIVA_CAPI_ADAPTER *);word CapiRelease(word);word CapiRegister(word);word api_put(APPL *, CAPI_MSG *);static word api_parse(byte *, word, byte *, API_PARSE *);static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out);static void api_load_msg(API_SAVE *in, API_PARSE *out);word api_remove_start(void);void api_remove_complete(void);static void plci_remove(PLCI *);static void diva_get_extended_adapter_features (DIVA_CAPI_ADAPTER * a);static void diva_ask_for_xdi_sdram_bar (DIVA_CAPI_ADAPTER *, IDI_SYNC_REQ *);void callback(ENTITY *);static void control_rc(PLCI *, byte, byte, byte, byte, byte);static void data_rc(PLCI *, byte);static void data_ack(PLCI *, byte);static void sig_ind(PLCI *);static void SendInfo(PLCI *, dword, byte * *, byte);static void SendSetupInfo(APPL *, PLCI *, dword, byte * *, byte);static void SendSSExtInd(APPL *, PLCI * plci, dword Id, byte * * parms);static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms);static void nl_ind(PLCI *);static byte connect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte connect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte connect_a_res(dword,word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte disconnect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte disconnect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte listen_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte info_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte info_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte alert_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte facility_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte facility_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte connect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte connect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte connect_b3_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte disconnect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte disconnect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte data_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte data_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte reset_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte reset_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte connect_b3_t90_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte select_b_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte manufacturer_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static byte manufacturer_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);static word get_plci(DIVA_CAPI_ADAPTER *);static void add_p(PLCI *, byte, byte *);static void add_s(PLCI * plci, byte code, API_PARSE * p);static void add_ss(PLCI * plci, byte code, API_PARSE * p);static void add_ie(PLCI * plci, byte code, byte * p, word p_length);static void add_d(PLCI *, word, byte *);static void add_ai(PLCI *, API_PARSE *);static word add_b1(PLCI *, API_PARSE *, word, word);static word add_b23(PLCI *, API_PARSE *);static word add_modem_b23 (PLCI * plci, API_PARSE* bp_parms);static void sig_req(PLCI *, byte, byte);static void nl_req_ncci(PLCI *, byte, byte);static void send_req(PLCI *);static void send_data(PLCI *);static word plci_remove_check(PLCI *);static void listen_check(DIVA_CAPI_ADAPTER *);static byte AddInfo(byte **, byte **, byte *, byte *);static byte getChannel(API_PARSE *);static void IndParse(PLCI *, word *, byte **, byte);static byte ie_compare(byte *, byte *);static word find_cip(DIVA_CAPI_ADAPTER *, byte *, byte *);static word CPN_filter_ok(byte *cpn,DIVA_CAPI_ADAPTER *,word);/* XON protocol helpers */static void channel_flow_control_remove (PLCI * plci);static void channel_x_off (PLCI * plci, byte ch, byte flag);static void channel_x_on (PLCI * plci, byte ch);static void channel_request_xon (PLCI * plci, byte ch);static void channel_xmit_xon (PLCI * plci);static int channel_can_xon (PLCI * plci, byte ch);static void channel_xmit_extended_xon (PLCI * plci);static byte SendMultiIE(PLCI * plci, dword Id, byte * * parms, byte ie_type, dword info_mask, byte setupParse);static word AdvCodecSupport(DIVA_CAPI_ADAPTER *, PLCI *, APPL *, byte);static void CodecIdCheck(DIVA_CAPI_ADAPTER *, PLCI *);static void SetVoiceChannel(PLCI *, byte *, DIVA_CAPI_ADAPTER * );static void VoiceChannelOff(PLCI *plci);static void adv_voice_write_coefs (PLCI *plci, word write_command);static void adv_voice_clear_config (PLCI *plci);static word get_b1_facilities (PLCI * plci, byte b1_resource);static byte add_b1_facilities (PLCI * plci, byte b1_resource, word b1_facilities);static void adjust_b1_facilities (PLCI *plci, byte new_b1_resource, word new_b1_facilities);static word adjust_b_process (dword Id, PLCI *plci, byte Rc);static void adjust_b1_resource (dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command);static void adjust_b_restore (dword Id, PLCI *plci, byte Rc);static void reset_b3_command (dword Id, PLCI *plci, byte Rc);static void select_b_command (dword Id, PLCI *plci, byte Rc);static void fax_connect_ack_command (dword Id, PLCI *plci, byte Rc);static void fax_edata_ack_command (dword Id, PLCI *plci, byte Rc);static void fax_connect_info_command (dword Id, PLCI *plci, byte Rc);static void fax_adjust_b23_command (dword Id, PLCI *plci, byte Rc);static void fax_disconnect_command (dword Id, PLCI *plci, byte Rc);static void hold_save_command (dword Id, PLCI *plci, byte Rc);static void retrieve_restore_command (dword Id, PLCI *plci, byte Rc);static void init_b1_config (PLCI *plci);static void clear_b1_config (PLCI *plci);static void dtmf_command (dword Id, PLCI *plci, byte Rc);static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);static void dtmf_confirmation (dword Id, PLCI *plci);static void dtmf_indication (dword Id, PLCI *plci, byte *msg, word length);static void dtmf_parameter_write (PLCI *plci);static void mixer_set_bchannel_id_esc (PLCI *plci, byte bchannel_id);static void mixer_set_bchannel_id (PLCI *plci, byte *chi);static void mixer_clear_config (PLCI *plci);static void mixer_notify_update (PLCI *plci, byte others);static void mixer_command (dword Id, PLCI *plci, byte Rc);static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);static void mixer_indication_coefs_set (dword Id, PLCI *plci);static void mixer_indication_xconnect_from (dword Id, PLCI *plci, byte *msg, word length);static void mixer_indication_xconnect_to (dword Id, PLCI *plci, byte *msg, word length);static void mixer_remove (PLCI *plci);static void ec_command (dword Id, PLCI *plci, byte Rc);static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);static void ec_indication (dword Id, PLCI *plci, byte *msg, word length);static void rtp_connect_b3_req_command (dword Id, PLCI *plci, byte Rc);static void rtp_connect_b3_res_command (dword Id, PLCI *plci, byte Rc);static int diva_get_dma_descriptor (PLCI *plci, dword *dma_magic);static void diva_free_dma_descriptor (PLCI *plci, int nr);/*------------------------------------------------------------------*//* external function prototypes *//*------------------------------------------------------------------*/extern byte MapController (byte);extern byte UnMapController (byte);#define MapId(Id) (((Id) & 0xffffff00L) | MapController ((byte)(Id)))#define UnMapId(Id) (((Id) & 0xffffff00L) | UnMapController ((byte)(Id)))void sendf(APPL *, word, dword, word, byte *, ...);void * TransmitBufferSet(APPL * appl, dword ref);void * TransmitBufferGet(APPL * appl, void * p);void TransmitBufferFree(APPL * appl, void * p);void * ReceiveBufferGet(APPL * appl, int Num);int fax_head_line_time (char *buffer);/*------------------------------------------------------------------*//* Global data definitions *//*------------------------------------------------------------------*/extern byte max_adapter;extern byte max_appl;extern DIVA_CAPI_ADAPTER * adapter;extern APPL * application;static byte remove_started = FALSE;static PLCI dummy_plci;static struct _ftable { word command; byte * format; byte (* function)(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);} ftable[] = { {_DATA_B3_R, "dwww", data_b3_req}, {_DATA_B3_I|RESPONSE, "w", data_b3_res}, {_INFO_R, "ss", info_req}, {_INFO_I|RESPONSE, "", info_res}, {_CONNECT_R, "wsssssssss", connect_req}, {_CONNECT_I|RESPONSE, "wsssss", connect_res}, {_CONNECT_ACTIVE_I|RESPONSE, "", connect_a_res}, {_DISCONNECT_R, "s", disconnect_req}, {_DISCONNECT_I|RESPONSE, "", disconnect_res}, {_LISTEN_R, "dddss", listen_req}, {_ALERT_R, "s", alert_req}, {_FACILITY_R, "ws", facility_req}, {_FACILITY_I|RESPONSE, "ws", facility_res}, {_CONNECT_B3_R, "s", connect_b3_req}, {_CONNECT_B3_I|RESPONSE, "ws", connect_b3_res}, {_CONNECT_B3_ACTIVE_I|RESPONSE, "", connect_b3_a_res}, {_DISCONNECT_B3_R, "s", disconnect_b3_req}, {_DISCONNECT_B3_I|RESPONSE, "", disconnect_b3_res}, {_RESET_B3_R, "s", reset_b3_req}, {_RESET_B3_I|RESPONSE, "", reset_b3_res}, {_CONNECT_B3_T90_ACTIVE_I|RESPONSE, "ws", connect_b3_t90_a_res}, {_CONNECT_B3_T90_ACTIVE_I|RESPONSE, "", connect_b3_t90_a_res}, {_SELECT_B_REQ, "s", select_b_req}, {_MANUFACTURER_R, "dws", manufacturer_req}, {_MANUFACTURER_I|RESPONSE, "dws", manufacturer_res}, {_MANUFACTURER_I|RESPONSE, "", manufacturer_res}};static byte * cip_bc[29][2] = { { "", "" }, /* 0 */ { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 1 */ { "\x02\x88\x90", "\x02\x88\x90" }, /* 2 */ { "\x02\x89\x90", "\x02\x89\x90" }, /* 3 */ { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 4 */ { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 5 */ { "\x02\x98\x90", "\x02\x98\x90" }, /* 6 */ { "\x04\x88\xc0\xc6\xe6", "\x04\x88\xc0\xc6\xe6" }, /* 7 */ { "\x04\x88\x90\x21\x8f", "\x04\x88\x90\x21\x8f" }, /* 8 */ { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 9 */ { "", "" }, /* 10 */ { "", "" }, /* 11 */ { "", "" }, /* 12 */ { "", "" }, /* 13 */ { "", "" }, /* 14 */ { "", "" }, /* 15 */ { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 16 */ { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 17 */ { "\x02\x88\x90", "\x02\x88\x90" }, /* 18 */ { "\x02\x88\x90", "\x02\x88\x90" }, /* 19 */ { "\x02\x88\x90", "\x02\x88\x90" }, /* 20 */ { "\x02\x88\x90", "\x02\x88\x90" }, /* 21 */ { "\x02\x88\x90", "\x02\x88\x90" }, /* 22 */ { "\x02\x88\x90", "\x02\x88\x90" }, /* 23 */ { "\x02\x88\x90", "\x02\x88\x90" }, /* 24 */ { "\x02\x88\x90", "\x02\x88\x90" }, /* 25 */ { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 26 */ { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 27 */ { "\x02\x88\x90", "\x02\x88\x90" } /* 28 */};static byte * cip_hlc[29] = { "", /* 0 */ "", /* 1 */ "", /* 2 */ "", /* 3 */ "", /* 4 */ "", /* 5 */ "", /* 6 */ "", /* 7 */ "", /* 8 */ "", /* 9 */ "", /* 10 */ "", /* 11 */ "", /* 12 */ "", /* 13 */ "", /* 14 */ "", /* 15 */ "\x02\x91\x81", /* 16 */ "\x02\x91\x84", /* 17 */ "\x02\x91\xa1", /* 18 */ "\x02\x91\xa4", /* 19 */ "\x02\x91\xa8", /* 20 */ "\x02\x91\xb1", /* 21 */ "\x02\x91\xb2", /* 22 */ "\x02\x91\xb5", /* 23 */ "\x02\x91\xb8", /* 24 */ "\x02\x91\xc1", /* 25 */ "\x02\x91\x81", /* 26 */ "\x03\x91\xe0\x01", /* 27 */ "\x03\x91\xe0\x02" /* 28 */};/*------------------------------------------------------------------*/#define V120_HEADER_LENGTH 1#define V120_HEADER_EXTEND_BIT 0x80#define V120_HEADER_BREAK_BIT 0x40#define V120_HEADER_C1_BIT 0x04#define V120_HEADER_C2_BIT 0x08#define V120_HEADER_FLUSH_COND (V120_HEADER_BREAK_BIT | V120_HEADER_C1_BIT | V120_HEADER_C2_BIT)static byte v120_default_header[] ={ 0x83 /* Ext, BR , res, res, C2 , C1 , B , F */};static byte v120_break_header[] ={ 0xc3 | V120_HEADER_BREAK_BIT /* Ext, BR , res, res, C2 , C1 , B , F */};/*------------------------------------------------------------------*//* API_PUT function *//*------------------------------------------------------------------*/word api_put(APPL * appl, CAPI_MSG * msg){ word i, j, k, l, n; word ret; byte c; byte controller; DIVA_CAPI_ADAPTER * a; PLCI * plci; NCCI * ncci_ptr; word ncci; CAPI_MSG *m; API_PARSE msg_parms[MAX_MSG_PARMS+1]; if (msg->header.length < sizeof (msg->header) || msg->header.length > MAX_MSG_SIZE) { dbug(1,dprintf("bad len")); return _BAD_MSG; } controller = (byte)((msg->header.controller &0x7f)-1); /* controller starts with 0 up to (max_adapter - 1) */ if ( controller >= max_adapter ) { dbug(1,dprintf("invalid ctrl")); return _BAD_MSG; } a = &adapter[controller]; plci = NULL; if ((msg->header.plci != 0) && (msg->header.plci <= a->max_plci) && !a->adapter_disabled) { dbug(1,dprintf("plci=%x",msg->header.plci)); plci = &a->plci[msg->header.plci-1]; ncci = GET_WORD(&msg->header.ncci); if (plci->Id && (plci->appl || (plci->State == INC_CON_PENDING) || (plci->State == INC_CON_ALERT)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -