⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_udp2.c

📁 No7信令,我需要交换类似的代码, 请店长审核,谢谢了,急着交换,谢谢
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** @(#) sdl_udp2.c,v 0.7 2000/11/30 08:12:03 brian Exp -----------------------------------------------------------------------------     Copyright (C) 2000  Brian Bidulock.  All Rights Reserved.                                  PUBLIC LICENSE     This license is provided without fee, provided that the above copy-     right notice and this public license must be retained on all copies,     extracts, compilations and derivative works.  Use or distribution of     this work in a manner that restricts its use except as provided here     will render this license void.     The author(s) hereby waive any and all other restrictions in respect     of their copyright in this software and its associated documentation.     The authors(s) of this software place in the public domain any novel     methods or processes which are embodied in this software.     The author(s) undertook to write it for the sake of the advancement     of the Arts and Sciences, but it is provided as is, and the author(s)     will not take any responsibility in it. ----------------------------------------------------------------------------- Last Modified 2000/11/30 08:12:03 by brian sdl_udp2.c,v Revision 0.7  2000/11/30 08:12:03  brian Added driver implementations. *****************************************************************************/static char const ident[] = "sdl_udp2.c,v 0.7 2000/11/30 08:12:03 brian Exp";/* *  This is a UDP emulation of the Siganlling Data Link for use in testing and *  experimentation with the SS7 stack.  This driver obviates the need for a *  hardware card for testing the SS7 stack.  This driver is loosely based on *  the draft-bressler-sigtran-ipss7l2-00.txt SIGTRAN draft which specifies *  SS7 over TCP. * *  The UDP emulation behaves in the fashion that an actual driver would *  behave as an SDL provider; however, repetitions of FISUs and LSSUs are not *  transmitted continuously on the UDP link, only the first occurence of the *  repetition is transmitted and another occurence of the repetition is *  transmitted for every change in a received frame from UDP. * *  The UDP emulation can be run at full line (LAN) rate for transfering MSUs; *  however, for line rates below full network rate, traffic shaping is *  performed to throttle transmissions of MSUs to the average simulated rate *  in 10ms (1 tick) bursts. */#define SDL_DESCRIP   "SS7/SDL/UDP: (Signalling Data Link over UDP) STREAMS DRIVER."#define SDL_COPYRIGHT "Copyright (c) 1997-2000 Brian Bidulock.  All Rights Reserved."#define SDL_DEVICES   "Supports Linux Kernel UDP sockets."#define SDL_CONTACT   "Brian Bidulock <bidulock@openss7.org>"#define SDL_BANNER    SDL_DESCRIP   "\n" \                      SDL_COPYRIGHT "\n" \                      SDL_DEVICES   "\n" \                      SDL_CONTACT   "\n"#ifdef MODULEMODULE_AUTHOR(SDL_CONTACT);MODULE_DESCRIPTION(SDL_DESCRIP);MODULE_SUPPORTED_DEVICES(SDL_DEVICES);#define MODULE_STATIC static#else#define MOD_INC_USE_COUNT#define MOD_DEC_USE_COUNT#define MODULE_STATIC#endif#ifndef SDL_DEBUG#define SDL_DEBUG 2#endifint sdl_debug = SDL_DEBUG;#define SDL_MOD_ID      0x1111#define SDL_MOD_NAME    "sdl_udp"// #define SDL_MIN_SDU     3// #define SDL_MAX_SDU     277// #define SDL_HIWATER     1// #define SDL_LOWATER     0#define SDL_C_MAJOR     0   /* FIXNE: pick something    */#define SDL_N_MINOR     256 /* as many as possible      */static int sdl_udp_major = SDL_C_MAJOR;typedef struct {    struct sdl_config   config;     /* set configuration */    struct sockaddr_in  loc_addr;   /* local  ip/port   */    struct sockaddr_in  rem_addr;   /* remote ip/port   */    struct socket       *udpsock;   /* UDP socket       */    signed long int     timestamp;  /* last tick        */    signed long int     tickbytes;  /* bytes per tick   */    signed long int     bytecount;  /* bytes this tick  */    spinlock_t          dev_lock;   /* per device lock  */    mblk_t              *freehead;  /* spare buffers    */    mblk_t              **freetail; /* buf tail ptr     */    struct sdl_dcalls   *dcalls;    /* driver calls     */} sdl_udpdev_t;/* *  ========================================= * *  DEVICE SPECIFIC Procedures * *  ========================================= *//* *  ----------------------------------------- * *  IOCTL * *  ----------------------------------------- */static int sdl_udp_ioctl(sdl_t *sdl, int cmd, void *arg, int size){    sdl_device_t *dev = &sdl->device;    sdl_udpdev_t *prv = dev->priv;    sdl_config_t *ureq = NULL;    sdl_ulong uarg = 0;    switch (cmd) {        case SDL_IOCTCONFIG:        case SDL_IOCSCONFIG:            if ( !arg || size < sizeof(sdl_config_t) ) return EINVAL;            ureq = arg;            break;        case SDL_IOCSIFTYPE:        case SDL_IOCSGRPTYPE:        case SDL_IOCSIFMODE:        case SDL_IOCSIFRATE:        case SDL_IOCSIFCLOCK:        case SDL_IOCSIFCODING:        case SDL_IOCSIFLEADS:        case SDL_IOCCIFLEADS:            if ( !arg || size < sizeof(sdl_ulong) ) return EINVAL;            uarg = *(sdl_ulong *)arg;            break;        case SDL_IOCCCONFIG:        case SDL_IOCCMRESET:        case SDL_IOCIFRESET:        case SDL_IOCCDISCTX:        case SDL_IOCCCONNTX:            break;    }    switch (cmd) {        case SDL_IOCTCONFIG:        case SDL_IOCSCONFIG:        case SDL_IOCCCONFIG:        case SDL_IOCCMRESET:        case SDL_IOCIFRESET:        case SDL_IOCSIFTYPE:            if ( uarg != SDL_TYPE_PACKET ) return EINVAL;            return(0);        case SDL_IOCSGRPTYPE:            if ( uarg != SDL_GTYPE_UDP ) return EINVAL;            return(0);        case SDL_IOCSIFMODE:            if ( uarg != SDL_MODE_PEER ) return EINVAL;            return(0);        case SDL_IOCSIFRATE:            {                int tdiff;                if ( uarg < 800L || uarg > 100000000L ) return EINVAL;                dev->config.ifrate = uarg;                prv->config.ifrate = uarg;                if ( (tdiff = prv->timestamp - jiffies) > 0 )                    prv->bytecount += prv->tickbytes * tdiff;                else                    prv->bytecount = 0;                prv->timestamp = jiffies;                prv->tickbytes = uarg/HZ/8;                while ( prv->bytecount >= prv->tickbytes ) {                    prv->bytecount -= prv->tickbytes;                    prv->timestamp++;                }                return(0);            }        case SDL_IOCSIFCLOCK:            if ( uarg != SDL_CLOCK_SHAPER ) return EINVAL;            return(0);        case SDL_IOCSIFCODING:            if ( uarg != SDL_CODING_NONE ) return EINVAL;            return(0);        case SDL_IOCSIFLEADS:        case SDL_IOCCIFLEADS:            if ( uarg ) return EINVAL;            return(0);        case SDL_IOCCDISCTX:            dev->config.ifflags &= ~SDL_FLAGS_IFTX;            prv->config.ifflags &= ~SDL_FLAGS_IFTX;            return(0);        case SDL_IOCCCONNTX:            dev->config.ifflags |= SDL_FLAGS_IFTX;            prv->config.ifflags |= SDL_FLAGS_IFTX;            return(0);    }    return EOPNOTSUPP;}static sdl_device_t sdl_device_default{    SDL_TYPE_PACKET,    /* iftype   */    SDL_GTYPE_UDP,      /* ifgtype  */    SDL_MODE_PEER,      /* ifmode   */    1544000,            /* ifrate   */    SDL_CLOCK_SHAPER,   /* ifclock  */    SDL_CODING_NONE,    /* ifcoding */    0,                  /* ifleads  */    0,                  /* ifindex  */    0,                  /* irq      */    0,                  /* iobase   */    0,                  /* dma_rx   */    0                   /* dma_tx   */};static inline intsdl_udp_open(sdl_device_t *dev){    if ( (dev->priv = kmalloc(sizeof(sdl_udpdev_t), GFP_KERNEL)) )    {        sdl_udpdev_t *devp = dev->priv;        bzero(devp, sizeof(*devp));        bcopy(dev, &sdl_device_default, sizeof(*dev));        devp->timestamp = jiffies;        devp->tickbytes = 1544000/HZ/8;        devp->bytecount = 0;        return(0);    }    return ENOMEM;}static voidsdl_udp_close(sdl_t *sdl){    if (sdl->device.priv) kfree(sdl->device.priv);    sdl->device.priv = NULL;}static voidsdl_udp_attach(sdl_t *sdl){}static voidsdl_udp_detach(sdl_t *sdl){}static void sdl_udp_data_ready(struct sock *, int);static intsdl_udp_enable(sdl_t *sdl){    int err;    struct socket *sock = NULL;    sdl_device_t *dev = &sdl->device;    sdl_udpdev_t *prv = dev->priv;    struct sockaddr *sa = (struct sockaddr *)prv->loc_addr;    if ( (err = sock_create(PF_INET, SOCK_DGRAM, 0, &sock)) < 0 )        return err;    sock->sk->reuse = 1;    /* FIXME: check this */    sock->sk->allocation = GFP_ATOMIC;    if ( (err = sock->bind(sock, sa, sizeof(*sa))) < 0 ) {        sock_release(sock);        return err;    }    sock->protinfo.destruct_hook = sdl; /* might be bad idea */    sock->sk->data_ready = sdl_udp_data_ready;    prv->udpsock = sock;    sdl->state = SDL_ENABLED;    return (0);}static intsdl_udp_disable(sdl_t *sdl){    sdl_udpdev_t *prv = sdl->device.priv;    struct socket *sock = prv->udpsock;    prv->config.ifflags &= ~SDL_FLAGS_IFTX;    sdl->statem.deadt_state = SDL_STATE_IDLE;    if ( sock ) {        sock->protinfo.destruct_hook = NULL;        sock_release(sock);        prv->udpsock = NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -