📄 m2pa.c
字号:
/***************************************************************************** @(#) m2pa.c,v 0.7.8.1 2001/12/11 13:15:13 brian Exp ----------------------------------------------------------------------------- Copyright (C) 2001 OpenSS7 Corporation <http://www.openss7.com> All Rights Reserved. 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 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 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. Last Modified 2001/12/11 13:15:13 by brian ----------------------------------------------------------------------------- m2pa.c,v Revision 0.7.8.1 2001/12/11 13:15:13 brian Branched for new development. Revision 0.7.6.5 2001/12/07 08:37:28 brian Passes large quantities of test cases. Revision 0.7.6.4 2001/12/01 21:51:18 brian Going to shift to style1. Revision 0.7.6.3 2001/06/03 18:31:59 brian Made a few changes. Revision 0.7.6.2 2001/05/24 06:32:15 brian More work on M2PA. Revision 0.7.6.1 2001/05/23 09:53:00 brian Working up M2PA some more. Revision 0.7 2001/05/23 07:37:15 brian Working on M2PA per draft-ietf-sigtran-m2pa-02.txt *****************************************************************************/static char const ident[] = "SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:13";#define M2PA_DESCRIP "M2PA/SCTP STREAMS MODULE."#define M2PA_COPYRIGHT "Copyright (c) 2001 OpenSS7 Corp. All Rights Reserved."#define M2PA_DEVICES "Part of the OpenSS7 Stack for LiS STREAMS."#define M2PA_CONTACT "Brian Bidulock <bidulock@openss7.org>"#define M2PA_BANNER M2PA_DESCRIP "\n" \ M2PA_COPYRIGHT "\n" \ M2PA_DEVICES "\n" \ M2PA_CONTACT "\n"#ifdef MODULEMODULE_AUTHOR(M2PA_CONTACT);MODULE_DESCRIPTION(M2PA_DESCRIP);MODULE_SUPPORTED_DEVICE(M2PA_DEVICE);#define MODULE_STATIC static#else#define MOD_INC_USE_COUNT#define MOD_DEC_USE_COUNT#define MODULE_STATIC#endif#ifdef M2PA_DEBUGstatic int m2pa_debug = M2PA_DEBUG;#elsestatic int m2pa_debug = 2;#endif#ifndef M2PA_CMAJOR#define M2PA_CMAJOR 240#endif#define M2PA_NMINOR 255#ifdef LIS_2_12#define INT int#else#define INT void#endiftypedef void (*bufcall_fnc_t)(long);/* * ========================================================================= * * STREAMS Definitions * * ========================================================================= */static struct module_info m2pa_info ={ 0, /* Module ID number */ /* FIXME */ "m2pa", /* Module name */ 1, /* Min packet size accepted */ 512, /* Max packet size accepted */ 8*512, /* Hi water mark */ 1*512 /* Lo water mark */};static INT m2pa_rput (queue_t *, mblk_t *);static INT m2pa_rsrv (queue_t *);static int m2pa_open (queue_t *, dev_t *, int, int, cred_t *);static int m2pa_close(queue_t *, int, cred_t *);static struct qinit m2pa_rinit ={ m2pa_rput, /* Read put (msg from below) */ m2pa_rsrv, /* Read queue service */ m2pa_open, /* Each open */ m2pa_close, /* Last close */ NULL, /* Admin (not used) */ &m2pa_info, /* Information */ NULL /* Statistics */};static INT m2pa_wput (queue_t *, mblk_t *);static INT m2pa_wsrv (queue_t *);static struct qinit m2pa_winit ={ m2pa_wput, /* Write put (msg from above) */ m2pa_wsrv, /* Write queue service */ NULL, /* Each open */ NULL, /* Last close */ NULL, /* Admin (not used) */ &m2pa_info, /* Information */ NULL /* Statistics */};MODULE_STATIC struct streamtab m2pa_info ={ &m2pa_rinit, /* Upper read queue */ &m2pa_winit, /* Upper write queue */ NULL, /* Lower read queue */ NULL /* Lower write queue */};/* * ========================================================================= * * M2PA Private Structure * * ========================================================================= */#define M2PA_PRIV(__q) ((m2pa_t *)(__q)->q_ptr)typedef struct m2pa { struct m2pa *next; queue_t *rq; /* STREAM read queue */ queue_t *wq; /* STREAM write queue */ uint state; /* M2PA state */ uint t_state; /* T-Provider state */ sl_state_t sl_state; /* Signalling Link State */} m2pa_t;#define M2PA_IDLE 0#define M2PA_OUT_OF_SERVICE 1#define M2PA_NOT_ALIGNED 2#define M2PA_ALIGNED 3#define M2PA_ALIGNED_NOT_READY 4#define M2PA_PROVING 5#define M2PA_PROVING_FAILED 6#define M2PA_ALIGNED_READY 7#define M2PA_IN_SERVICE 8#define M2PA_LOC_EMERGENCY 0x0001#define M2PA_REM_EMERGENCY 0x0002#define M2PA_EMERGENCY (M2PA_LOC_EMERGENCY|M2PA_REM_EMERGENCY)#define M2PA_LOC_PROC_OUTAGE 0x0004#define M2PA_REM_PROC_OUTAGE 0x0008#define M2PA_PROC_OUTAGE (M2PA_LOC_PROC_OUTAGE|M2PA_REM_PROC_OUTAGE)#define M2PA_STATUS_OUT_OF_SERVICE (__constant_htonl(0))#define M2PA_STATUS_IN_SERVICE (__constant_htonl(1))#define M2PA_STATUS_PROCESSOR_OUTAGE (__constant_htonl(2))#define M2PA_STATUS_PROCESSOR_ENDED (__constant_htonl(3))#define M2PA_STATUS_BUSY (__constant_htonl(4))#define M2PA_STATUS_BUSY_ENDED (__constant_htonl(5))#define M2PA_STATUS_ALIGN (__constant_htonl(6))#define M2PA_STATUS_NORMAL_PROVING (__constant_htonl(7))#define M2PA_STATUS_EMERGENCY_PROVING (__constant_htonl(8))#define M2PA_STATUS_SIO 0#define M2PA_STATUS_SIN 1#define M2PA_STATUS_SIE 2#define M2PA_STATUS_SIOS 3#define M2PA_STATUS_SIPO 4#define M2PA_STATUS_SIB 5#define M2PA_STATUS_SIIS 6/* * ========================================================================= * * M2PA-Provider --> M2PA-User Primitives (M_CTL, M_PROTO, M_PCPROTO) * * ========================================================================= *//* * LMI_INFO_ACK * * Builds an LMI_INFO_ACK primiive given the current state of the Signalling * Link interface and the Physical Point of Appearance address to which the * interface is attached. * */static inline mblk_t *lmi_info_ack(uint state, caddr_t ppa_ptr, size_t ppa_len){ mblk_t *mp; lmi_ok_ack_t *p; if ( (mp = allocb(sizeof(*p)+ppa_len, BPRI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = (lmi_info_ack_t *)mp->b_wptr; p->lmi_primitive = LMI_INFO_ACK; p->lmi_version = 1; p->lmi_state = state; p->lmi_max_sdu = -1; p->lmi_min_sdu = 1; p->lmi_header_len = 0; p->lmi_ppa_style = LMI_STYLE2; mp->b_wptr += sizeof(*p); bcopy(ppa_ptr, mp->b_wptr, ppa_len); mp->b_wptr += ppa_len; } return(mp);}/* * LMI_OK_ACK * * Builds an LMI_OK_ACK primitive given the correct primitive and the state * of the interface. */static inline mblk_t *lmi_ok_ack(int prim, uint state){ mblk_t *mp; lmi_ok_ack_t *p; if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = (lmi_ok_ack_t *)mp->b_wptr; p->lmi_primitive = LMI_OK_ACK; p->lmi_correct_primitive= prim; p->lmi_state = state; mp->b_wptr += sizeof(*p); } return(mp);}/* * LMI_ERROR_ACK * * Builds an LMI_ERROR_ACK primitive given the errored primitive, the error, * reason and the state of the interface. */static inline mblk_t *lmi_error_ack(int prim, int err, int reason, uint state){ mblk_t *mp; lmi_error_ack_t *p; if ( (mp = allocb(sizeof(*p), BRPI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = (lmi_error_ack_t *)mp->b_wptr; p->lmi_primitive = LMI_ERROR_ACK; p->lmi_error_primitive = prim; p->lmi_errno = err; p->lmi_reason = reason; p->lmi_state = state; mp->b_wptr += sizeof(*p); } return(mp);}/* * LMI_ENABLE_CON * * Builds and LMI_ENABLE_CON primitive. */static inline mblk_t *lmi_enable_con(void){ mblk_t *mp; lmi_enable_con_t *p; if ( (mp = allocb(sizeof(*p), BRPI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = (lmi_enable_con_t *)mp->b_wptr; p->lmi_primitive = LMI_ENABLE_CON; p->lmi_state = LMI_ENABLED; mp->b_wptr += sizeof(*p); } return(mp);}/* * LMI_DISABLE_CON * * Builds an LMI_DISABLED_CON primitive. */static inline mblk_t *lmi_disable_con(void){ mblk_t *mp; lmi_disable_con_t *p; if ( (mp = allocb(sizeof(*p), BRPI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = (lmi_disable_con_t *)mp->b_wptr; p->lmi_primitive = LMI_ENABLE_CON; p->lmi_state = LMI_DISABLED; mp->b_wptr += sizeof(*p); } return(mp);}/* * LMI_ERROR_IND * * Builds an LMI_ERROR_IND primitive given the error, reason and state of the * interface. */static inline mblk_t *lmi_error_ind(int err, int reason, uint state){ mblk_t *mp; lmi_error_ind_t *p; if ( (mp = allocb(sizeof(*p), BRPI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = (lmi_error_ind_t *)mp->b_wptr; p->lmi_primitive = LMI_ERROR_ACK; p->lmi_errno = err; p->lmi_reason = reason; p->lmi_state = state; mp->b_wptr += sizeof(*p); } return(mp);}/* * LMI_STATS_IND * * Builds an LMI_STATS_IND primitive given the state interval. (This * primitive will probably be reworked.) * */static inline mblk_t *lmi_stats_ind(uint interval){ mblk_t *mp; lmi_stats_ind_t *p; if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PROTO; p = (lmi_stats_ind_t *)mp->b_wptr; p->lmi_primitive = LMI_STATS_IND; p->lmi_interval = interval; p->lmi_timestamp = jiffies; mp->b_wptr += sizeof(*p); } return(mp);}/* * LMI_EVENT_IND * * Builds an LMI_EVENT_IND primitive given the event object id and the * severity. (This primitive will probably be reworked.) */static inline mblk_t *lmi_event_ind(uint objectid, uint severity){ mblk_t *mp; lmi_event_ind_t *p; if ( (mp = allocb(sizeof(*p), BPRI_MED)) ) { mp->b_datap->db_type = M_PCPROTO; p = (lmi_event_ind_t *)mp->b_wptr; p->lmi_primitive = LMI_EVENT_IND; p->lmi_objectid = objectid; p->lmi_timestamp = jiffies; p->lmi_severity = severity; mp->b_wptr += sizeof(*p); } return(mp);}/* * SL_PDU_IND * * Builds a protocol data unit indication given the data which is contained * in the PDU. */static inline mblk_t *sl_pdu_ind(mblk_t *dp){ mblk_t *mp; sl_pdu_ind_t *p; if ( (mp = allocb(sizeof(*p), BPRI_HI)) ) { mp->b_datap->db_type = M_PROTO; p->sl_primitive = SL_PDU_IND; mp->b_wptr += sizeof(*p); mp->b_cont = dp; } return(mp);}/* * SL_LINK_CONGESTED_IND * * Builds a link congested indication given the congestion status and discard * status. */static inline mblk_t *sl_link_congested_ind(int cong, int disc){ mblk_t *mp; sl_link_congested_ind_t *p; if ( (mp = allocb(sizeof(*p), BPRI_HI)) ) { mp->b_datap->db_type = M_PCPROTO; p->sl_primitive = SL_LINK_CONGESTED_IND; p->sl_timestamp = jiffies; p->sl_cong_status = cong; p->sl_disc_status = disc; mp->b_wptr += sizeof(*p); } return(mp);}/* * SL_LINK_CONGESTION_CEASED_IND * * Build a link congestion ceased indication given the congestion status and * the discard status. */static inline mblk_t *sl_link_congestion_ceased_ind(int cong, int disc){ mblk_t *mp; sl_link_congestion_ceased_ind_t *p; if ( (mp = allocb(sizeof(*p), BPRI_HI)) ) { mp->b_datap->db_type = M_PCPROTO; p->sl_primitive = SL_LINK_CONGESTION_CEASED_IND; p->sl_timestamp = jiffies; p->sl_cong_status = cong; p->sl_disc_status = disc; mp->b_wptr += sizeof(*p); } return(mp);}/* * SL_RETREIVED_MESSAGE_IND * * Builds a retrieved message indication, given the M_DATA blocks of the * retrieved message. */static inline mblk_t *sl_retreived_message_ind(mblk_t *dp){ mblk_t *mp; sl_retrieved_message_ind_t *p; if ( (mp = allocb(sizeof(*p), BPRI_HI)) ) { mp->b_datap->db_type = M_PROTO; p->sl_primitive = SL_RETRIEVED_MESSAGE_IND; mp->b_wptr += sizeof(*p); mp->b_cont = dp; } return(mp);}/* * SL_RETREIVAL_COMPLETE_IND * * Builds a retrieval complete indication. */static inline mblk_t *sl_retreival_complete_ind(void){ mblk_t *mp; sl_retreival_complete_ind_t *p; if ( (mp = allocb(sizeof(*p), BPRI_HI)) ) { mp->b_datap->db_type = M_PROTO; p->sl_primitive = SL_RETREIVAL_COMPLETE_IND; mp->b_wptr += sizeof(*p); } return(mp);}/* * SL_RB_CLEARED_IND * * Builds a receive buffer cleared indication. */static inline mblk_t *sl_rb_cleared_ind(void){ mblk_t *mp; sl_rb_cleared_ind_t *p; if ( (mp = allocb(sizeof(*p), BPRI_HI)) ) { mp->b_datap->db_type = M_PROTO; p->sl_primitive = SL_RB_CLEARED_IND; mp->b_wptr += sizeof(*p); } return(mp);}/* * SL_BSNT_IND * * Builds a BSNT confirmation, returning the BSNT which was requested to be * retrieved. */static inline mblk_t *sl_bsnt_ind(int bsnt){ mblk_t *mp; sl_bsnt_ind_t *p; if ( (mp = allocb(sizeof(*p), BPRI_HI)) ) { mp->b_datap->db_type = M_PROTO;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -