/* * HS X.25 Protocol Stack. Developed by Hillstone Software (http://www.hillstone-software.com) */ #ifndef _HS_X25_API_H #define _HS_X25_API_H #define HS_MAX_NUA 15 // max NUA length #define HS_MAX_FAC 255 // max facility length #define HS_MAX_CUD 128 // max call user data length typedef enum { T20TMR, T21TMR, T22TMR, T23TMR, T10TMR, T11TMR, T12TMR, T13TMR, } hs_x25_tid_t; typedef enum { HS_X25_RC_OK, // success HS_X25_RC_NOLINK, // could not allocate new l2 link HS_X25_RC_NO_VC, // no free vc available HS_X25_RC_DL_INIT_FAIL, // data link layer init failed HS_X25_RC_INV_PAR, // invalid parameters HS_X25_RC_TOO_LONG, // packet too long HS_X25_RC_DL_LIS_FAIL, // DL Listen failed HS_X25_RC_TXQ_FULL, // Transmit queue is full HS_X25_RC_INV_PKTSIZE, // Invalid packet size HS_X25_RC_INV_WSIZE, // invalid window size HS_X25_RC_TX_PENDING, HS_X25_RC_FAIL, HS_X25_RC_BUF_TOO_BIG, } hs_x25_rc_t; typedef enum { HS_X25_EV_CONN_FAIL_PKTLR, // Connect failed, packet layer not ready HS_X25_EV_PKTLR_DOWN, // Packet layer down as result of physical layer down HS_X25_EV_PKTLR_RESTARTED, // Packet layer restarted (result of restart from the line) HS_X25_EV_CALL_CONNECTED, // X.25 SVC connected HS_X25_EV_CALL_CLEAR_COMPLETE, // X.25 SVC clearing completed HS_X25_EV_CALL_CLEARED, // X.25 SVC cleared by network HS_X25_EV_DATA, // X.25 data received HS_X25_EV_DATA_EXP, // X.25 Expedited data received HS_X25_EV_EXP_DATA_TX_FAIL, // cannot send expedited data, previous exp data not acknowledged HS_X25_EV_EXP_DATA_DELIVERED, // expedited data delivered to remote end HS_X25_EV_CALL_CLEARED_T13, // X.25 SVC cleared - no answer to call indication HS_X25_EV_BUF_TX_FAIL, // buffer not transmitted and must be released HS_X25_EV_INCOMING_CALL_CONNECTED, // incoming call connected (HsX25Listen completed) } hs_x25_ev_t; typedef void hs_x25_timer_callback_t(long handle); /* * Start timer * handle - HsX25 handle * secs - timeout in seconds * callback - timer expired callback address (function in HsX25 code) * tid - timer id * return - timer handle */ typedef long hs_x25_start_timer_t(long handle, unsigned long secs, hs_x25_timer_callback_t *callback, int tid); /* * Stop Timer * handle - timer handle * tid - timer id */ typedef void hs_x25_stop_timer_t(long handle, int tid); typedef void hs_x25_event_callback_t(long handle, int ev, long arg1, long arg2); typedef struct { hs_x25_start_timer_t *start_timer; hs_x25_stop_timer_t *stop_timer; hs_x25_event_callback_t *event_cb; } hs_x25_api_t; typedef enum { HS_X25_OPT_NORMAL =0, HS_X25_OPT_L2_LOOP =1, } hs_x25_opt_t; typedef void hs_trace_cb_t(int is_rx, unsigned char *buf, int len, long arg); typedef struct { hs_x25_api_t api; int opt; int is_rfc1613; // 1=CISCO mode XOT, 0=Proprietory bridge mode XOT unsigned char *rfc1613_peer_ip; int is_dce; int pktsize; int wsize; hs_trace_cb_t *trc_fn; int hi_incoming_lcn; // high LCN for incoming calls int lo_incoming_lcn; // low LCN for incoming calls int support_dbit; // set D bit ON in call accept } hs_x25_init_t; /* configuration structure */ typedef struct { int t10_val; int t11_val; int t12_val; int t13_val; int t20_val; int t20_retry; int t21_val; int t22_val; int t23_val; int pktsize; // configured packet size in bytes (size of DATA payload) int wsize; // configured window size int hi_incoming_lcn; // high LCN for incoming calls int lo_incoming_lcn; // low LCN for incoming calls int support_dbit; // set D bit ON in call accept } hs_x25_cfg_t; typedef struct { long l2_addr; long arg; unsigned char called[HS_MAX_NUA+1]; unsigned char calling[HS_MAX_NUA+1]; unsigned char facility_buf[HS_MAX_FAC]; unsigned char facility_len; unsigned char call_user_data[HS_MAX_CUD]; int cud_len; int dbit; } hs_x25_conn_t; /* listen structure */ typedef struct { long l2_addr; // link identifier long arg; // in case of XOT, listening TCP port number int take_any_call; // if this flag is set, addresses below are ignored and any call is accepted unsigned char called[HS_MAX_NUA]; // one byte per digit, e.g 0x31 0x32 0x33 etc int called_len; // called address length unsigned char calling[HS_MAX_NUA]; // one byte per digit, e.g 0x31 0x32 0x33 etc int calling_len; //calling address length } hs_x25_listen_t; /* data structure */ typedef struct { unsigned char *bufp; int len; } hs_x25data_t; typedef struct { int lci; int pti; unsigned char *pkt; int len; int Pr; int Ps; unsigned char *pktname; } hs_x25_pkt_info_t; typedef enum { HS_X25_RC_DECODE_UNSPEC, // unspecified error HS_X25_RC_DECODE_OK, // packet decode correct HS_X25_RC_DECODE_SHORT, // packet too short HS_X25_RC_DECODE_INV_GFI, // invalid GFI or PTI HS_X25_RC_DECODE_LCI_UNASSIGN, // packet on unassigned logical channel HS_X25_RC_DECODE_LONG, // packet too long } hs_x25_packet_decode_err_t; typedef enum { /* events coming from above (user app) */ HS_X25_CONNECT, // user request to establish outgoing call HS_X25_LISTEN, // user request to listen for incoming call HS_X25_DATA, // send data packet HS_X25_DATA_EXP, // send expedited data (bypass flow control) HS_X25_DISCONNECT, // disconnect call from user /* data link related events */ HS_X25_DL_RELEASE, // data link disconnected HS_X25_DL_CONNECT, // data link is up HS_X25_DL_DATA, // data received from data link /* events generated based on reception from the line */ HS_X25_CALL_ACCEPTED, // call connected or call acepted HS_X25_CALL_REQ, // call request or call indication HS_X25_RESTART_REQ, // restart request or restart indication HS_X25_RESTART_CNF, // restart confirmation HS_X25_RR, // receiver ready HS_X25_RNR, // receiver not ready HS_X25_DAT, // data from line HS_X25_CLEAR_CNF, // clear confirmation from line HS_X25_CLEAR_REQ, // clear request or indication from line HS_X25_INT_CNF, // interrupt confirmation from line HS_X25_INT_REQ, // interrupt request or indication from line HS_X25_RESET_REQ, // reset request or indications from line HS_X25_RESET_CNF, // reset confirm from line /* internal */ HS_X25_TICK, HS_X25_RNR_CONDITON, // set or clear RNR condition } hs_x25_fsm_events_t; typedef struct { long data; long rr; long rnr; long reset; long intr; } tx_rx_t; typedef struct { int lci; tx_rx_t tx; tx_rx_t rx; unsigned char *st; int w; } hs_x25_stats_t; /* * Initialise HS X.25 Protocol */ extern int HsX25Init(hs_x25_init_t *init); /* * Initiate outgoing X.25 call */ extern int HsX25Connect(hs_x25_conn_t *conn, long *handle, int *lci); /* * Submit a listen request for incoming X.25 call */ extern int HsX25Listen(hs_x25_listen_t *listen); /* * Clear X.25 Call */ extern int HsX25Clear(long handle); /* * Send X.25 Data sequence */ extern int HsX25Data(long handle, unsigned char *buf, int len, int qbit); /* * Send expedited data (Interrupt) */ extern int HsX25DataExp(long handle, unsigned char *buf, int len); /* * Send RNR (signal receiver not ready) */ extern int HsX25Rnr(long handle, int on); extern int HsX25Tick(void); /* * Flush listen queue */ extern int HsX25FlushListenQueue(long l2_addr); /* * Close all interfaces */ extern void HsX25ShutDown(void); /* * Configure X.25 Stack */ extern int HsX25Config(hs_x25_cfg_t *cfg); extern int HsX25DecodePkt(unsigned char *pkt, int len, int *ev, hs_x25_pkt_info_t *info, int need_name); extern void HsX25GetStats(long handle, hs_x25_stats_t *stats); #endif /* _HS_X25_API_H */