/*****************************************************************************
|
/*****************************************************************************
|
* af_wanpipe.c WANPIPE(tm) Secure Socket Layer.
|
* af_wanpipe.c WANPIPE(tm) Secure Socket Layer.
|
*
|
*
|
* Author: Nenad Corbic <ncorbic@sangoma.com>
|
* Author: Nenad Corbic <ncorbic@sangoma.com>
|
*
|
*
|
* Copyright: (c) 2000 Sangoma Technologies Inc.
|
* Copyright: (c) 2000 Sangoma Technologies Inc.
|
*
|
*
|
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
* as published by the Free Software Foundation; either version
|
* as published by the Free Software Foundation; either version
|
* 2 of the License, or (at your option) any later version.
|
* 2 of the License, or (at your option) any later version.
|
* ============================================================================
|
* ============================================================================
|
* Due Credit:
|
* Due Credit:
|
* Wanpipe socket layer is based on Packet and
|
* Wanpipe socket layer is based on Packet and
|
* the X25 socket layers. The above sockets were
|
* the X25 socket layers. The above sockets were
|
* used for the specific use of Sangoma Technoloiges
|
* used for the specific use of Sangoma Technoloiges
|
* API programs.
|
* API programs.
|
* Packet socket Authors: Ross Biro, Fred N. van Kempen and
|
* Packet socket Authors: Ross Biro, Fred N. van Kempen and
|
* Alan Cox.
|
* Alan Cox.
|
* X25 socket Author: Jonathan Naylor.
|
* X25 socket Author: Jonathan Naylor.
|
* ============================================================================
|
* ============================================================================
|
* Apr 25, 2000 Nenad Corbic o Added the ability to send zero length packets.
|
* Apr 25, 2000 Nenad Corbic o Added the ability to send zero length packets.
|
* Mar 13, 2000 Nenad Corbic o Added a tx buffer check via ioctl call.
|
* Mar 13, 2000 Nenad Corbic o Added a tx buffer check via ioctl call.
|
* Mar 06, 2000 Nenad Corbic o Fixed the corrupt sock lcn problem.
|
* Mar 06, 2000 Nenad Corbic o Fixed the corrupt sock lcn problem.
|
* Server and client applicaton can run
|
* Server and client applicaton can run
|
* simultaneously without conflicts.
|
* simultaneously without conflicts.
|
* Feb 29, 2000 Nenad Corbic o Added support for PVC protocols, such as
|
* Feb 29, 2000 Nenad Corbic o Added support for PVC protocols, such as
|
* CHDLC, Frame Relay and HDLC API.
|
* CHDLC, Frame Relay and HDLC API.
|
* Jan 17, 2000 Nenad Corbic o Initial version, based on AF_PACKET socket.
|
* Jan 17, 2000 Nenad Corbic o Initial version, based on AF_PACKET socket.
|
* X25API support only.
|
* X25API support only.
|
*
|
*
|
******************************************************************************/
|
******************************************************************************/
|
|
|
#include <linux/version.h>
|
#include <linux/version.h>
|
#include <linux/config.h>
|
#include <linux/config.h>
|
#include <linux/types.h>
|
#include <linux/types.h>
|
#include <linux/sched.h>
|
#include <linux/sched.h>
|
#include <linux/mm.h>
|
#include <linux/mm.h>
|
#include <linux/fcntl.h>
|
#include <linux/fcntl.h>
|
#include <linux/socket.h>
|
#include <linux/socket.h>
|
#include <linux/in.h>
|
#include <linux/in.h>
|
#include <linux/inet.h>
|
#include <linux/inet.h>
|
#include <linux/netdevice.h>
|
#include <linux/netdevice.h>
|
#include <linux/poll.h>
|
#include <linux/poll.h>
|
#include <linux/wireless.h>
|
#include <linux/wireless.h>
|
#include <linux/kmod.h>
|
#include <linux/kmod.h>
|
#include <net/ip.h>
|
#include <net/ip.h>
|
#include <net/protocol.h>
|
#include <net/protocol.h>
|
#include <linux/skbuff.h>
|
#include <linux/skbuff.h>
|
#include <net/sock.h>
|
#include <net/sock.h>
|
#include <linux/errno.h>
|
#include <linux/errno.h>
|
#include <linux/timer.h>
|
#include <linux/timer.h>
|
#include <asm/system.h>
|
#include <asm/system.h>
|
#include <asm/uaccess.h>
|
#include <asm/uaccess.h>
|
#include <linux/module.h>
|
#include <linux/module.h>
|
#include <linux/init.h>
|
#include <linux/init.h>
|
#include <linux/wanpipe.h>
|
#include <linux/wanpipe.h>
|
#include <linux/if_wanpipe.h>
|
#include <linux/if_wanpipe.h>
|
#include <linux/pkt_sched.h>
|
#include <linux/pkt_sched.h>
|
#include <linux/tcp.h>
|
#include <linux/tcp.h>
|
#include <linux/if_wanpipe_common.h>
|
#include <linux/if_wanpipe_common.h>
|
#include <linux/sdla_x25.h>
|
#include <linux/sdla_x25.h>
|
|
|
#ifdef CONFIG_INET
|
#ifdef CONFIG_INET
|
#include <net/inet_common.h>
|
#include <net/inet_common.h>
|
#endif
|
#endif
|
|
|
#define SLOW_BACKOFF 0.1*HZ
|
#define SLOW_BACKOFF 0.1*HZ
|
#define FAST_BACKOFF 0.01*HZ
|
#define FAST_BACKOFF 0.01*HZ
|
|
|
//#define PRINT_DEBUG
|
//#define PRINT_DEBUG
|
#ifdef PRINT_DEBUG
|
#ifdef PRINT_DEBUG
|
#define DBG_PRINTK(format, a...) printk(format, ## a)
|
#define DBG_PRINTK(format, a...) printk(format, ## a)
|
#else
|
#else
|
#define DBG_PRINTK(format, a...)
|
#define DBG_PRINTK(format, a...)
|
#endif
|
#endif
|
|
|
#if defined(LINUX_2_1)
|
#if defined(LINUX_2_1)
|
#define dev_put(a)
|
#define dev_put(a)
|
#define __sock_put(a)
|
#define __sock_put(a)
|
#define sock_hold(a)
|
#define sock_hold(a)
|
#define DECLARE_WAITQUEUE(a,b) \
|
#define DECLARE_WAITQUEUE(a,b) \
|
struct wait_queue a = { b, NULL }
|
struct wait_queue a = { b, NULL }
|
#endif
|
#endif
|
|
|
/* SECURE SOCKET IMPLEMENTATION
|
/* SECURE SOCKET IMPLEMENTATION
|
*
|
*
|
* TRANSMIT:
|
* TRANSMIT:
|
*
|
*
|
* When the user sends a packet via send() system call
|
* When the user sends a packet via send() system call
|
* the wanpipe_sendmsg() function is executed.
|
* the wanpipe_sendmsg() function is executed.
|
*
|
*
|
* Each packet is enqueud into sk->write_queue transmit
|
* Each packet is enqueud into sk->write_queue transmit
|
* queue. When the packet is enqueued, a delayed transmit
|
* queue. When the packet is enqueued, a delayed transmit
|
* timer is triggerd which acts as a Bottom Half hander.
|
* timer is triggerd which acts as a Bottom Half hander.
|
*
|
*
|
* wanpipe_delay_transmit() function (BH), dequeues packets
|
* wanpipe_delay_transmit() function (BH), dequeues packets
|
* from the sk->write_queue transmit queue and sends it
|
* from the sk->write_queue transmit queue and sends it
|
* to the deriver via dev->hard_start_xmit(skb, dev) function.
|
* to the deriver via dev->hard_start_xmit(skb, dev) function.
|
* Note, this function is actual a function pointer of if_send()
|
* Note, this function is actual a function pointer of if_send()
|
* routine in the wanpipe driver.
|
* routine in the wanpipe driver.
|
*
|
*
|
* X25API GUARANTEED DELIVERY:
|
* X25API GUARANTEED DELIVERY:
|
*
|
*
|
* In order to provide 100% guaranteed packet delivery,
|
* In order to provide 100% guaranteed packet delivery,
|
* an atomic 'packet_sent' counter is implemented. Counter
|
* an atomic 'packet_sent' counter is implemented. Counter
|
* is incremented for each packet enqueued
|
* is incremented for each packet enqueued
|
* into sk->write_queue. Counter is decremented each
|
* into sk->write_queue. Counter is decremented each
|
* time wanpipe_delayed_transmit() function successfuly
|
* time wanpipe_delayed_transmit() function successfuly
|
* passes the packet to the driver. Before each send(), a poll
|
* passes the packet to the driver. Before each send(), a poll
|
* routine checks the sock resources The maximum value of
|
* routine checks the sock resources The maximum value of
|
* packet sent counter is 1, thus if one packet is queued, the
|
* packet sent counter is 1, thus if one packet is queued, the
|
* application will block until that packet is passed to the
|
* application will block until that packet is passed to the
|
* driver.
|
* driver.
|
*
|
*
|
* RECEIVE:
|
* RECEIVE:
|
*
|
*
|
* Wanpipe device drivers call the socket bottom half
|
* Wanpipe device drivers call the socket bottom half
|
* function, wanpipe_rcv() to queue the incoming packets
|
* function, wanpipe_rcv() to queue the incoming packets
|
* into an AF_WANPIPE socket queue. Based on wanpipe_rcv()
|
* into an AF_WANPIPE socket queue. Based on wanpipe_rcv()
|
* return code, the driver knows whether the packet was
|
* return code, the driver knows whether the packet was
|
* sucessfully queued. If the socket queue is full,
|
* sucessfully queued. If the socket queue is full,
|
* protocol flow control is used by the driver, if any,
|
* protocol flow control is used by the driver, if any,
|
* to slow down the traffic until the sock queue is free.
|
* to slow down the traffic until the sock queue is free.
|
*
|
*
|
* Every time a packet arrives into a socket queue the
|
* Every time a packet arrives into a socket queue the
|
* socket wakes up processes which are waiting to receive
|
* socket wakes up processes which are waiting to receive
|
* data.
|
* data.
|
*
|
*
|
* If the socket queue is full, the driver sets a block
|
* If the socket queue is full, the driver sets a block
|
* bit which signals the socket to kick the wanpipe driver
|
* bit which signals the socket to kick the wanpipe driver
|
* bottom half hander when the socket queue is partialy
|
* bottom half hander when the socket queue is partialy
|
* empty. wanpipe_recvmsg() function performs this action.
|
* empty. wanpipe_recvmsg() function performs this action.
|
*
|
*
|
* In case of x25api, packets will never be dropped, since
|
* In case of x25api, packets will never be dropped, since
|
* flow control is available.
|
* flow control is available.
|
*
|
*
|
* In case of streaming protocols like CHDLC, packets will
|
* In case of streaming protocols like CHDLC, packets will
|
* be dropped but the statistics will be generated.
|
* be dropped but the statistics will be generated.
|
*/
|
*/
|
|
|
|
|
/* The code below is used to test memory leaks. It prints out
|
/* The code below is used to test memory leaks. It prints out
|
* a message every time kmalloc and kfree system calls get executed.
|
* a message every time kmalloc and kfree system calls get executed.
|
* If the calls match there is no leak :)
|
* If the calls match there is no leak :)
|
*/
|
*/
|
|
|
/***********FOR DEBUGGING PURPOSES*********************************************
|
/***********FOR DEBUGGING PURPOSES*********************************************
|
#define KMEM_SAFETYZONE 8
|
#define KMEM_SAFETYZONE 8
|
|
|
static void * dbg_kmalloc(unsigned int size, int prio, int line) {
|
static void * dbg_kmalloc(unsigned int size, int prio, int line) {
|
void * v = kmalloc(size,prio);
|
void * v = kmalloc(size,prio);
|
printk(KERN_INFO "line %d kmalloc(%d,%d) = %p\n",line,size,prio,v);
|
printk(KERN_INFO "line %d kmalloc(%d,%d) = %p\n",line,size,prio,v);
|
return v;
|
return v;
|
}
|
}
|
static void dbg_kfree(void * v, int line) {
|
static void dbg_kfree(void * v, int line) {
|
printk(KERN_INFO "line %d kfree(%p)\n",line,v);
|
printk(KERN_INFO "line %d kfree(%p)\n",line,v);
|
kfree(v);
|
kfree(v);
|
}
|
}
|
|
|
#define kmalloc(x,y) dbg_kmalloc(x,y,__LINE__)
|
#define kmalloc(x,y) dbg_kmalloc(x,y,__LINE__)
|
#define kfree(x) dbg_kfree(x,__LINE__)
|
#define kfree(x) dbg_kfree(x,__LINE__)
|
******************************************************************************/
|
******************************************************************************/
|
|
|
|
|
/* List of all wanpipe sockets. */
|
/* List of all wanpipe sockets. */
|
struct sock * wanpipe_sklist = NULL;
|
struct sock * wanpipe_sklist = NULL;
|
static rwlock_t wanpipe_sklist_lock = RW_LOCK_UNLOCKED;
|
static rwlock_t wanpipe_sklist_lock = RW_LOCK_UNLOCKED;
|
|
|
atomic_t wanpipe_socks_nr;
|
atomic_t wanpipe_socks_nr;
|
static unsigned long wanpipe_tx_critical=0;
|
static unsigned long wanpipe_tx_critical=0;
|
|
|
#if 0
|
#if 0
|
/* Private wanpipe socket structures. */
|
/* Private wanpipe socket structures. */
|
struct wanpipe_opt
|
struct wanpipe_opt
|
{
|
{
|
void *mbox; /* Mail box */
|
void *mbox; /* Mail box */
|
void *card; /* Card bouded to */
|
void *card; /* Card bouded to */
|
netdevice_t *dev; /* Bounded device */
|
netdevice_t *dev; /* Bounded device */
|
unsigned short lcn; /* Binded LCN */
|
unsigned short lcn; /* Binded LCN */
|
unsigned char svc; /* 0=pvc, 1=svc */
|
unsigned char svc; /* 0=pvc, 1=svc */
|
unsigned char timer; /* flag for delayed transmit*/
|
unsigned char timer; /* flag for delayed transmit*/
|
struct timer_list tx_timer;
|
struct timer_list tx_timer;
|
unsigned poll_cnt;
|
unsigned poll_cnt;
|
unsigned char force; /* Used to force sock release */
|
unsigned char force; /* Used to force sock release */
|
atomic_t packet_sent;
|
atomic_t packet_sent;
|
};
|
};
|
#endif
|
#endif
|
|
|
static int sk_count=0;
|
static int sk_count=0;
|
extern struct proto_ops wanpipe_ops;
|
extern struct proto_ops wanpipe_ops;
|
static unsigned long find_free_critical=0;
|
static unsigned long find_free_critical=0;
|
|
|
static void wanpipe_unlink_driver (struct sock *);
|
static void wanpipe_unlink_driver (struct sock *);
|
static void wanpipe_link_driver (netdevice_t *,struct sock *sk);
|
static void wanpipe_link_driver (netdevice_t *,struct sock *sk);
|
static void wanpipe_wakeup_driver(struct sock *sk);
|
static void wanpipe_wakeup_driver(struct sock *sk);
|
static int execute_command(struct sock *, unsigned char, unsigned int);
|
static int execute_command(struct sock *, unsigned char, unsigned int);
|
static int check_dev (netdevice_t *, sdla_t *);
|
static int check_dev (netdevice_t *, sdla_t *);
|
netdevice_t * wanpipe_find_free_dev (sdla_t *);
|
netdevice_t * wanpipe_find_free_dev (sdla_t *);
|
static void wanpipe_unlink_card (struct sock *);
|
static void wanpipe_unlink_card (struct sock *);
|
static int wanpipe_link_card (struct sock *);
|
static int wanpipe_link_card (struct sock *);
|
static struct sock *wanpipe_make_new(struct sock *);
|
static struct sock *wanpipe_make_new(struct sock *);
|
static struct sock *wanpipe_alloc_socket(void);
|
static struct sock *wanpipe_alloc_socket(void);
|
static inline int get_atomic_device (netdevice_t *);
|
static inline int get_atomic_device (netdevice_t *);
|
static int wanpipe_exec_cmd(struct sock *, int, unsigned int);
|
static int wanpipe_exec_cmd(struct sock *, int, unsigned int);
|
static int get_ioctl_cmd (struct sock *, void *);
|
static int get_ioctl_cmd (struct sock *, void *);
|
static int set_ioctl_cmd (struct sock *, void *);
|
static int set_ioctl_cmd (struct sock *, void *);
|
static void release_device (netdevice_t *);
|
static void release_device (netdevice_t *);
|
static void wanpipe_kill_sock_timer (unsigned long data);
|
static void wanpipe_kill_sock_timer (unsigned long data);
|
static void wanpipe_kill_sock_irq (struct sock *);
|
static void wanpipe_kill_sock_irq (struct sock *);
|
static void wanpipe_kill_sock_accept (struct sock *);
|
static void wanpipe_kill_sock_accept (struct sock *);
|
static int wanpipe_do_bind(struct sock *, netdevice_t *, int);
|
static int wanpipe_do_bind(struct sock *, netdevice_t *, int);
|
struct sock * get_newsk_from_skb (struct sk_buff *);
|
struct sock * get_newsk_from_skb (struct sk_buff *);
|
static int wanpipe_debug (struct sock *, void *);
|
static int wanpipe_debug (struct sock *, void *);
|
static void wanpipe_delayed_transmit (unsigned long data);
|
static void wanpipe_delayed_transmit (unsigned long data);
|
static void release_driver(struct sock *);
|
static void release_driver(struct sock *);
|
static void start_cleanup_timer (struct sock *);
|
static void start_cleanup_timer (struct sock *);
|
static void check_write_queue(struct sock *);
|
static void check_write_queue(struct sock *);
|
static int check_driver_busy (struct sock *);
|
static int check_driver_busy (struct sock *);
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_rcv
|
* wanpipe_rcv
|
*
|
*
|
* Wanpipe socket bottom half handler. This function
|
* Wanpipe socket bottom half handler. This function
|
* is called by the WANPIPE device drivers to queue a
|
* is called by the WANPIPE device drivers to queue a
|
* incomming packet into the socket receive queue.
|
* incomming packet into the socket receive queue.
|
* Once the packet is queued, all processes waiting to
|
* Once the packet is queued, all processes waiting to
|
* read are woken up.
|
* read are woken up.
|
*
|
*
|
* During socket bind, this function is bounded into
|
* During socket bind, this function is bounded into
|
* WANPIPE driver private.
|
* WANPIPE driver private.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int wanpipe_rcv(struct sk_buff *skb, netdevice_t *dev, struct sock *sk)
|
static int wanpipe_rcv(struct sk_buff *skb, netdevice_t *dev, struct sock *sk)
|
{
|
{
|
struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)skb->cb;
|
struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)skb->cb;
|
wanpipe_common_t *chan = dev->priv;
|
wanpipe_common_t *chan = dev->priv;
|
/*
|
/*
|
* When we registered the protocol we saved the socket in the data
|
* When we registered the protocol we saved the socket in the data
|
* field for just this event.
|
* field for just this event.
|
*/
|
*/
|
|
|
skb->dev = dev;
|
skb->dev = dev;
|
|
|
sll->sll_family = AF_WANPIPE;
|
sll->sll_family = AF_WANPIPE;
|
sll->sll_hatype = dev->type;
|
sll->sll_hatype = dev->type;
|
sll->sll_protocol = skb->protocol;
|
sll->sll_protocol = skb->protocol;
|
sll->sll_pkttype = skb->pkt_type;
|
sll->sll_pkttype = skb->pkt_type;
|
sll->sll_ifindex = dev->ifindex;
|
sll->sll_ifindex = dev->ifindex;
|
sll->sll_halen = 0;
|
sll->sll_halen = 0;
|
|
|
if (dev->hard_header_parse)
|
if (dev->hard_header_parse)
|
sll->sll_halen = dev->hard_header_parse(skb, sll->sll_addr);
|
sll->sll_halen = dev->hard_header_parse(skb, sll->sll_addr);
|
|
|
/*
|
/*
|
* WAN_PACKET_DATA : Data which should be passed up the receive queue.
|
* WAN_PACKET_DATA : Data which should be passed up the receive queue.
|
* WAN_PACKET_ASYC : Asynchronous data like place call, which should
|
* WAN_PACKET_ASYC : Asynchronous data like place call, which should
|
* be passed up the listening sock.
|
* be passed up the listening sock.
|
* WAN_PACKET_ERR : Asynchronous data like clear call or restart
|
* WAN_PACKET_ERR : Asynchronous data like clear call or restart
|
* which should go into an error queue.
|
* which should go into an error queue.
|
*/
|
*/
|
switch (skb->pkt_type){
|
switch (skb->pkt_type){
|
|
|
case WAN_PACKET_DATA:
|
case WAN_PACKET_DATA:
|
if (sock_queue_rcv_skb(sk,skb)<0){
|
if (sock_queue_rcv_skb(sk,skb)<0){
|
return -ENOMEM;
|
return -ENOMEM;
|
}
|
}
|
break;
|
break;
|
case WAN_PACKET_CMD:
|
case WAN_PACKET_CMD:
|
sk->state = chan->state;
|
sk->state = chan->state;
|
/* Bug fix: update Mar6.
|
/* Bug fix: update Mar6.
|
* Do not set the sock lcn number here, since
|
* Do not set the sock lcn number here, since
|
* cmd is not guaranteed to be executed on the
|
* cmd is not guaranteed to be executed on the
|
* board, thus Lcn could be wrong */
|
* board, thus Lcn could be wrong */
|
sk->data_ready(sk,skb->len);
|
sk->data_ready(sk,skb->len);
|
kfree_skb(skb);
|
kfree_skb(skb);
|
break;
|
break;
|
case WAN_PACKET_ERR:
|
case WAN_PACKET_ERR:
|
sk->state = chan->state;
|
sk->state = chan->state;
|
if (sock_queue_err_skb(sk,skb)<0){
|
if (sock_queue_err_skb(sk,skb)<0){
|
return -ENOMEM;
|
return -ENOMEM;
|
}
|
}
|
break;
|
break;
|
default:
|
default:
|
printk(KERN_INFO "wansock: BH Illegal Packet Type Dropping\n");
|
printk(KERN_INFO "wansock: BH Illegal Packet Type Dropping\n");
|
kfree_skb(skb);
|
kfree_skb(skb);
|
break;
|
break;
|
}
|
}
|
|
|
//??????????????????????
|
//??????????????????????
|
// if (sk->state == WANSOCK_DISCONNECTED){
|
// if (sk->state == WANSOCK_DISCONNECTED){
|
// if (sk->zapped){
|
// if (sk->zapped){
|
// //printk(KERN_INFO "wansock: Disconnected, killing early\n");
|
// //printk(KERN_INFO "wansock: Disconnected, killing early\n");
|
// wanpipe_unlink_driver(sk);
|
// wanpipe_unlink_driver(sk);
|
// sk->bound_dev_if = 0;
|
// sk->bound_dev_if = 0;
|
// }
|
// }
|
// }
|
// }
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_listen_rcv
|
* wanpipe_listen_rcv
|
*
|
*
|
* Wanpipe LISTEN socket bottom half handler. This function
|
* Wanpipe LISTEN socket bottom half handler. This function
|
* is called by the WANPIPE device drivers to queue an
|
* is called by the WANPIPE device drivers to queue an
|
* incomming call into the socket listening queue.
|
* incomming call into the socket listening queue.
|
* Once the packet is queued, the waiting accept() process
|
* Once the packet is queued, the waiting accept() process
|
* is woken up.
|
* is woken up.
|
*
|
*
|
* During socket bind, this function is bounded into
|
* During socket bind, this function is bounded into
|
* WANPIPE driver private.
|
* WANPIPE driver private.
|
*
|
*
|
* IMPORTANT NOTE:
|
* IMPORTANT NOTE:
|
* The accept call() is waiting for an skb packet
|
* The accept call() is waiting for an skb packet
|
* which contains a pointer to a device structure.
|
* which contains a pointer to a device structure.
|
*
|
*
|
* When we do a bind to a device structre, we
|
* When we do a bind to a device structre, we
|
* bind a newly created socket into "chan->sk". Thus,
|
* bind a newly created socket into "chan->sk". Thus,
|
* when accept receives the skb packet, it will know
|
* when accept receives the skb packet, it will know
|
* from which dev it came form, and in turn it will know
|
* from which dev it came form, and in turn it will know
|
* the address of the new sock.
|
* the address of the new sock.
|
*
|
*
|
* NOTE: This function gets called from driver ISR.
|
* NOTE: This function gets called from driver ISR.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int wanpipe_listen_rcv (struct sk_buff *skb, struct sock *sk)
|
static int wanpipe_listen_rcv (struct sk_buff *skb, struct sock *sk)
|
{
|
{
|
|
|
struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)skb->cb;
|
struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)skb->cb;
|
struct sock *newsk;
|
struct sock *newsk;
|
netdevice_t *dev;
|
netdevice_t *dev;
|
sdla_t *card;
|
sdla_t *card;
|
mbox_cmd_t *mbox_ptr;
|
mbox_cmd_t *mbox_ptr;
|
wanpipe_common_t *chan;
|
wanpipe_common_t *chan;
|
|
|
/* Find a free device, if none found, all svc's are busy
|
/* Find a free device, if none found, all svc's are busy
|
*/
|
*/
|
|
|
card = (sdla_t*)sk->protinfo.af_wanpipe->card;
|
card = (sdla_t*)sk->protinfo.af_wanpipe->card;
|
if (!card){
|
if (!card){
|
printk(KERN_INFO "wansock: LISTEN ERROR, No Card\n");
|
printk(KERN_INFO "wansock: LISTEN ERROR, No Card\n");
|
return -ENODEV;
|
return -ENODEV;
|
}
|
}
|
|
|
dev = wanpipe_find_free_dev(card);
|
dev = wanpipe_find_free_dev(card);
|
if (!dev){
|
if (!dev){
|
printk(KERN_INFO "wansock: LISTEN ERROR, No Free Device\n");
|
printk(KERN_INFO "wansock: LISTEN ERROR, No Free Device\n");
|
return -ENODEV;
|
return -ENODEV;
|
}
|
}
|
|
|
chan=dev->priv;
|
chan=dev->priv;
|
chan->state = WANSOCK_CONNECTING;
|
chan->state = WANSOCK_CONNECTING;
|
|
|
/* Allocate a new sock, which accept will bind
|
/* Allocate a new sock, which accept will bind
|
* and pass up to the user
|
* and pass up to the user
|
*/
|
*/
|
if ((newsk = wanpipe_make_new(sk)) == NULL){
|
if ((newsk = wanpipe_make_new(sk)) == NULL){
|
release_device(dev);
|
release_device(dev);
|
return -ENOMEM;
|
return -ENOMEM;
|
}
|
}
|
|
|
|
|
/* Initialize the new sock structure
|
/* Initialize the new sock structure
|
*/
|
*/
|
newsk->bound_dev_if = dev->ifindex;
|
newsk->bound_dev_if = dev->ifindex;
|
newsk->protinfo.af_wanpipe->card = sk->protinfo.af_wanpipe->card;
|
newsk->protinfo.af_wanpipe->card = sk->protinfo.af_wanpipe->card;
|
|
|
/* Insert the sock into the main wanpipe
|
/* Insert the sock into the main wanpipe
|
* sock list.
|
* sock list.
|
*/
|
*/
|
atomic_inc(&wanpipe_socks_nr);
|
atomic_inc(&wanpipe_socks_nr);
|
|
|
/* Allocate and fill in the new Mail Box. Then
|
/* Allocate and fill in the new Mail Box. Then
|
* bind the mail box to the sock. It will be
|
* bind the mail box to the sock. It will be
|
* used by the ioctl call to read call information
|
* used by the ioctl call to read call information
|
* and to execute commands.
|
* and to execute commands.
|
*/
|
*/
|
if ((mbox_ptr = kmalloc(sizeof(mbox_cmd_t), GFP_ATOMIC)) == NULL) {
|
if ((mbox_ptr = kmalloc(sizeof(mbox_cmd_t), GFP_ATOMIC)) == NULL) {
|
wanpipe_kill_sock_irq (newsk);
|
wanpipe_kill_sock_irq (newsk);
|
release_device(dev);
|
release_device(dev);
|
return -ENOMEM;
|
return -ENOMEM;
|
}
|
}
|
memset(mbox_ptr, 0, sizeof(mbox_cmd_t));
|
memset(mbox_ptr, 0, sizeof(mbox_cmd_t));
|
memcpy(mbox_ptr,skb->data,skb->len);
|
memcpy(mbox_ptr,skb->data,skb->len);
|
|
|
/* Register the lcn on which incoming call came
|
/* Register the lcn on which incoming call came
|
* from. Thus, if we have to clear it, we know
|
* from. Thus, if we have to clear it, we know
|
* whic lcn to clear
|
* whic lcn to clear
|
*/
|
*/
|
|
|
newsk->protinfo.af_wanpipe->lcn = mbox_ptr->cmd.lcn;
|
newsk->protinfo.af_wanpipe->lcn = mbox_ptr->cmd.lcn;
|
newsk->protinfo.af_wanpipe->mbox = (void *)mbox_ptr;
|
newsk->protinfo.af_wanpipe->mbox = (void *)mbox_ptr;
|
|
|
DBG_PRINTK(KERN_INFO "NEWSOCK : Device %s, bind to lcn %i\n",
|
DBG_PRINTK(KERN_INFO "NEWSOCK : Device %s, bind to lcn %i\n",
|
dev->name,mbox_ptr->cmd.lcn);
|
dev->name,mbox_ptr->cmd.lcn);
|
|
|
chan->lcn = mbox_ptr->cmd.lcn;
|
chan->lcn = mbox_ptr->cmd.lcn;
|
card->u.x.svc_to_dev_map[(chan->lcn%MAX_X25_LCN)] = dev;
|
card->u.x.svc_to_dev_map[(chan->lcn%MAX_X25_LCN)] = dev;
|
|
|
newsk->zapped=0;
|
newsk->zapped=0;
|
newsk->num = htons(X25_PROT);
|
newsk->num = htons(X25_PROT);
|
|
|
if (wanpipe_do_bind(newsk,dev,newsk->num)){
|
if (wanpipe_do_bind(newsk,dev,newsk->num)){
|
wanpipe_kill_sock_irq (newsk);
|
wanpipe_kill_sock_irq (newsk);
|
release_device(dev);
|
release_device(dev);
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
newsk->state = WANSOCK_CONNECTING;
|
newsk->state = WANSOCK_CONNECTING;
|
|
|
|
|
/* Fill in the standard sock address info */
|
/* Fill in the standard sock address info */
|
|
|
sll->sll_family = AF_WANPIPE;
|
sll->sll_family = AF_WANPIPE;
|
sll->sll_hatype = dev->type;
|
sll->sll_hatype = dev->type;
|
sll->sll_protocol = skb->protocol;
|
sll->sll_protocol = skb->protocol;
|
sll->sll_pkttype = skb->pkt_type;
|
sll->sll_pkttype = skb->pkt_type;
|
sll->sll_ifindex = dev->ifindex;
|
sll->sll_ifindex = dev->ifindex;
|
sll->sll_halen = 0;
|
sll->sll_halen = 0;
|
|
|
skb->dev = dev;
|
skb->dev = dev;
|
sk->ack_backlog++;
|
sk->ack_backlog++;
|
|
|
/* We must do this manually, since the sock_queue_rcv_skb()
|
/* We must do this manually, since the sock_queue_rcv_skb()
|
* function sets the skb->dev to NULL. However, we use
|
* function sets the skb->dev to NULL. However, we use
|
* the dev field in the accept function.*/
|
* the dev field in the accept function.*/
|
if (atomic_read(&sk->rmem_alloc) + skb->truesize >=
|
if (atomic_read(&sk->rmem_alloc) + skb->truesize >=
|
(unsigned)sk->rcvbuf){
|
(unsigned)sk->rcvbuf){
|
|
|
wanpipe_unlink_driver(newsk);
|
wanpipe_unlink_driver(newsk);
|
wanpipe_kill_sock_irq (newsk);
|
wanpipe_kill_sock_irq (newsk);
|
--sk->ack_backlog;
|
--sk->ack_backlog;
|
return -ENOMEM;
|
return -ENOMEM;
|
}
|
}
|
|
|
skb_set_owner_r(skb, sk);
|
skb_set_owner_r(skb, sk);
|
skb_queue_tail(&sk->receive_queue, skb);
|
skb_queue_tail(&sk->receive_queue, skb);
|
sk->data_ready(sk,skb->len);
|
sk->data_ready(sk,skb->len);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_make_new
|
* wanpipe_make_new
|
*
|
*
|
* Create a new sock, and allocate a wanpipe private
|
* Create a new sock, and allocate a wanpipe private
|
* structure to it. Also, copy the important data
|
* structure to it. Also, copy the important data
|
* from the original sock to the new sock.
|
* from the original sock to the new sock.
|
*
|
*
|
* This function is used by wanpipe_listen_rcv() listen
|
* This function is used by wanpipe_listen_rcv() listen
|
* bottom half handler. A copy of the listening sock
|
* bottom half handler. A copy of the listening sock
|
* is created using this function.
|
* is created using this function.
|
*
|
*
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static struct sock *wanpipe_make_new(struct sock *osk)
|
static struct sock *wanpipe_make_new(struct sock *osk)
|
{
|
{
|
struct sock *sk;
|
struct sock *sk;
|
|
|
if (osk->type != SOCK_RAW)
|
if (osk->type != SOCK_RAW)
|
return NULL;
|
return NULL;
|
|
|
if ((sk = wanpipe_alloc_socket()) == NULL)
|
if ((sk = wanpipe_alloc_socket()) == NULL)
|
return NULL;
|
return NULL;
|
|
|
sk->type = osk->type;
|
sk->type = osk->type;
|
sk->socket = osk->socket;
|
sk->socket = osk->socket;
|
sk->priority = osk->priority;
|
sk->priority = osk->priority;
|
sk->protocol = osk->protocol;
|
sk->protocol = osk->protocol;
|
sk->num = osk->num;
|
sk->num = osk->num;
|
sk->rcvbuf = osk->rcvbuf;
|
sk->rcvbuf = osk->rcvbuf;
|
sk->sndbuf = osk->sndbuf;
|
sk->sndbuf = osk->sndbuf;
|
sk->debug = osk->debug;
|
sk->debug = osk->debug;
|
sk->state = WANSOCK_CONNECTING;
|
sk->state = WANSOCK_CONNECTING;
|
sk->sleep = osk->sleep;
|
sk->sleep = osk->sleep;
|
|
|
return sk;
|
return sk;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_make_new
|
* wanpipe_make_new
|
*
|
*
|
* Allocate memory for the a new sock, and sock
|
* Allocate memory for the a new sock, and sock
|
* private data.
|
* private data.
|
*
|
*
|
* Increment the module use count.
|
* Increment the module use count.
|
*
|
*
|
* This function is used by wanpipe_create() and
|
* This function is used by wanpipe_create() and
|
* wanpipe_make_new() functions.
|
* wanpipe_make_new() functions.
|
*
|
*
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static struct sock *wanpipe_alloc_socket(void)
|
static struct sock *wanpipe_alloc_socket(void)
|
{
|
{
|
struct sock *sk;
|
struct sock *sk;
|
struct wanpipe_opt *wan_opt;
|
struct wanpipe_opt *wan_opt;
|
|
|
if ((sk = sk_alloc(PF_WANPIPE, GFP_ATOMIC, 1)) == NULL)
|
if ((sk = sk_alloc(PF_WANPIPE, GFP_ATOMIC, 1)) == NULL)
|
return NULL;
|
return NULL;
|
|
|
if ((wan_opt = kmalloc(sizeof(struct wanpipe_opt), GFP_ATOMIC)) == NULL) {
|
if ((wan_opt = kmalloc(sizeof(struct wanpipe_opt), GFP_ATOMIC)) == NULL) {
|
sk_free(sk);
|
sk_free(sk);
|
return NULL;
|
return NULL;
|
}
|
}
|
memset(wan_opt, 0x00, sizeof(struct wanpipe_opt));
|
memset(wan_opt, 0x00, sizeof(struct wanpipe_opt));
|
|
|
sk->protinfo.af_wanpipe = wan_opt;
|
sk->protinfo.af_wanpipe = wan_opt;
|
sk->protinfo.destruct_hook = wan_opt;
|
sk->protinfo.destruct_hook = wan_opt;
|
|
|
/* Use timer to send data to the driver. This will act
|
/* Use timer to send data to the driver. This will act
|
* as a BH handler for sendmsg functions */
|
* as a BH handler for sendmsg functions */
|
sk->protinfo.af_wanpipe->tx_timer.data=(unsigned long)sk;
|
sk->protinfo.af_wanpipe->tx_timer.data=(unsigned long)sk;
|
sk->protinfo.af_wanpipe->tx_timer.function=wanpipe_delayed_transmit;
|
sk->protinfo.af_wanpipe->tx_timer.function=wanpipe_delayed_transmit;
|
|
|
MOD_INC_USE_COUNT;
|
MOD_INC_USE_COUNT;
|
|
|
sock_init_data(NULL, sk);
|
sock_init_data(NULL, sk);
|
return sk;
|
return sk;
|
}
|
}
|
|
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_sendmsg
|
* wanpipe_sendmsg
|
*
|
*
|
* This function implements a sendto() system call,
|
* This function implements a sendto() system call,
|
* for AF_WANPIPE socket family.
|
* for AF_WANPIPE socket family.
|
* During socket bind() sk->bound_dev_if is initialized
|
* During socket bind() sk->bound_dev_if is initialized
|
* to a correct network device. This number is used
|
* to a correct network device. This number is used
|
* to find a network device to which the packet should
|
* to find a network device to which the packet should
|
* be passed to.
|
* be passed to.
|
*
|
*
|
* Each packet is queued into sk->write_queue and
|
* Each packet is queued into sk->write_queue and
|
* delayed transmit bottom half handler is marked for
|
* delayed transmit bottom half handler is marked for
|
* execution.
|
* execution.
|
*
|
*
|
* A socket must be in WANSOCK_CONNECTED state before
|
* A socket must be in WANSOCK_CONNECTED state before
|
* a packet is queued into sk->write_queue.
|
* a packet is queued into sk->write_queue.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int wanpipe_sendmsg(struct socket *sock, struct msghdr *msg, int len,
|
static int wanpipe_sendmsg(struct socket *sock, struct msghdr *msg, int len,
|
struct scm_cookie *scm)
|
struct scm_cookie *scm)
|
{
|
{
|
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
struct wan_sockaddr_ll *saddr=(struct wan_sockaddr_ll *)msg->msg_name;
|
struct wan_sockaddr_ll *saddr=(struct wan_sockaddr_ll *)msg->msg_name;
|
struct sk_buff *skb;
|
struct sk_buff *skb;
|
netdevice_t *dev;
|
netdevice_t *dev;
|
unsigned short proto;
|
unsigned short proto;
|
unsigned char *addr;
|
unsigned char *addr;
|
int ifindex, err, reserve = 0;
|
int ifindex, err, reserve = 0;
|
|
|
|
|
if (!sk->zapped)
|
if (!sk->zapped)
|
return -ENETDOWN;
|
return -ENETDOWN;
|
|
|
if (sk->state != WANSOCK_CONNECTED)
|
if (sk->state != WANSOCK_CONNECTED)
|
return -ENOTCONN;
|
return -ENOTCONN;
|
|
|
if (msg->msg_flags&~MSG_DONTWAIT)
|
if (msg->msg_flags&~MSG_DONTWAIT)
|
return(-EINVAL);
|
return(-EINVAL);
|
|
|
/* it was <=, now one can send
|
/* it was <=, now one can send
|
* zero length packets */
|
* zero length packets */
|
if (len < sizeof(x25api_hdr_t))
|
if (len < sizeof(x25api_hdr_t))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
if (saddr == NULL) {
|
if (saddr == NULL) {
|
ifindex = sk->bound_dev_if;
|
ifindex = sk->bound_dev_if;
|
proto = sk->num;
|
proto = sk->num;
|
addr = NULL;
|
addr = NULL;
|
|
|
}else{
|
}else{
|
if (msg->msg_namelen < sizeof(struct wan_sockaddr_ll)){
|
if (msg->msg_namelen < sizeof(struct wan_sockaddr_ll)){
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
ifindex = sk->bound_dev_if;
|
ifindex = sk->bound_dev_if;
|
proto = saddr->sll_protocol;
|
proto = saddr->sll_protocol;
|
addr = saddr->sll_addr;
|
addr = saddr->sll_addr;
|
}
|
}
|
|
|
dev = dev_get_by_index(ifindex);
|
dev = dev_get_by_index(ifindex);
|
if (dev == NULL){
|
if (dev == NULL){
|
printk(KERN_INFO "wansock: Send failed, dev index: %i\n",ifindex);
|
printk(KERN_INFO "wansock: Send failed, dev index: %i\n",ifindex);
|
return -ENXIO;
|
return -ENXIO;
|
}
|
}
|
dev_put(dev);
|
dev_put(dev);
|
|
|
if (sock->type == SOCK_RAW)
|
if (sock->type == SOCK_RAW)
|
reserve = dev->hard_header_len;
|
reserve = dev->hard_header_len;
|
|
|
if (len > dev->mtu+reserve){
|
if (len > dev->mtu+reserve){
|
return -EMSGSIZE;
|
return -EMSGSIZE;
|
}
|
}
|
|
|
#ifndef LINUX_2_4
|
#ifndef LINUX_2_4
|
dev_lock_list();
|
dev_lock_list();
|
#endif
|
#endif
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
|
skb = sock_alloc_send_skb(sk, len+dev->hard_header_len+15,
|
skb = sock_alloc_send_skb(sk, len+dev->hard_header_len+15,
|
msg->msg_flags & MSG_DONTWAIT, &err);
|
msg->msg_flags & MSG_DONTWAIT, &err);
|
#else
|
#else
|
skb = sock_alloc_send_skb(sk, len+dev->hard_header_len+15, 0,
|
skb = sock_alloc_send_skb(sk, len+dev->hard_header_len+15, 0,
|
msg->msg_flags & MSG_DONTWAIT, &err);
|
msg->msg_flags & MSG_DONTWAIT, &err);
|
#endif
|
#endif
|
|
|
if (skb==NULL){
|
if (skb==NULL){
|
goto out_unlock;
|
goto out_unlock;
|
}
|
}
|
|
|
skb_reserve(skb, (dev->hard_header_len+15)&~15);
|
skb_reserve(skb, (dev->hard_header_len+15)&~15);
|
skb->nh.raw = skb->data;
|
skb->nh.raw = skb->data;
|
|
|
/* Returns -EFAULT on error */
|
/* Returns -EFAULT on error */
|
err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
|
err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
|
if (err){
|
if (err){
|
goto out_free;
|
goto out_free;
|
}
|
}
|
|
|
if (dev->hard_header) {
|
if (dev->hard_header) {
|
int res;
|
int res;
|
err = -EINVAL;
|
err = -EINVAL;
|
res = dev->hard_header(skb, dev, ntohs(proto), addr, NULL, len);
|
res = dev->hard_header(skb, dev, ntohs(proto), addr, NULL, len);
|
if (res<0){
|
if (res<0){
|
goto out_free;
|
goto out_free;
|
}
|
}
|
}
|
}
|
|
|
skb->protocol = proto;
|
skb->protocol = proto;
|
skb->dev = dev;
|
skb->dev = dev;
|
skb->priority = sk->priority;
|
skb->priority = sk->priority;
|
skb->pkt_type = WAN_PACKET_DATA;
|
skb->pkt_type = WAN_PACKET_DATA;
|
|
|
err = -ENETDOWN;
|
err = -ENETDOWN;
|
if (!(dev->flags & IFF_UP))
|
if (!(dev->flags & IFF_UP))
|
goto out_free;
|
goto out_free;
|
|
|
#ifndef LINUX_2_4
|
#ifndef LINUX_2_4
|
dev_unlock_list();
|
dev_unlock_list();
|
#endif
|
#endif
|
|
|
if (atomic_read(&sk->wmem_alloc) + skb->truesize > (unsigned int)sk->sndbuf){
|
if (atomic_read(&sk->wmem_alloc) + skb->truesize > (unsigned int)sk->sndbuf){
|
kfree_skb(skb);
|
kfree_skb(skb);
|
return -ENOBUFS;
|
return -ENOBUFS;
|
}
|
}
|
|
|
skb_queue_tail(&sk->write_queue,skb);
|
skb_queue_tail(&sk->write_queue,skb);
|
atomic_inc(&sk->protinfo.af_wanpipe->packet_sent);
|
atomic_inc(&sk->protinfo.af_wanpipe->packet_sent);
|
|
|
if (!(test_and_set_bit(0,&sk->protinfo.af_wanpipe->timer))){
|
if (!(test_and_set_bit(0,&sk->protinfo.af_wanpipe->timer))){
|
del_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
del_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
sk->protinfo.af_wanpipe->tx_timer.expires=jiffies+1;
|
sk->protinfo.af_wanpipe->tx_timer.expires=jiffies+1;
|
add_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
add_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
}
|
}
|
|
|
return(len);
|
return(len);
|
|
|
out_free:
|
out_free:
|
kfree_skb(skb);
|
kfree_skb(skb);
|
out_unlock:
|
out_unlock:
|
#ifndef LINUX_2_4
|
#ifndef LINUX_2_4
|
dev_unlock_list();
|
dev_unlock_list();
|
#endif
|
#endif
|
return err;
|
return err;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_delayed_tarnsmit
|
* wanpipe_delayed_tarnsmit
|
*
|
*
|
* Transmit bottom half handeler. It dequeues packets
|
* Transmit bottom half handeler. It dequeues packets
|
* from sk->write_queue and passes them to the
|
* from sk->write_queue and passes them to the
|
* driver. If the driver is busy, the packet is
|
* driver. If the driver is busy, the packet is
|
* re-enqueued.
|
* re-enqueued.
|
*
|
*
|
* Packet Sent counter is decremented on successful
|
* Packet Sent counter is decremented on successful
|
* transmission.
|
* transmission.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
|
|
static void wanpipe_delayed_transmit (unsigned long data)
|
static void wanpipe_delayed_transmit (unsigned long data)
|
{
|
{
|
struct sock *sk=(struct sock *)data;
|
struct sock *sk=(struct sock *)data;
|
struct sk_buff *skb;
|
struct sk_buff *skb;
|
netdevice_t *dev = sk->protinfo.af_wanpipe->dev;
|
netdevice_t *dev = sk->protinfo.af_wanpipe->dev;
|
sdla_t *card = (sdla_t*)sk->protinfo.af_wanpipe->card;
|
sdla_t *card = (sdla_t*)sk->protinfo.af_wanpipe->card;
|
|
|
if (!card || !dev){
|
if (!card || !dev){
|
clear_bit (0,&sk->protinfo.af_wanpipe->timer);
|
clear_bit (0,&sk->protinfo.af_wanpipe->timer);
|
DBG_PRINTK(KERN_INFO "wansock: Transmit delay, no dev or card\n");
|
DBG_PRINTK(KERN_INFO "wansock: Transmit delay, no dev or card\n");
|
return;
|
return;
|
}
|
}
|
|
|
if (sk->state != WANSOCK_CONNECTED || !sk->zapped){
|
if (sk->state != WANSOCK_CONNECTED || !sk->zapped){
|
clear_bit (0,&sk->protinfo.af_wanpipe->timer);
|
clear_bit (0,&sk->protinfo.af_wanpipe->timer);
|
DBG_PRINTK(KERN_INFO "wansock: Tx Timer, State not CONNECTED\n");
|
DBG_PRINTK(KERN_INFO "wansock: Tx Timer, State not CONNECTED\n");
|
return;
|
return;
|
}
|
}
|
|
|
/* If driver is executing command, we must offload
|
/* If driver is executing command, we must offload
|
* the board by not sending data. Otherwise a
|
* the board by not sending data. Otherwise a
|
* pending command will never get a free buffer
|
* pending command will never get a free buffer
|
* to execute */
|
* to execute */
|
if (atomic_read(&card->u.x.command_busy)){
|
if (atomic_read(&card->u.x.command_busy)){
|
sk->protinfo.af_wanpipe->tx_timer.expires=jiffies+SLOW_BACKOFF;
|
sk->protinfo.af_wanpipe->tx_timer.expires=jiffies+SLOW_BACKOFF;
|
add_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
add_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
DBG_PRINTK(KERN_INFO "wansock: Tx Timer, command bys BACKOFF\n");
|
DBG_PRINTK(KERN_INFO "wansock: Tx Timer, command bys BACKOFF\n");
|
return;
|
return;
|
}
|
}
|
|
|
|
|
if (test_and_set_bit(0,&wanpipe_tx_critical)){
|
if (test_and_set_bit(0,&wanpipe_tx_critical)){
|
printk(KERN_INFO "WanSock: Tx timer critical %s\n",dev->name);
|
printk(KERN_INFO "WanSock: Tx timer critical %s\n",dev->name);
|
sk->protinfo.af_wanpipe->tx_timer.expires=jiffies+SLOW_BACKOFF;
|
sk->protinfo.af_wanpipe->tx_timer.expires=jiffies+SLOW_BACKOFF;
|
add_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
add_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
return;
|
return;
|
}
|
}
|
|
|
/* Check for a packet in the fifo and send */
|
/* Check for a packet in the fifo and send */
|
if ((skb=skb_dequeue(&sk->write_queue)) != NULL){
|
if ((skb=skb_dequeue(&sk->write_queue)) != NULL){
|
|
|
if (dev->hard_start_xmit(skb, dev) != 0){
|
if (dev->hard_start_xmit(skb, dev) != 0){
|
|
|
/* Driver failed to transmit, re-enqueue
|
/* Driver failed to transmit, re-enqueue
|
* the packet and retry again later */
|
* the packet and retry again later */
|
skb_queue_head(&sk->write_queue,skb);
|
skb_queue_head(&sk->write_queue,skb);
|
clear_bit(0,&wanpipe_tx_critical);
|
clear_bit(0,&wanpipe_tx_critical);
|
return;
|
return;
|
}else{
|
}else{
|
|
|
/* Packet Sent successful. Check for more packets
|
/* Packet Sent successful. Check for more packets
|
* if more packets, re-trigger the transmit routine
|
* if more packets, re-trigger the transmit routine
|
* other wise exit
|
* other wise exit
|
*/
|
*/
|
atomic_dec(&sk->protinfo.af_wanpipe->packet_sent);
|
atomic_dec(&sk->protinfo.af_wanpipe->packet_sent);
|
|
|
if (skb_peek(&sk->write_queue) == NULL){
|
if (skb_peek(&sk->write_queue) == NULL){
|
/* If there is nothing to send, kick
|
/* If there is nothing to send, kick
|
* the poll routine, which will trigger
|
* the poll routine, which will trigger
|
* the application to send more data */
|
* the application to send more data */
|
sk->data_ready(sk,0);
|
sk->data_ready(sk,0);
|
clear_bit (0,&sk->protinfo.af_wanpipe->timer);
|
clear_bit (0,&sk->protinfo.af_wanpipe->timer);
|
}else{
|
}else{
|
/* Reschedule as fast as possible */
|
/* Reschedule as fast as possible */
|
sk->protinfo.af_wanpipe->tx_timer.expires=jiffies+1;
|
sk->protinfo.af_wanpipe->tx_timer.expires=jiffies+1;
|
add_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
add_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
}
|
}
|
}
|
}
|
}
|
}
|
clear_bit(0,&wanpipe_tx_critical);
|
clear_bit(0,&wanpipe_tx_critical);
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* execute_command
|
* execute_command
|
*
|
*
|
* Execute x25api commands. The atomic variable
|
* Execute x25api commands. The atomic variable
|
* chan->command is used to indicate to the driver that
|
* chan->command is used to indicate to the driver that
|
* command is pending for exection. The acutal command
|
* command is pending for exection. The acutal command
|
* structure is placed into a sock mbox structure
|
* structure is placed into a sock mbox structure
|
* (sk->protinfo.af_wanpipe->mbox).
|
* (sk->protinfo.af_wanpipe->mbox).
|
*
|
*
|
* The sock private structure, mbox is
|
* The sock private structure, mbox is
|
* used as shared memory between sock and the driver.
|
* used as shared memory between sock and the driver.
|
* Driver uses the sock mbox to execute the command
|
* Driver uses the sock mbox to execute the command
|
* and return the result.
|
* and return the result.
|
*
|
*
|
* For all command except PLACE CALL, the function
|
* For all command except PLACE CALL, the function
|
* waits for the result. PLACE CALL can be ether
|
* waits for the result. PLACE CALL can be ether
|
* blocking or nonblocking. The user sets this option
|
* blocking or nonblocking. The user sets this option
|
* via ioctl call.
|
* via ioctl call.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
|
|
static int execute_command(struct sock *sk, unsigned char cmd, unsigned int flags)
|
static int execute_command(struct sock *sk, unsigned char cmd, unsigned int flags)
|
{
|
{
|
netdevice_t *dev;
|
netdevice_t *dev;
|
wanpipe_common_t *chan=NULL;
|
wanpipe_common_t *chan=NULL;
|
int err=0;
|
int err=0;
|
DECLARE_WAITQUEUE(wait, current);
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
dev = dev_get_by_index(sk->bound_dev_if);
|
dev = dev_get_by_index(sk->bound_dev_if);
|
if (dev == NULL){
|
if (dev == NULL){
|
printk(KERN_INFO "wansock: Exec failed no dev %i\n",
|
printk(KERN_INFO "wansock: Exec failed no dev %i\n",
|
sk->bound_dev_if);
|
sk->bound_dev_if);
|
return -ENODEV;
|
return -ENODEV;
|
}
|
}
|
dev_put(dev);
|
dev_put(dev);
|
|
|
if ((chan=dev->priv) == NULL){
|
if ((chan=dev->priv) == NULL){
|
printk(KERN_INFO "wansock: Exec cmd failed no priv area\n");
|
printk(KERN_INFO "wansock: Exec cmd failed no priv area\n");
|
return -ENODEV;
|
return -ENODEV;
|
}
|
}
|
|
|
if (atomic_read(&chan->command)){
|
if (atomic_read(&chan->command)){
|
printk(KERN_INFO "wansock: ERROR: Command already running %x, %s\n",
|
printk(KERN_INFO "wansock: ERROR: Command already running %x, %s\n",
|
atomic_read(&chan->command),dev->name);
|
atomic_read(&chan->command),dev->name);
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
if (!sk->protinfo.af_wanpipe->mbox){
|
if (!sk->protinfo.af_wanpipe->mbox){
|
printk(KERN_INFO "wansock: In execute without MBOX\n");
|
printk(KERN_INFO "wansock: In execute without MBOX\n");
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.command=cmd;
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.command=cmd;
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.lcn =
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.lcn =
|
sk->protinfo.af_wanpipe->lcn;
|
sk->protinfo.af_wanpipe->lcn;
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.result=0x7F;
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.result=0x7F;
|
|
|
|
|
if (flags & O_NONBLOCK){
|
if (flags & O_NONBLOCK){
|
cmd |= 0x80;
|
cmd |= 0x80;
|
atomic_set(&chan->command, cmd);
|
atomic_set(&chan->command, cmd);
|
}else{
|
}else{
|
atomic_set(&chan->command, cmd);
|
atomic_set(&chan->command, cmd);
|
}
|
}
|
|
|
add_wait_queue(sk->sleep,&wait);
|
add_wait_queue(sk->sleep,&wait);
|
current->state = TASK_INTERRUPTIBLE;
|
current->state = TASK_INTERRUPTIBLE;
|
for (;;){
|
for (;;){
|
if (((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.result != 0x7F) {
|
if (((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.result != 0x7F) {
|
err = 0;
|
err = 0;
|
break;
|
break;
|
}
|
}
|
if (signal_pending(current)) {
|
if (signal_pending(current)) {
|
err = -ERESTARTSYS;
|
err = -ERESTARTSYS;
|
break;
|
break;
|
}
|
}
|
schedule();
|
schedule();
|
}
|
}
|
current->state = TASK_RUNNING;
|
current->state = TASK_RUNNING;
|
remove_wait_queue(sk->sleep,&wait);
|
remove_wait_queue(sk->sleep,&wait);
|
|
|
return err;
|
return err;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_destroy_timer
|
* wanpipe_destroy_timer
|
*
|
*
|
* Used by wanpipe_release, to delay release of
|
* Used by wanpipe_release, to delay release of
|
* the socket.
|
* the socket.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static void wanpipe_destroy_timer(unsigned long data)
|
static void wanpipe_destroy_timer(unsigned long data)
|
{
|
{
|
struct sock *sk=(struct sock *)data;
|
struct sock *sk=(struct sock *)data;
|
|
|
if ((!atomic_read(&sk->wmem_alloc) && !atomic_read(&sk->rmem_alloc)) ||
|
if ((!atomic_read(&sk->wmem_alloc) && !atomic_read(&sk->rmem_alloc)) ||
|
(++sk->protinfo.af_wanpipe->force == 5)) {
|
(++sk->protinfo.af_wanpipe->force == 5)) {
|
|
|
if (atomic_read(&sk->wmem_alloc) || atomic_read(&sk->rmem_alloc))
|
if (atomic_read(&sk->wmem_alloc) || atomic_read(&sk->rmem_alloc))
|
printk(KERN_INFO "wansock: Warning, Packet Discarded due to sock shutdown!\n");
|
printk(KERN_INFO "wansock: Warning, Packet Discarded due to sock shutdown!\n");
|
|
|
if (sk->protinfo.af_wanpipe){
|
if (sk->protinfo.af_wanpipe){
|
kfree(sk->protinfo.af_wanpipe);
|
kfree(sk->protinfo.af_wanpipe);
|
sk->protinfo.af_wanpipe=NULL;
|
sk->protinfo.af_wanpipe=NULL;
|
}
|
}
|
|
|
#ifdef LINUX_2_4
|
#ifdef LINUX_2_4
|
if (atomic_read(&sk->refcnt) != 1){
|
if (atomic_read(&sk->refcnt) != 1){
|
atomic_set(&sk->refcnt,1);
|
atomic_set(&sk->refcnt,1);
|
DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i ! :delay.\n",
|
DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i ! :delay.\n",
|
atomic_read(&sk->refcnt));
|
atomic_read(&sk->refcnt));
|
}
|
}
|
sock_put(sk);
|
sock_put(sk);
|
#else
|
#else
|
sk_free(sk);
|
sk_free(sk);
|
#endif
|
#endif
|
atomic_dec(&wanpipe_socks_nr);
|
atomic_dec(&wanpipe_socks_nr);
|
MOD_DEC_USE_COUNT;
|
MOD_DEC_USE_COUNT;
|
return;
|
return;
|
}
|
}
|
|
|
sk->timer.expires=jiffies+5*HZ;
|
sk->timer.expires=jiffies+5*HZ;
|
add_timer(&sk->timer);
|
add_timer(&sk->timer);
|
printk(KERN_INFO "wansock: packet sk destroy delayed\n");
|
printk(KERN_INFO "wansock: packet sk destroy delayed\n");
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_unlink_driver
|
* wanpipe_unlink_driver
|
*
|
*
|
* When the socket is released, this function is
|
* When the socket is released, this function is
|
* used to remove links that bind the sock and the
|
* used to remove links that bind the sock and the
|
* driver together.
|
* driver together.
|
*===========================================================*/
|
*===========================================================*/
|
static void wanpipe_unlink_driver (struct sock *sk)
|
static void wanpipe_unlink_driver (struct sock *sk)
|
{
|
{
|
netdevice_t *dev;
|
netdevice_t *dev;
|
wanpipe_common_t *chan=NULL;
|
wanpipe_common_t *chan=NULL;
|
|
|
sk->zapped=0;
|
sk->zapped=0;
|
sk->state = WANSOCK_DISCONNECTED;
|
sk->state = WANSOCK_DISCONNECTED;
|
sk->protinfo.af_wanpipe->dev = NULL;
|
sk->protinfo.af_wanpipe->dev = NULL;
|
|
|
dev = dev_get_by_index(sk->bound_dev_if);
|
dev = dev_get_by_index(sk->bound_dev_if);
|
if (!dev){
|
if (!dev){
|
printk(KERN_INFO "wansock: No dev on release\n");
|
printk(KERN_INFO "wansock: No dev on release\n");
|
return;
|
return;
|
}
|
}
|
dev_put(dev);
|
dev_put(dev);
|
|
|
if ((chan = dev->priv) == NULL){
|
if ((chan = dev->priv) == NULL){
|
printk(KERN_INFO "wansock: No Priv Area on release\n");
|
printk(KERN_INFO "wansock: No Priv Area on release\n");
|
return;
|
return;
|
}
|
}
|
|
|
set_bit(0,&chan->common_critical);
|
set_bit(0,&chan->common_critical);
|
chan->sk=NULL;
|
chan->sk=NULL;
|
chan->func=NULL;
|
chan->func=NULL;
|
chan->mbox=NULL;
|
chan->mbox=NULL;
|
chan->tx_timer=NULL;
|
chan->tx_timer=NULL;
|
clear_bit(0,&chan->common_critical);
|
clear_bit(0,&chan->common_critical);
|
release_device(dev);
|
release_device(dev);
|
|
|
return;
|
return;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_link_driver
|
* wanpipe_link_driver
|
*
|
*
|
* Upon successful bind(), sock is linked to a driver
|
* Upon successful bind(), sock is linked to a driver
|
* by binding in the wanpipe_rcv() bottom half handler
|
* by binding in the wanpipe_rcv() bottom half handler
|
* to the driver function pointer, as well as sock and
|
* to the driver function pointer, as well as sock and
|
* sock mailbox addresses. This way driver can pass
|
* sock mailbox addresses. This way driver can pass
|
* data up the socket.
|
* data up the socket.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static void wanpipe_link_driver (netdevice_t *dev, struct sock *sk)
|
static void wanpipe_link_driver (netdevice_t *dev, struct sock *sk)
|
{
|
{
|
wanpipe_common_t *chan = dev->priv;
|
wanpipe_common_t *chan = dev->priv;
|
if (!chan)
|
if (!chan)
|
return;
|
return;
|
set_bit(0,&chan->common_critical);
|
set_bit(0,&chan->common_critical);
|
chan->sk=sk;
|
chan->sk=sk;
|
chan->func=wanpipe_rcv;
|
chan->func=wanpipe_rcv;
|
chan->mbox=sk->protinfo.af_wanpipe->mbox;
|
chan->mbox=sk->protinfo.af_wanpipe->mbox;
|
chan->tx_timer = &sk->protinfo.af_wanpipe->tx_timer;
|
chan->tx_timer = &sk->protinfo.af_wanpipe->tx_timer;
|
sk->protinfo.af_wanpipe->dev=dev;
|
sk->protinfo.af_wanpipe->dev=dev;
|
sk->zapped = 1;
|
sk->zapped = 1;
|
clear_bit(0,&chan->common_critical);
|
clear_bit(0,&chan->common_critical);
|
}
|
}
|
|
|
|
|
/*============================================================
|
/*============================================================
|
* release_device
|
* release_device
|
*
|
*
|
* During sock release, clear a critical bit, which
|
* During sock release, clear a critical bit, which
|
* marks the device a being taken.
|
* marks the device a being taken.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
|
|
static void release_device (netdevice_t *dev)
|
static void release_device (netdevice_t *dev)
|
{
|
{
|
wanpipe_common_t *chan=dev->priv;
|
wanpipe_common_t *chan=dev->priv;
|
clear_bit(0,(void*)&chan->rw_bind);
|
clear_bit(0,(void*)&chan->rw_bind);
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_release
|
* wanpipe_release
|
*
|
*
|
* Close a PACKET socket. This is fairly simple. We
|
* Close a PACKET socket. This is fairly simple. We
|
* immediately go to 'closed' state and remove our
|
* immediately go to 'closed' state and remove our
|
* protocol entry in the device list.
|
* protocol entry in the device list.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
#ifdef LINUX_2_4
|
#ifdef LINUX_2_4
|
static int wanpipe_release(struct socket *sock)
|
static int wanpipe_release(struct socket *sock)
|
#else
|
#else
|
static int wanpipe_release(struct socket *sock, struct socket *peersock)
|
static int wanpipe_release(struct socket *sock, struct socket *peersock)
|
#endif
|
#endif
|
{
|
{
|
|
|
#ifndef LINUX_2_4
|
#ifndef LINUX_2_4
|
struct sk_buff *skb;
|
struct sk_buff *skb;
|
#endif
|
#endif
|
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
struct sock **skp;
|
struct sock **skp;
|
|
|
if (!sk)
|
if (!sk)
|
return 0;
|
return 0;
|
|
|
check_write_queue(sk);
|
check_write_queue(sk);
|
|
|
/* Kill the tx timer, if we don't kill it now, the timer
|
/* Kill the tx timer, if we don't kill it now, the timer
|
* will run after we kill the sock. Timer code will
|
* will run after we kill the sock. Timer code will
|
* try to access the sock which has been killed and cause
|
* try to access the sock which has been killed and cause
|
* kernel panic */
|
* kernel panic */
|
|
|
del_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
del_timer(&sk->protinfo.af_wanpipe->tx_timer);
|
|
|
/*
|
/*
|
* Unhook packet receive handler.
|
* Unhook packet receive handler.
|
*/
|
*/
|
|
|
if (sk->num == htons(X25_PROT) && sk->state != WANSOCK_DISCONNECTED && sk->zapped){
|
if (sk->num == htons(X25_PROT) && sk->state != WANSOCK_DISCONNECTED && sk->zapped){
|
netdevice_t *dev = dev_get_by_index(sk->bound_dev_if);
|
netdevice_t *dev = dev_get_by_index(sk->bound_dev_if);
|
wanpipe_common_t *chan;
|
wanpipe_common_t *chan;
|
if (dev){
|
if (dev){
|
chan=dev->priv;
|
chan=dev->priv;
|
atomic_set(&chan->disconnect,1);
|
atomic_set(&chan->disconnect,1);
|
DBG_PRINTK(KERN_INFO "wansock: Sending Clear Indication %i\n",
|
DBG_PRINTK(KERN_INFO "wansock: Sending Clear Indication %i\n",
|
sk->state);
|
sk->state);
|
dev_put(dev);
|
dev_put(dev);
|
}
|
}
|
}
|
}
|
|
|
set_bit(1,&wanpipe_tx_critical);
|
set_bit(1,&wanpipe_tx_critical);
|
write_lock(&wanpipe_sklist_lock);
|
write_lock(&wanpipe_sklist_lock);
|
for (skp = &wanpipe_sklist; *skp; skp = &(*skp)->next) {
|
for (skp = &wanpipe_sklist; *skp; skp = &(*skp)->next) {
|
if (*skp == sk) {
|
if (*skp == sk) {
|
*skp = sk->next;
|
*skp = sk->next;
|
__sock_put(sk);
|
__sock_put(sk);
|
break;
|
break;
|
}
|
}
|
}
|
}
|
write_unlock(&wanpipe_sklist_lock);
|
write_unlock(&wanpipe_sklist_lock);
|
clear_bit(1,&wanpipe_tx_critical);
|
clear_bit(1,&wanpipe_tx_critical);
|
|
|
|
|
|
|
release_driver(sk);
|
release_driver(sk);
|
|
|
|
|
/*
|
/*
|
* Now the socket is dead. No more input will appear.
|
* Now the socket is dead. No more input will appear.
|
*/
|
*/
|
|
|
sk->state_change(sk); /* It is useless. Just for sanity. */
|
sk->state_change(sk); /* It is useless. Just for sanity. */
|
|
|
sock->sk = NULL;
|
sock->sk = NULL;
|
sk->socket = NULL;
|
sk->socket = NULL;
|
sk->dead = 1;
|
sk->dead = 1;
|
|
|
/* Purge queues */
|
/* Purge queues */
|
#ifdef LINUX_2_4
|
#ifdef LINUX_2_4
|
skb_queue_purge(&sk->receive_queue);
|
skb_queue_purge(&sk->receive_queue);
|
skb_queue_purge(&sk->write_queue);
|
skb_queue_purge(&sk->write_queue);
|
skb_queue_purge(&sk->error_queue);
|
skb_queue_purge(&sk->error_queue);
|
#else
|
#else
|
|
|
while ((skb=skb_dequeue(&sk->receive_queue))!=NULL){
|
while ((skb=skb_dequeue(&sk->receive_queue))!=NULL){
|
kfree_skb(skb);
|
kfree_skb(skb);
|
}
|
}
|
while ((skb=skb_dequeue(&sk->error_queue))!=NULL){
|
while ((skb=skb_dequeue(&sk->error_queue))!=NULL){
|
kfree_skb(skb);
|
kfree_skb(skb);
|
}
|
}
|
while ((skb=skb_dequeue(&sk->write_queue))!=NULL){
|
while ((skb=skb_dequeue(&sk->write_queue))!=NULL){
|
kfree_skb(skb);
|
kfree_skb(skb);
|
}
|
}
|
#endif
|
#endif
|
if (atomic_read(&sk->rmem_alloc) || atomic_read(&sk->wmem_alloc)) {
|
if (atomic_read(&sk->rmem_alloc) || atomic_read(&sk->wmem_alloc)) {
|
del_timer(&sk->timer);
|
del_timer(&sk->timer);
|
printk(KERN_INFO "wansock: Killing in Timer R %i , W %i\n",
|
printk(KERN_INFO "wansock: Killing in Timer R %i , W %i\n",
|
atomic_read(&sk->rmem_alloc),atomic_read(&sk->wmem_alloc));
|
atomic_read(&sk->rmem_alloc),atomic_read(&sk->wmem_alloc));
|
sk->timer.data=(unsigned long)sk;
|
sk->timer.data=(unsigned long)sk;
|
sk->timer.expires=jiffies+HZ;
|
sk->timer.expires=jiffies+HZ;
|
sk->timer.function=wanpipe_destroy_timer;
|
sk->timer.function=wanpipe_destroy_timer;
|
add_timer(&sk->timer);
|
add_timer(&sk->timer);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
if (sk->protinfo.af_wanpipe){
|
if (sk->protinfo.af_wanpipe){
|
kfree(sk->protinfo.af_wanpipe);
|
kfree(sk->protinfo.af_wanpipe);
|
sk->protinfo.af_wanpipe=NULL;
|
sk->protinfo.af_wanpipe=NULL;
|
}
|
}
|
|
|
#ifdef LINUX_2_4
|
#ifdef LINUX_2_4
|
if (atomic_read(&sk->refcnt) != 1){
|
if (atomic_read(&sk->refcnt) != 1){
|
DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i !:release.\n",
|
DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i !:release.\n",
|
atomic_read(&sk->refcnt));
|
atomic_read(&sk->refcnt));
|
atomic_set(&sk->refcnt,1);
|
atomic_set(&sk->refcnt,1);
|
}
|
}
|
sock_put(sk);
|
sock_put(sk);
|
#else
|
#else
|
sk_free(sk);
|
sk_free(sk);
|
#endif
|
#endif
|
atomic_dec(&wanpipe_socks_nr);
|
atomic_dec(&wanpipe_socks_nr);
|
MOD_DEC_USE_COUNT;
|
MOD_DEC_USE_COUNT;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* check_write_queue
|
* check_write_queue
|
*
|
*
|
* During sock shutdown, if the sock state is
|
* During sock shutdown, if the sock state is
|
* WANSOCK_CONNECTED and there is transmit data
|
* WANSOCK_CONNECTED and there is transmit data
|
* pending. Wait until data is released
|
* pending. Wait until data is released
|
* before proceeding.
|
* before proceeding.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static void check_write_queue(struct sock *sk)
|
static void check_write_queue(struct sock *sk)
|
{
|
{
|
|
|
if (sk->state != WANSOCK_CONNECTED)
|
if (sk->state != WANSOCK_CONNECTED)
|
return;
|
return;
|
|
|
if (!atomic_read(&sk->wmem_alloc))
|
if (!atomic_read(&sk->wmem_alloc))
|
return;
|
return;
|
|
|
printk(KERN_INFO "wansock: MAJOR ERROR, Data lost on sock release !!!\n");
|
printk(KERN_INFO "wansock: MAJOR ERROR, Data lost on sock release !!!\n");
|
|
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* release_driver
|
* release_driver
|
*
|
*
|
* This function is called during sock shutdown, to
|
* This function is called during sock shutdown, to
|
* release any resources and links that bind the sock
|
* release any resources and links that bind the sock
|
* to the driver. It also changes the state of the
|
* to the driver. It also changes the state of the
|
* sock to WANSOCK_DISCONNECTED
|
* sock to WANSOCK_DISCONNECTED
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static void release_driver(struct sock *sk)
|
static void release_driver(struct sock *sk)
|
{
|
{
|
struct sk_buff *skb=NULL;
|
struct sk_buff *skb=NULL;
|
struct sock *deadsk=NULL;
|
struct sock *deadsk=NULL;
|
|
|
if (sk->state == WANSOCK_LISTEN || sk->state == WANSOCK_BIND_LISTEN){
|
if (sk->state == WANSOCK_LISTEN || sk->state == WANSOCK_BIND_LISTEN){
|
while ((skb=skb_dequeue(&sk->receive_queue))!=NULL){
|
while ((skb=skb_dequeue(&sk->receive_queue))!=NULL){
|
if ((deadsk = get_newsk_from_skb(skb))){
|
if ((deadsk = get_newsk_from_skb(skb))){
|
DBG_PRINTK (KERN_INFO "wansock: RELEASE: FOUND DEAD SOCK\n");
|
DBG_PRINTK (KERN_INFO "wansock: RELEASE: FOUND DEAD SOCK\n");
|
deadsk->dead=1;
|
deadsk->dead=1;
|
start_cleanup_timer(deadsk);
|
start_cleanup_timer(deadsk);
|
}
|
}
|
kfree_skb(skb);
|
kfree_skb(skb);
|
}
|
}
|
if (sk->zapped)
|
if (sk->zapped)
|
wanpipe_unlink_card(sk);
|
wanpipe_unlink_card(sk);
|
}else{
|
}else{
|
if (sk->zapped)
|
if (sk->zapped)
|
wanpipe_unlink_driver(sk);
|
wanpipe_unlink_driver(sk);
|
}
|
}
|
sk->state = WANSOCK_DISCONNECTED;
|
sk->state = WANSOCK_DISCONNECTED;
|
sk->bound_dev_if = 0;
|
sk->bound_dev_if = 0;
|
sk->zapped=0;
|
sk->zapped=0;
|
|
|
if (sk->protinfo.af_wanpipe){
|
if (sk->protinfo.af_wanpipe){
|
if (sk->protinfo.af_wanpipe->mbox){
|
if (sk->protinfo.af_wanpipe->mbox){
|
kfree(sk->protinfo.af_wanpipe->mbox);
|
kfree(sk->protinfo.af_wanpipe->mbox);
|
sk->protinfo.af_wanpipe->mbox=NULL;
|
sk->protinfo.af_wanpipe->mbox=NULL;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* start_cleanup_timer
|
* start_cleanup_timer
|
*
|
*
|
* If new incoming call's are pending but the socket
|
* If new incoming call's are pending but the socket
|
* is being released, start the timer which will
|
* is being released, start the timer which will
|
* envoke the kill routines for pending socks.
|
* envoke the kill routines for pending socks.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
|
|
static void start_cleanup_timer (struct sock *sk)
|
static void start_cleanup_timer (struct sock *sk)
|
{
|
{
|
del_timer(&sk->timer);
|
del_timer(&sk->timer);
|
sk->timer.data = (unsigned long)sk;
|
sk->timer.data = (unsigned long)sk;
|
sk->timer.expires = jiffies + HZ;
|
sk->timer.expires = jiffies + HZ;
|
sk->timer.function = wanpipe_kill_sock_timer;
|
sk->timer.function = wanpipe_kill_sock_timer;
|
add_timer(&sk->timer);
|
add_timer(&sk->timer);
|
}
|
}
|
|
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_kill_sock
|
* wanpipe_kill_sock
|
*
|
*
|
* This is a function which performs actual killing
|
* This is a function which performs actual killing
|
* of the sock. It releases socket resources,
|
* of the sock. It releases socket resources,
|
* and unlinks the sock from the driver.
|
* and unlinks the sock from the driver.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static void wanpipe_kill_sock_timer (unsigned long data)
|
static void wanpipe_kill_sock_timer (unsigned long data)
|
{
|
{
|
|
|
struct sock *sk = (struct sock *)data;
|
struct sock *sk = (struct sock *)data;
|
#ifndef LINUX_2_4
|
#ifndef LINUX_2_4
|
struct sk_buff *skb;
|
struct sk_buff *skb;
|
#endif
|
#endif
|
|
|
struct sock **skp;
|
struct sock **skp;
|
|
|
if (!sk)
|
if (!sk)
|
return;
|
return;
|
|
|
/* This functin can be called from interrupt. We must use
|
/* This functin can be called from interrupt. We must use
|
* appropriate locks */
|
* appropriate locks */
|
|
|
if (test_bit(1,&wanpipe_tx_critical)){
|
if (test_bit(1,&wanpipe_tx_critical)){
|
sk->timer.expires=jiffies+10;
|
sk->timer.expires=jiffies+10;
|
add_timer(&sk->timer);
|
add_timer(&sk->timer);
|
return;
|
return;
|
}
|
}
|
|
|
write_lock(&wanpipe_sklist_lock);
|
write_lock(&wanpipe_sklist_lock);
|
for (skp = &wanpipe_sklist; *skp; skp = &(*skp)->next) {
|
for (skp = &wanpipe_sklist; *skp; skp = &(*skp)->next) {
|
if (*skp == sk) {
|
if (*skp == sk) {
|
*skp = sk->next;
|
*skp = sk->next;
|
__sock_put(sk);
|
__sock_put(sk);
|
break;
|
break;
|
}
|
}
|
}
|
}
|
write_unlock(&wanpipe_sklist_lock);
|
write_unlock(&wanpipe_sklist_lock);
|
|
|
|
|
if (sk->num == htons(X25_PROT) && sk->state != WANSOCK_DISCONNECTED){
|
if (sk->num == htons(X25_PROT) && sk->state != WANSOCK_DISCONNECTED){
|
netdevice_t *dev = dev_get_by_index(sk->bound_dev_if);
|
netdevice_t *dev = dev_get_by_index(sk->bound_dev_if);
|
wanpipe_common_t *chan;
|
wanpipe_common_t *chan;
|
if (dev){
|
if (dev){
|
chan=dev->priv;
|
chan=dev->priv;
|
atomic_set(&chan->disconnect,1);
|
atomic_set(&chan->disconnect,1);
|
dev_put(dev);
|
dev_put(dev);
|
}
|
}
|
}
|
}
|
|
|
release_driver(sk);
|
release_driver(sk);
|
|
|
sk->socket = NULL;
|
sk->socket = NULL;
|
|
|
/* Purge queues */
|
/* Purge queues */
|
#ifdef LINUX_2_4
|
#ifdef LINUX_2_4
|
skb_queue_purge(&sk->receive_queue);
|
skb_queue_purge(&sk->receive_queue);
|
skb_queue_purge(&sk->write_queue);
|
skb_queue_purge(&sk->write_queue);
|
skb_queue_purge(&sk->error_queue);
|
skb_queue_purge(&sk->error_queue);
|
#else
|
#else
|
while ((skb=skb_dequeue(&sk->receive_queue)) != NULL){
|
while ((skb=skb_dequeue(&sk->receive_queue)) != NULL){
|
kfree_skb(skb);
|
kfree_skb(skb);
|
}
|
}
|
while ((skb=skb_dequeue(&sk->write_queue)) != NULL) {
|
while ((skb=skb_dequeue(&sk->write_queue)) != NULL) {
|
kfree_skb(skb);
|
kfree_skb(skb);
|
}
|
}
|
while ((skb=skb_dequeue(&sk->error_queue)) != NULL){
|
while ((skb=skb_dequeue(&sk->error_queue)) != NULL){
|
kfree_skb(skb);
|
kfree_skb(skb);
|
}
|
}
|
#endif
|
#endif
|
|
|
if (atomic_read(&sk->rmem_alloc) || atomic_read(&sk->wmem_alloc)) {
|
if (atomic_read(&sk->rmem_alloc) || atomic_read(&sk->wmem_alloc)) {
|
del_timer(&sk->timer);
|
del_timer(&sk->timer);
|
printk(KERN_INFO "wansock: Killing SOCK in Timer\n");
|
printk(KERN_INFO "wansock: Killing SOCK in Timer\n");
|
sk->timer.data=(unsigned long)sk;
|
sk->timer.data=(unsigned long)sk;
|
sk->timer.expires=jiffies+HZ;
|
sk->timer.expires=jiffies+HZ;
|
sk->timer.function=wanpipe_destroy_timer;
|
sk->timer.function=wanpipe_destroy_timer;
|
add_timer(&sk->timer);
|
add_timer(&sk->timer);
|
return;
|
return;
|
}
|
}
|
|
|
if (sk->protinfo.af_wanpipe){
|
if (sk->protinfo.af_wanpipe){
|
kfree(sk->protinfo.af_wanpipe);
|
kfree(sk->protinfo.af_wanpipe);
|
sk->protinfo.af_wanpipe=NULL;
|
sk->protinfo.af_wanpipe=NULL;
|
}
|
}
|
|
|
#ifdef LINUX_2_4
|
#ifdef LINUX_2_4
|
if (atomic_read(&sk->refcnt) != 1){
|
if (atomic_read(&sk->refcnt) != 1){
|
atomic_set(&sk->refcnt,1);
|
atomic_set(&sk->refcnt,1);
|
DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i ! :timer.\n",
|
DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i ! :timer.\n",
|
atomic_read(&sk->refcnt));
|
atomic_read(&sk->refcnt));
|
}
|
}
|
sock_put(sk);
|
sock_put(sk);
|
#else
|
#else
|
sk_free(sk);
|
sk_free(sk);
|
#endif
|
#endif
|
atomic_dec(&wanpipe_socks_nr);
|
atomic_dec(&wanpipe_socks_nr);
|
MOD_DEC_USE_COUNT;
|
MOD_DEC_USE_COUNT;
|
return;
|
return;
|
}
|
}
|
|
|
static void wanpipe_kill_sock_accept (struct sock *sk)
|
static void wanpipe_kill_sock_accept (struct sock *sk)
|
{
|
{
|
|
|
struct sock **skp;
|
struct sock **skp;
|
|
|
if (!sk)
|
if (!sk)
|
return;
|
return;
|
|
|
/* This functin can be called from interrupt. We must use
|
/* This functin can be called from interrupt. We must use
|
* appropriate locks */
|
* appropriate locks */
|
|
|
write_lock(&wanpipe_sklist_lock);
|
write_lock(&wanpipe_sklist_lock);
|
for (skp = &wanpipe_sklist; *skp; skp = &(*skp)->next) {
|
for (skp = &wanpipe_sklist; *skp; skp = &(*skp)->next) {
|
if (*skp == sk) {
|
if (*skp == sk) {
|
*skp = sk->next;
|
*skp = sk->next;
|
__sock_put(sk);
|
__sock_put(sk);
|
break;
|
break;
|
}
|
}
|
}
|
}
|
write_unlock(&wanpipe_sklist_lock);
|
write_unlock(&wanpipe_sklist_lock);
|
|
|
sk->socket = NULL;
|
sk->socket = NULL;
|
|
|
|
|
if (sk->protinfo.af_wanpipe){
|
if (sk->protinfo.af_wanpipe){
|
kfree(sk->protinfo.af_wanpipe);
|
kfree(sk->protinfo.af_wanpipe);
|
sk->protinfo.af_wanpipe=NULL;
|
sk->protinfo.af_wanpipe=NULL;
|
}
|
}
|
|
|
#ifdef LINUX_2_4
|
#ifdef LINUX_2_4
|
if (atomic_read(&sk->refcnt) != 1){
|
if (atomic_read(&sk->refcnt) != 1){
|
atomic_set(&sk->refcnt,1);
|
atomic_set(&sk->refcnt,1);
|
DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i ! :timer.\n",
|
DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i ! :timer.\n",
|
atomic_read(&sk->refcnt));
|
atomic_read(&sk->refcnt));
|
}
|
}
|
sock_put(sk);
|
sock_put(sk);
|
#else
|
#else
|
sk_free(sk);
|
sk_free(sk);
|
#endif
|
#endif
|
atomic_dec(&wanpipe_socks_nr);
|
atomic_dec(&wanpipe_socks_nr);
|
MOD_DEC_USE_COUNT;
|
MOD_DEC_USE_COUNT;
|
return;
|
return;
|
}
|
}
|
|
|
|
|
static void wanpipe_kill_sock_irq (struct sock *sk)
|
static void wanpipe_kill_sock_irq (struct sock *sk)
|
{
|
{
|
|
|
if (!sk)
|
if (!sk)
|
return;
|
return;
|
|
|
sk->socket = NULL;
|
sk->socket = NULL;
|
|
|
if (sk->protinfo.af_wanpipe){
|
if (sk->protinfo.af_wanpipe){
|
kfree(sk->protinfo.af_wanpipe);
|
kfree(sk->protinfo.af_wanpipe);
|
sk->protinfo.af_wanpipe=NULL;
|
sk->protinfo.af_wanpipe=NULL;
|
}
|
}
|
|
|
#ifdef LINUX_2_4
|
#ifdef LINUX_2_4
|
if (atomic_read(&sk->refcnt) != 1){
|
if (atomic_read(&sk->refcnt) != 1){
|
atomic_set(&sk->refcnt,1);
|
atomic_set(&sk->refcnt,1);
|
DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i !:listen.\n",
|
DBG_PRINTK(KERN_INFO "wansock: Error, wrong reference count: %i !:listen.\n",
|
atomic_read(&sk->refcnt));
|
atomic_read(&sk->refcnt));
|
}
|
}
|
sock_put(sk);
|
sock_put(sk);
|
#else
|
#else
|
sk_free(sk);
|
sk_free(sk);
|
#endif
|
#endif
|
atomic_dec(&wanpipe_socks_nr);
|
atomic_dec(&wanpipe_socks_nr);
|
MOD_DEC_USE_COUNT;
|
MOD_DEC_USE_COUNT;
|
return;
|
return;
|
}
|
}
|
|
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_do_bind
|
* wanpipe_do_bind
|
*
|
*
|
* Bottom half of the binding system call.
|
* Bottom half of the binding system call.
|
* Once the wanpipe_bind() function checks the
|
* Once the wanpipe_bind() function checks the
|
* legality of the call, this function binds the
|
* legality of the call, this function binds the
|
* sock to the driver.
|
* sock to the driver.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int wanpipe_do_bind(struct sock *sk, netdevice_t *dev, int protocol)
|
static int wanpipe_do_bind(struct sock *sk, netdevice_t *dev, int protocol)
|
{
|
{
|
wanpipe_common_t *chan=NULL;
|
wanpipe_common_t *chan=NULL;
|
int err=0;
|
int err=0;
|
|
|
if (sk->zapped){
|
if (sk->zapped){
|
err = -EALREADY;
|
err = -EALREADY;
|
goto bind_unlock_exit;
|
goto bind_unlock_exit;
|
}
|
}
|
|
|
sk->num = protocol;
|
sk->num = protocol;
|
|
|
if (protocol == 0){
|
if (protocol == 0){
|
release_device(dev);
|
release_device(dev);
|
err = -EINVAL;
|
err = -EINVAL;
|
goto bind_unlock_exit;
|
goto bind_unlock_exit;
|
}
|
}
|
|
|
if (dev) {
|
if (dev) {
|
if (dev->flags&IFF_UP) {
|
if (dev->flags&IFF_UP) {
|
chan=dev->priv;
|
chan=dev->priv;
|
sk->state = chan->state;
|
sk->state = chan->state;
|
|
|
if (sk->num == htons(X25_PROT) &&
|
if (sk->num == htons(X25_PROT) &&
|
sk->state != WANSOCK_DISCONNECTED &&
|
sk->state != WANSOCK_DISCONNECTED &&
|
sk->state != WANSOCK_CONNECTING){
|
sk->state != WANSOCK_CONNECTING){
|
DBG_PRINTK(KERN_INFO
|
DBG_PRINTK(KERN_INFO
|
"wansock: Binding to Device not DISCONNECTED %i\n",
|
"wansock: Binding to Device not DISCONNECTED %i\n",
|
sk->state);
|
sk->state);
|
release_device(dev);
|
release_device(dev);
|
err = -EAGAIN;
|
err = -EAGAIN;
|
goto bind_unlock_exit;
|
goto bind_unlock_exit;
|
}
|
}
|
|
|
wanpipe_link_driver(dev,sk);
|
wanpipe_link_driver(dev,sk);
|
sk->bound_dev_if = dev->ifindex;
|
sk->bound_dev_if = dev->ifindex;
|
|
|
/* X25 Specific option */
|
/* X25 Specific option */
|
if (sk->num == htons(X25_PROT))
|
if (sk->num == htons(X25_PROT))
|
sk->protinfo.af_wanpipe->svc = chan->svc;
|
sk->protinfo.af_wanpipe->svc = chan->svc;
|
|
|
} else {
|
} else {
|
sk->err = ENETDOWN;
|
sk->err = ENETDOWN;
|
sk->error_report(sk);
|
sk->error_report(sk);
|
release_device(dev);
|
release_device(dev);
|
err = -EINVAL;
|
err = -EINVAL;
|
}
|
}
|
} else {
|
} else {
|
err = -ENODEV;
|
err = -ENODEV;
|
}
|
}
|
bind_unlock_exit:
|
bind_unlock_exit:
|
/* FIXME where is this lock */
|
/* FIXME where is this lock */
|
|
|
return err;
|
return err;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_bind
|
* wanpipe_bind
|
*
|
*
|
* BIND() System call, which is bound to the AF_WANPIPE
|
* BIND() System call, which is bound to the AF_WANPIPE
|
* operations structure. It checks for correct wanpipe
|
* operations structure. It checks for correct wanpipe
|
* card name, and cross references interface names with
|
* card name, and cross references interface names with
|
* the card names. Thus, interface name must belong to
|
* the card names. Thus, interface name must belong to
|
* the actual card.
|
* the actual card.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
|
|
static int wanpipe_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
|
static int wanpipe_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
|
{
|
{
|
struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)uaddr;
|
struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)uaddr;
|
struct sock *sk=sock->sk;
|
struct sock *sk=sock->sk;
|
netdevice_t *dev = NULL;
|
netdevice_t *dev = NULL;
|
sdla_t *card=NULL;
|
sdla_t *card=NULL;
|
char name[15];
|
char name[15];
|
|
|
/*
|
/*
|
* Check legality
|
* Check legality
|
*/
|
*/
|
|
|
if (addr_len < sizeof(struct wan_sockaddr_ll)){
|
if (addr_len < sizeof(struct wan_sockaddr_ll)){
|
printk(KERN_INFO "wansock: Address length error\n");
|
printk(KERN_INFO "wansock: Address length error\n");
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
if (sll->sll_family != AF_WANPIPE){
|
if (sll->sll_family != AF_WANPIPE){
|
printk(KERN_INFO "wansock: Illegal family name specified.\n");
|
printk(KERN_INFO "wansock: Illegal family name specified.\n");
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
card = wanpipe_find_card (sll->sll_card);
|
card = wanpipe_find_card (sll->sll_card);
|
if (!card){
|
if (!card){
|
printk(KERN_INFO "wansock: Wanpipe card not found: %s\n",sll->sll_card);
|
printk(KERN_INFO "wansock: Wanpipe card not found: %s\n",sll->sll_card);
|
return -ENODEV;
|
return -ENODEV;
|
}else{
|
}else{
|
sk->protinfo.af_wanpipe->card = (void *)card;
|
sk->protinfo.af_wanpipe->card = (void *)card;
|
}
|
}
|
|
|
if (!strcmp(sll->sll_device,"svc_listen")){
|
if (!strcmp(sll->sll_device,"svc_listen")){
|
|
|
/* Bind a sock to a card structure for listening
|
/* Bind a sock to a card structure for listening
|
*/
|
*/
|
int err=0;
|
int err=0;
|
|
|
/* This is x25 specific area if protocol doesn't
|
/* This is x25 specific area if protocol doesn't
|
* match, return error */
|
* match, return error */
|
if (sll->sll_protocol != htons(X25_PROT))
|
if (sll->sll_protocol != htons(X25_PROT))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
err= wanpipe_link_card (sk);
|
err= wanpipe_link_card (sk);
|
if (err < 0)
|
if (err < 0)
|
return err;
|
return err;
|
|
|
if (sll->sll_protocol)
|
if (sll->sll_protocol)
|
sk->num = sll->sll_protocol;
|
sk->num = sll->sll_protocol;
|
sk->state = WANSOCK_BIND_LISTEN;
|
sk->state = WANSOCK_BIND_LISTEN;
|
return 0;
|
return 0;
|
|
|
}else if (!strcmp(sll->sll_device,"svc_connect")){
|
}else if (!strcmp(sll->sll_device,"svc_connect")){
|
|
|
/* This is x25 specific area if protocol doesn't
|
/* This is x25 specific area if protocol doesn't
|
* match, return error */
|
* match, return error */
|
if (sll->sll_protocol != htons(X25_PROT))
|
if (sll->sll_protocol != htons(X25_PROT))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
/* Find a free device
|
/* Find a free device
|
*/
|
*/
|
dev = wanpipe_find_free_dev(card);
|
dev = wanpipe_find_free_dev(card);
|
if (dev == NULL){
|
if (dev == NULL){
|
DBG_PRINTK(KERN_INFO "wansock: No free network devices for card %s\n",
|
DBG_PRINTK(KERN_INFO "wansock: No free network devices for card %s\n",
|
card->devname);
|
card->devname);
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
}else{
|
}else{
|
/* Bind a socket to a interface name
|
/* Bind a socket to a interface name
|
* This is used by PVC mostly
|
* This is used by PVC mostly
|
*/
|
*/
|
strncpy(name,sll->sll_device,14);
|
strncpy(name,sll->sll_device,14);
|
name[14]=0;
|
name[14]=0;
|
#ifdef LINUX_2_4
|
#ifdef LINUX_2_4
|
dev = dev_get_by_name(name);
|
dev = dev_get_by_name(name);
|
#else
|
#else
|
dev = dev_get(name);
|
dev = dev_get(name);
|
#endif
|
#endif
|
if (dev == NULL){
|
if (dev == NULL){
|
printk(KERN_INFO "wansock: Failed to get Dev from name: %s,\n",
|
printk(KERN_INFO "wansock: Failed to get Dev from name: %s,\n",
|
name);
|
name);
|
return -ENODEV;
|
return -ENODEV;
|
}
|
}
|
|
|
dev_put(dev);
|
dev_put(dev);
|
|
|
if (check_dev(dev, card)){
|
if (check_dev(dev, card)){
|
printk(KERN_INFO "wansock: Device %s, doesn't belong to card %s\n",
|
printk(KERN_INFO "wansock: Device %s, doesn't belong to card %s\n",
|
dev->name, card->devname);
|
dev->name, card->devname);
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
if (get_atomic_device (dev))
|
if (get_atomic_device (dev))
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
return wanpipe_do_bind(sk, dev, sll->sll_protocol ? : sk->num);
|
return wanpipe_do_bind(sk, dev, sll->sll_protocol ? : sk->num);
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* get_atomic_device
|
* get_atomic_device
|
*
|
*
|
* Sets a bit atomically which indicates that
|
* Sets a bit atomically which indicates that
|
* the interface is taken. This avoids race conditions.
|
* the interface is taken. This avoids race conditions.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
|
|
static inline int get_atomic_device (netdevice_t *dev)
|
static inline int get_atomic_device (netdevice_t *dev)
|
{
|
{
|
wanpipe_common_t *chan = dev->priv;
|
wanpipe_common_t *chan = dev->priv;
|
if (!test_and_set_bit(0,(void *)&chan->rw_bind)){
|
if (!test_and_set_bit(0,(void *)&chan->rw_bind)){
|
return 0;
|
return 0;
|
}
|
}
|
return 1;
|
return 1;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* check_dev
|
* check_dev
|
*
|
*
|
* Check that device name belongs to a particular card.
|
* Check that device name belongs to a particular card.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int check_dev (netdevice_t *dev, sdla_t *card)
|
static int check_dev (netdevice_t *dev, sdla_t *card)
|
{
|
{
|
netdevice_t* tmp_dev;
|
netdevice_t* tmp_dev;
|
|
|
for (tmp_dev = card->wandev.dev; tmp_dev; tmp_dev=*((netdevice_t**)tmp_dev->priv)){
|
for (tmp_dev = card->wandev.dev; tmp_dev; tmp_dev=*((netdevice_t**)tmp_dev->priv)){
|
if (tmp_dev->ifindex == dev->ifindex){
|
if (tmp_dev->ifindex == dev->ifindex){
|
return 0;
|
return 0;
|
}
|
}
|
}
|
}
|
return 1;
|
return 1;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_find_free_dev
|
* wanpipe_find_free_dev
|
*
|
*
|
* Find a free network interface. If found set atomic
|
* Find a free network interface. If found set atomic
|
* bit indicating that the interface is taken.
|
* bit indicating that the interface is taken.
|
* X25API Specific.
|
* X25API Specific.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
netdevice_t * wanpipe_find_free_dev (sdla_t *card)
|
netdevice_t * wanpipe_find_free_dev (sdla_t *card)
|
{
|
{
|
netdevice_t* dev;
|
netdevice_t* dev;
|
volatile wanpipe_common_t *chan;
|
volatile wanpipe_common_t *chan;
|
|
|
if (test_and_set_bit(0,&find_free_critical)){
|
if (test_and_set_bit(0,&find_free_critical)){
|
printk(KERN_INFO "CRITICAL in Find Free\n");
|
printk(KERN_INFO "CRITICAL in Find Free\n");
|
}
|
}
|
|
|
for (dev = card->wandev.dev; dev; dev=*((netdevice_t**)dev->priv)){
|
for (dev = card->wandev.dev; dev; dev=*((netdevice_t**)dev->priv)){
|
chan = dev->priv;
|
chan = dev->priv;
|
if (!chan)
|
if (!chan)
|
continue;
|
continue;
|
if (chan->usedby == API && chan->svc){
|
if (chan->usedby == API && chan->svc){
|
if (!get_atomic_device (dev)){
|
if (!get_atomic_device (dev)){
|
if (chan->state != WANSOCK_DISCONNECTED){
|
if (chan->state != WANSOCK_DISCONNECTED){
|
release_device(dev);
|
release_device(dev);
|
}else{
|
}else{
|
clear_bit(0,&find_free_critical);
|
clear_bit(0,&find_free_critical);
|
return dev;
|
return dev;
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
clear_bit(0,&find_free_critical);
|
clear_bit(0,&find_free_critical);
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_create
|
* wanpipe_create
|
*
|
*
|
* SOCKET() System call. It allocates a sock structure
|
* SOCKET() System call. It allocates a sock structure
|
* and adds the socket to the wanpipe_sk_list.
|
* and adds the socket to the wanpipe_sk_list.
|
* Crates AF_WANPIPE socket.
|
* Crates AF_WANPIPE socket.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int wanpipe_create(struct socket *sock, int protocol)
|
static int wanpipe_create(struct socket *sock, int protocol)
|
{
|
{
|
struct sock *sk;
|
struct sock *sk;
|
|
|
//FIXME: This checks for root user, SECURITY ?
|
//FIXME: This checks for root user, SECURITY ?
|
//if (!capable(CAP_NET_RAW))
|
//if (!capable(CAP_NET_RAW))
|
// return -EPERM;
|
// return -EPERM;
|
|
|
if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW)
|
if (sock->type != SOCK_DGRAM && sock->type != SOCK_RAW)
|
return -ESOCKTNOSUPPORT;
|
return -ESOCKTNOSUPPORT;
|
|
|
sock->state = SS_UNCONNECTED;
|
sock->state = SS_UNCONNECTED;
|
|
|
if ((sk = wanpipe_alloc_socket()) == NULL)
|
if ((sk = wanpipe_alloc_socket()) == NULL)
|
return -ENOBUFS;
|
return -ENOBUFS;
|
|
|
sk->reuse = 1;
|
sk->reuse = 1;
|
sock->ops = &wanpipe_ops;
|
sock->ops = &wanpipe_ops;
|
sock_init_data(sock,sk);
|
sock_init_data(sock,sk);
|
|
|
sk->zapped=0;
|
sk->zapped=0;
|
sk->family = PF_WANPIPE;
|
sk->family = PF_WANPIPE;
|
sk->num = protocol;
|
sk->num = protocol;
|
sk->state = WANSOCK_DISCONNECTED;
|
sk->state = WANSOCK_DISCONNECTED;
|
sk->ack_backlog = 0;
|
sk->ack_backlog = 0;
|
sk->bound_dev_if=0;
|
sk->bound_dev_if=0;
|
|
|
atomic_inc(&wanpipe_socks_nr);
|
atomic_inc(&wanpipe_socks_nr);
|
|
|
/* We must disable interrupts because the ISR
|
/* We must disable interrupts because the ISR
|
* can also change the list */
|
* can also change the list */
|
set_bit(1,&wanpipe_tx_critical);
|
set_bit(1,&wanpipe_tx_critical);
|
write_lock(&wanpipe_sklist_lock);
|
write_lock(&wanpipe_sklist_lock);
|
sk->next = wanpipe_sklist;
|
sk->next = wanpipe_sklist;
|
wanpipe_sklist = sk;
|
wanpipe_sklist = sk;
|
sock_hold(sk);
|
sock_hold(sk);
|
write_unlock(&wanpipe_sklist_lock);
|
write_unlock(&wanpipe_sklist_lock);
|
clear_bit(1,&wanpipe_tx_critical);
|
clear_bit(1,&wanpipe_tx_critical);
|
|
|
return(0);
|
return(0);
|
}
|
}
|
|
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_recvmsg
|
* wanpipe_recvmsg
|
*
|
*
|
* Pull a packet from our receive queue and hand it
|
* Pull a packet from our receive queue and hand it
|
* to the user. If necessary we block.
|
* to the user. If necessary we block.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int wanpipe_recvmsg(struct socket *sock, struct msghdr *msg, int len,
|
static int wanpipe_recvmsg(struct socket *sock, struct msghdr *msg, int len,
|
int flags, struct scm_cookie *scm)
|
int flags, struct scm_cookie *scm)
|
{
|
{
|
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
struct sk_buff *skb;
|
struct sk_buff *skb;
|
int copied, err=-ENOBUFS;
|
int copied, err=-ENOBUFS;
|
|
|
|
|
/*
|
/*
|
* If the address length field is there to be filled in, we fill
|
* If the address length field is there to be filled in, we fill
|
* it in now.
|
* it in now.
|
*/
|
*/
|
|
|
msg->msg_namelen = sizeof(struct wan_sockaddr_ll);
|
msg->msg_namelen = sizeof(struct wan_sockaddr_ll);
|
|
|
/*
|
/*
|
* Call the generic datagram receiver. This handles all sorts
|
* Call the generic datagram receiver. This handles all sorts
|
* of horrible races and re-entrancy so we can forget about it
|
* of horrible races and re-entrancy so we can forget about it
|
* in the protocol layers.
|
* in the protocol layers.
|
*
|
*
|
* Now it will return ENETDOWN, if device have just gone down,
|
* Now it will return ENETDOWN, if device have just gone down,
|
* but then it will block.
|
* but then it will block.
|
*/
|
*/
|
|
|
if (flags & MSG_OOB){
|
if (flags & MSG_OOB){
|
skb=skb_dequeue(&sk->error_queue);
|
skb=skb_dequeue(&sk->error_queue);
|
}else{
|
}else{
|
skb=skb_recv_datagram(sk,flags,1,&err);
|
skb=skb_recv_datagram(sk,flags,1,&err);
|
}
|
}
|
/*
|
/*
|
* An error occurred so return it. Because skb_recv_datagram()
|
* An error occurred so return it. Because skb_recv_datagram()
|
* handles the blocking we don't see and worry about blocking
|
* handles the blocking we don't see and worry about blocking
|
* retries.
|
* retries.
|
*/
|
*/
|
|
|
if(skb==NULL)
|
if(skb==NULL)
|
goto out;
|
goto out;
|
|
|
/*
|
/*
|
* You lose any data beyond the buffer you gave. If it worries a
|
* You lose any data beyond the buffer you gave. If it worries a
|
* user program they can ask the device for its MTU anyway.
|
* user program they can ask the device for its MTU anyway.
|
*/
|
*/
|
|
|
copied = skb->len;
|
copied = skb->len;
|
if (copied > len)
|
if (copied > len)
|
{
|
{
|
copied=len;
|
copied=len;
|
msg->msg_flags|=MSG_TRUNC;
|
msg->msg_flags|=MSG_TRUNC;
|
}
|
}
|
|
|
wanpipe_wakeup_driver(sk);
|
wanpipe_wakeup_driver(sk);
|
|
|
/* We can't use skb_copy_datagram here */
|
/* We can't use skb_copy_datagram here */
|
err = memcpy_toiovec(msg->msg_iov, skb->data, copied);
|
err = memcpy_toiovec(msg->msg_iov, skb->data, copied);
|
if (err)
|
if (err)
|
goto out_free;
|
goto out_free;
|
|
|
#ifdef LINUX_2_1
|
#ifdef LINUX_2_1
|
sk->stamp=skb->stamp;
|
sk->stamp=skb->stamp;
|
#else
|
#else
|
sock_recv_timestamp(msg, sk, skb);
|
sock_recv_timestamp(msg, sk, skb);
|
#endif
|
#endif
|
|
|
if (msg->msg_name)
|
if (msg->msg_name)
|
memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
|
memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
|
|
|
/*
|
/*
|
* Free or return the buffer as appropriate. Again this
|
* Free or return the buffer as appropriate. Again this
|
* hides all the races and re-entrancy issues from us.
|
* hides all the races and re-entrancy issues from us.
|
*/
|
*/
|
err = (flags&MSG_TRUNC) ? skb->len : copied;
|
err = (flags&MSG_TRUNC) ? skb->len : copied;
|
|
|
out_free:
|
out_free:
|
skb_free_datagram(sk, skb);
|
skb_free_datagram(sk, skb);
|
out:
|
out:
|
return err;
|
return err;
|
}
|
}
|
|
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_wakeup_driver
|
* wanpipe_wakeup_driver
|
*
|
*
|
* If socket receive buffer is full and driver cannot
|
* If socket receive buffer is full and driver cannot
|
* pass data up the sock, it sets a packet_block flag.
|
* pass data up the sock, it sets a packet_block flag.
|
* This function check that flag and if sock receive
|
* This function check that flag and if sock receive
|
* queue has room it kicks the driver BH handler.
|
* queue has room it kicks the driver BH handler.
|
*
|
*
|
* This way, driver doesn't have to poll the sock
|
* This way, driver doesn't have to poll the sock
|
* receive queue.
|
* receive queue.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static void wanpipe_wakeup_driver(struct sock *sk)
|
static void wanpipe_wakeup_driver(struct sock *sk)
|
{
|
{
|
netdevice_t *dev=NULL;
|
netdevice_t *dev=NULL;
|
wanpipe_common_t *chan=NULL;
|
wanpipe_common_t *chan=NULL;
|
|
|
dev = dev_get_by_index(sk->bound_dev_if);
|
dev = dev_get_by_index(sk->bound_dev_if);
|
if (!dev)
|
if (!dev)
|
return;
|
return;
|
|
|
dev_put(dev);
|
dev_put(dev);
|
|
|
if ((chan = dev->priv) == NULL)
|
if ((chan = dev->priv) == NULL)
|
return;
|
return;
|
|
|
if (atomic_read(&chan->receive_block)){
|
if (atomic_read(&chan->receive_block)){
|
if (atomic_read(&sk->rmem_alloc) < ((unsigned)sk->rcvbuf*0.9) ){
|
if (atomic_read(&sk->rmem_alloc) < ((unsigned)sk->rcvbuf*0.9) ){
|
printk(KERN_INFO "wansock: Queuing task for wanpipe\n");
|
printk(KERN_INFO "wansock: Queuing task for wanpipe\n");
|
atomic_set(&chan->receive_block,0);
|
atomic_set(&chan->receive_block,0);
|
wanpipe_queue_tq(&chan->wanpipe_task);
|
wanpipe_queue_tq(&chan->wanpipe_task);
|
wanpipe_mark_bh();
|
wanpipe_mark_bh();
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_getname
|
* wanpipe_getname
|
*
|
*
|
* I don't know what to do with this yet.
|
* I don't know what to do with this yet.
|
* User can use this function to get sock address
|
* User can use this function to get sock address
|
* information. Not very useful for Sangoma's purposes.
|
* information. Not very useful for Sangoma's purposes.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
|
|
static int wanpipe_getname(struct socket *sock, struct sockaddr *uaddr,
|
static int wanpipe_getname(struct socket *sock, struct sockaddr *uaddr,
|
int *uaddr_len, int peer)
|
int *uaddr_len, int peer)
|
{
|
{
|
netdevice_t *dev;
|
netdevice_t *dev;
|
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)uaddr;
|
struct wan_sockaddr_ll *sll = (struct wan_sockaddr_ll*)uaddr;
|
|
|
sll->sll_family = AF_WANPIPE;
|
sll->sll_family = AF_WANPIPE;
|
sll->sll_ifindex = sk->bound_dev_if;
|
sll->sll_ifindex = sk->bound_dev_if;
|
sll->sll_protocol = sk->num;
|
sll->sll_protocol = sk->num;
|
dev = dev_get_by_index(sk->bound_dev_if);
|
dev = dev_get_by_index(sk->bound_dev_if);
|
if (dev) {
|
if (dev) {
|
sll->sll_hatype = dev->type;
|
sll->sll_hatype = dev->type;
|
sll->sll_halen = dev->addr_len;
|
sll->sll_halen = dev->addr_len;
|
memcpy(sll->sll_addr, dev->dev_addr, dev->addr_len);
|
memcpy(sll->sll_addr, dev->dev_addr, dev->addr_len);
|
} else {
|
} else {
|
sll->sll_hatype = 0; /* Bad: we have no ARPHRD_UNSPEC */
|
sll->sll_hatype = 0; /* Bad: we have no ARPHRD_UNSPEC */
|
sll->sll_halen = 0;
|
sll->sll_halen = 0;
|
}
|
}
|
*uaddr_len = sizeof(*sll);
|
*uaddr_len = sizeof(*sll);
|
|
|
dev_put(dev);
|
dev_put(dev);
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_notifier
|
* wanpipe_notifier
|
*
|
*
|
* If driver turns off network interface, this function
|
* If driver turns off network interface, this function
|
* will be envoked. Currently I treate it as a
|
* will be envoked. Currently I treate it as a
|
* call disconnect. More thought should go into this
|
* call disconnect. More thought should go into this
|
* function.
|
* function.
|
*
|
*
|
* FIXME: More thought should go into this function.
|
* FIXME: More thought should go into this function.
|
*
|
*
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int wanpipe_notifier(struct notifier_block *this, unsigned long msg, void *data)
|
static int wanpipe_notifier(struct notifier_block *this, unsigned long msg, void *data)
|
{
|
{
|
struct sock *sk;
|
struct sock *sk;
|
netdevice_t *dev = (netdevice_t*)data;
|
netdevice_t *dev = (netdevice_t*)data;
|
struct wanpipe_opt *po;
|
struct wanpipe_opt *po;
|
|
|
for (sk = wanpipe_sklist; sk; sk = sk->next) {
|
for (sk = wanpipe_sklist; sk; sk = sk->next) {
|
|
|
if ((po = sk->protinfo.af_wanpipe)==NULL)
|
if ((po = sk->protinfo.af_wanpipe)==NULL)
|
continue;
|
continue;
|
if (dev == NULL)
|
if (dev == NULL)
|
continue;
|
continue;
|
|
|
switch (msg) {
|
switch (msg) {
|
case NETDEV_DOWN:
|
case NETDEV_DOWN:
|
case NETDEV_UNREGISTER:
|
case NETDEV_UNREGISTER:
|
if (dev->ifindex == sk->bound_dev_if) {
|
if (dev->ifindex == sk->bound_dev_if) {
|
printk(KERN_INFO "wansock: Device down %s\n",dev->name);
|
printk(KERN_INFO "wansock: Device down %s\n",dev->name);
|
if (sk->zapped){
|
if (sk->zapped){
|
wanpipe_unlink_driver(sk);
|
wanpipe_unlink_driver(sk);
|
sk->err = ENETDOWN;
|
sk->err = ENETDOWN;
|
sk->error_report(sk);
|
sk->error_report(sk);
|
}
|
}
|
|
|
if (msg == NETDEV_UNREGISTER) {
|
if (msg == NETDEV_UNREGISTER) {
|
printk(KERN_INFO "wansock: Unregistering Device: %s\n",
|
printk(KERN_INFO "wansock: Unregistering Device: %s\n",
|
dev->name);
|
dev->name);
|
wanpipe_unlink_driver(sk);
|
wanpipe_unlink_driver(sk);
|
sk->bound_dev_if = 0;
|
sk->bound_dev_if = 0;
|
}
|
}
|
}
|
}
|
break;
|
break;
|
case NETDEV_UP:
|
case NETDEV_UP:
|
if (dev->ifindex == sk->bound_dev_if && sk->num && !sk->zapped) {
|
if (dev->ifindex == sk->bound_dev_if && sk->num && !sk->zapped) {
|
printk(KERN_INFO "wansock: Registering Device: %s\n",
|
printk(KERN_INFO "wansock: Registering Device: %s\n",
|
dev->name);
|
dev->name);
|
wanpipe_link_driver(dev,sk);
|
wanpipe_link_driver(dev,sk);
|
}
|
}
|
break;
|
break;
|
}
|
}
|
}
|
}
|
return NOTIFY_DONE;
|
return NOTIFY_DONE;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_ioctl
|
* wanpipe_ioctl
|
*
|
*
|
* Execute a user commands, and set socket options.
|
* Execute a user commands, and set socket options.
|
*
|
*
|
* FIXME: More thought should go into this function.
|
* FIXME: More thought should go into this function.
|
*
|
*
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int wanpipe_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
static int wanpipe_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
|
{
|
{
|
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
int err;
|
int err;
|
int pid;
|
int pid;
|
|
|
switch(cmd)
|
switch(cmd)
|
{
|
{
|
case FIOSETOWN:
|
case FIOSETOWN:
|
case SIOCSPGRP:
|
case SIOCSPGRP:
|
err = get_user(pid, (int *) arg);
|
err = get_user(pid, (int *) arg);
|
if (err)
|
if (err)
|
return err;
|
return err;
|
if (current->pid != pid && current->pgrp != -pid &&
|
if (current->pid != pid && current->pgrp != -pid &&
|
!capable(CAP_NET_ADMIN))
|
!capable(CAP_NET_ADMIN))
|
return -EPERM;
|
return -EPERM;
|
sk->proc = pid;
|
sk->proc = pid;
|
return(0);
|
return(0);
|
case FIOGETOWN:
|
case FIOGETOWN:
|
case SIOCGPGRP:
|
case SIOCGPGRP:
|
return put_user(sk->proc, (int *)arg);
|
return put_user(sk->proc, (int *)arg);
|
case SIOCGSTAMP:
|
case SIOCGSTAMP:
|
if(sk->stamp.tv_sec==0)
|
if(sk->stamp.tv_sec==0)
|
return -ENOENT;
|
return -ENOENT;
|
err = -EFAULT;
|
err = -EFAULT;
|
if (!copy_to_user((void *)arg, &sk->stamp, sizeof(struct timeval)))
|
if (!copy_to_user((void *)arg, &sk->stamp, sizeof(struct timeval)))
|
err = 0;
|
err = 0;
|
return err;
|
return err;
|
|
|
case SIOC_WANPIPE_CHECK_TX:
|
case SIOC_WANPIPE_CHECK_TX:
|
|
|
return atomic_read(&sk->wmem_alloc);
|
return atomic_read(&sk->wmem_alloc);
|
|
|
case SIOC_WANPIPE_SOCK_STATE:
|
case SIOC_WANPIPE_SOCK_STATE:
|
|
|
if (sk->state == WANSOCK_CONNECTED)
|
if (sk->state == WANSOCK_CONNECTED)
|
return 0;
|
return 0;
|
|
|
return 1;
|
return 1;
|
|
|
|
|
case SIOC_WANPIPE_GET_CALL_DATA:
|
case SIOC_WANPIPE_GET_CALL_DATA:
|
|
|
return get_ioctl_cmd (sk,(void*)arg);
|
return get_ioctl_cmd (sk,(void*)arg);
|
|
|
case SIOC_WANPIPE_SET_CALL_DATA:
|
case SIOC_WANPIPE_SET_CALL_DATA:
|
|
|
return set_ioctl_cmd (sk,(void*)arg);
|
return set_ioctl_cmd (sk,(void*)arg);
|
|
|
case SIOC_WANPIPE_ACCEPT_CALL:
|
case SIOC_WANPIPE_ACCEPT_CALL:
|
case SIOC_WANPIPE_CLEAR_CALL:
|
case SIOC_WANPIPE_CLEAR_CALL:
|
case SIOC_WANPIPE_RESET_CALL:
|
case SIOC_WANPIPE_RESET_CALL:
|
|
|
if ((err=set_ioctl_cmd(sk,(void*)arg)) < 0)
|
if ((err=set_ioctl_cmd(sk,(void*)arg)) < 0)
|
return err;
|
return err;
|
|
|
err=wanpipe_exec_cmd(sk,cmd,0);
|
err=wanpipe_exec_cmd(sk,cmd,0);
|
get_ioctl_cmd(sk,(void*)arg);
|
get_ioctl_cmd(sk,(void*)arg);
|
return err;
|
return err;
|
|
|
case SIOC_WANPIPE_DEBUG:
|
case SIOC_WANPIPE_DEBUG:
|
|
|
return wanpipe_debug(sk,(void*)arg);
|
return wanpipe_debug(sk,(void*)arg);
|
|
|
case SIOC_WANPIPE_SET_NONBLOCK:
|
case SIOC_WANPIPE_SET_NONBLOCK:
|
|
|
if (sk->state != WANSOCK_DISCONNECTED)
|
if (sk->state != WANSOCK_DISCONNECTED)
|
return -EINVAL;
|
return -EINVAL;
|
|
|
sock->file->f_flags |= O_NONBLOCK;
|
sock->file->f_flags |= O_NONBLOCK;
|
return 0;
|
return 0;
|
|
|
case SIOCGIFFLAGS:
|
case SIOCGIFFLAGS:
|
#ifndef CONFIG_INET
|
#ifndef CONFIG_INET
|
case SIOCSIFFLAGS:
|
case SIOCSIFFLAGS:
|
#endif
|
#endif
|
case SIOCGIFCONF:
|
case SIOCGIFCONF:
|
case SIOCGIFMETRIC:
|
case SIOCGIFMETRIC:
|
case SIOCSIFMETRIC:
|
case SIOCSIFMETRIC:
|
case SIOCGIFMEM:
|
case SIOCGIFMEM:
|
case SIOCSIFMEM:
|
case SIOCSIFMEM:
|
case SIOCGIFMTU:
|
case SIOCGIFMTU:
|
case SIOCSIFMTU:
|
case SIOCSIFMTU:
|
case SIOCSIFLINK:
|
case SIOCSIFLINK:
|
case SIOCGIFHWADDR:
|
case SIOCGIFHWADDR:
|
case SIOCSIFHWADDR:
|
case SIOCSIFHWADDR:
|
case SIOCSIFMAP:
|
case SIOCSIFMAP:
|
case SIOCGIFMAP:
|
case SIOCGIFMAP:
|
case SIOCSIFSLAVE:
|
case SIOCSIFSLAVE:
|
case SIOCGIFSLAVE:
|
case SIOCGIFSLAVE:
|
case SIOCGIFINDEX:
|
case SIOCGIFINDEX:
|
case SIOCGIFNAME:
|
case SIOCGIFNAME:
|
case SIOCGIFCOUNT:
|
case SIOCGIFCOUNT:
|
case SIOCSIFHWBROADCAST:
|
case SIOCSIFHWBROADCAST:
|
return(dev_ioctl(cmd,(void *) arg));
|
return(dev_ioctl(cmd,(void *) arg));
|
|
|
#ifdef CONFIG_INET
|
#ifdef CONFIG_INET
|
case SIOCADDRT:
|
case SIOCADDRT:
|
case SIOCDELRT:
|
case SIOCDELRT:
|
case SIOCDARP:
|
case SIOCDARP:
|
case SIOCGARP:
|
case SIOCGARP:
|
case SIOCSARP:
|
case SIOCSARP:
|
case SIOCDRARP:
|
case SIOCDRARP:
|
case SIOCGRARP:
|
case SIOCGRARP:
|
case SIOCSRARP:
|
case SIOCSRARP:
|
case SIOCGIFADDR:
|
case SIOCGIFADDR:
|
case SIOCSIFADDR:
|
case SIOCSIFADDR:
|
case SIOCGIFBRDADDR:
|
case SIOCGIFBRDADDR:
|
case SIOCSIFBRDADDR:
|
case SIOCSIFBRDADDR:
|
case SIOCGIFNETMASK:
|
case SIOCGIFNETMASK:
|
case SIOCSIFNETMASK:
|
case SIOCSIFNETMASK:
|
case SIOCGIFDSTADDR:
|
case SIOCGIFDSTADDR:
|
case SIOCSIFDSTADDR:
|
case SIOCSIFDSTADDR:
|
case SIOCSIFFLAGS:
|
case SIOCSIFFLAGS:
|
case SIOCADDDLCI:
|
case SIOCADDDLCI:
|
case SIOCDELDLCI:
|
case SIOCDELDLCI:
|
return inet_dgram_ops.ioctl(sock, cmd, arg);
|
return inet_dgram_ops.ioctl(sock, cmd, arg);
|
#endif
|
#endif
|
|
|
default:
|
default:
|
if ((cmd >= SIOCDEVPRIVATE) &&
|
if ((cmd >= SIOCDEVPRIVATE) &&
|
(cmd <= (SIOCDEVPRIVATE + 15)))
|
(cmd <= (SIOCDEVPRIVATE + 15)))
|
return(dev_ioctl(cmd,(void *) arg));
|
return(dev_ioctl(cmd,(void *) arg));
|
|
|
#ifdef CONFIG_NET_RADIO
|
#ifdef CONFIG_NET_RADIO
|
if((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST))
|
if((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST))
|
return(dev_ioctl(cmd,(void *) arg));
|
return(dev_ioctl(cmd,(void *) arg));
|
#endif
|
#endif
|
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
}
|
}
|
/*NOTREACHED*/
|
/*NOTREACHED*/
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* wanpipe_debug
|
* wanpipe_debug
|
*
|
*
|
* This function will pass up information about all
|
* This function will pass up information about all
|
* active sockets.
|
* active sockets.
|
*
|
*
|
* FIXME: More thought should go into this function.
|
* FIXME: More thought should go into this function.
|
*
|
*
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int wanpipe_debug (struct sock *origsk, void *arg)
|
static int wanpipe_debug (struct sock *origsk, void *arg)
|
{
|
{
|
struct sock *sk=NULL;
|
struct sock *sk=NULL;
|
netdevice_t *dev=NULL;
|
netdevice_t *dev=NULL;
|
wanpipe_common_t *chan=NULL;
|
wanpipe_common_t *chan=NULL;
|
int cnt=0, err=0;
|
int cnt=0, err=0;
|
wan_debug_t *dbg_data = (wan_debug_t *)arg;
|
wan_debug_t *dbg_data = (wan_debug_t *)arg;
|
|
|
for (sk = wanpipe_sklist; sk; sk = sk->next){
|
for (sk = wanpipe_sklist; sk; sk = sk->next){
|
|
|
if (sk == origsk){
|
if (sk == origsk){
|
continue;
|
continue;
|
}
|
}
|
|
|
if ((err=put_user(1, &dbg_data->debug[cnt].free)))
|
if ((err=put_user(1, &dbg_data->debug[cnt].free)))
|
return err;
|
return err;
|
if ((err=put_user(sk->state, &dbg_data->debug[cnt].sk_state)))
|
if ((err=put_user(sk->state, &dbg_data->debug[cnt].sk_state)))
|
return err;
|
return err;
|
if ((err=put_user(sk->rcvbuf, &dbg_data->debug[cnt].rcvbuf)))
|
if ((err=put_user(sk->rcvbuf, &dbg_data->debug[cnt].rcvbuf)))
|
return err;
|
return err;
|
if ((err=put_user(atomic_read(&sk->rmem_alloc), &dbg_data->debug[cnt].rmem)))
|
if ((err=put_user(atomic_read(&sk->rmem_alloc), &dbg_data->debug[cnt].rmem)))
|
return err;
|
return err;
|
if ((err=put_user(atomic_read(&sk->wmem_alloc), &dbg_data->debug[cnt].wmem)))
|
if ((err=put_user(atomic_read(&sk->wmem_alloc), &dbg_data->debug[cnt].wmem)))
|
return err;
|
return err;
|
if ((err=put_user(sk->sndbuf, &dbg_data->debug[cnt].sndbuf)))
|
if ((err=put_user(sk->sndbuf, &dbg_data->debug[cnt].sndbuf)))
|
return err;
|
return err;
|
if ((err=put_user(sk_count, &dbg_data->debug[cnt].sk_count)))
|
if ((err=put_user(sk_count, &dbg_data->debug[cnt].sk_count)))
|
return err;
|
return err;
|
if ((err=put_user(sk->protinfo.af_wanpipe->poll_cnt,
|
if ((err=put_user(sk->protinfo.af_wanpipe->poll_cnt,
|
&dbg_data->debug[cnt].poll_cnt)))
|
&dbg_data->debug[cnt].poll_cnt)))
|
return err;
|
return err;
|
if ((err=put_user(sk->bound_dev_if, &dbg_data->debug[cnt].bound)))
|
if ((err=put_user(sk->bound_dev_if, &dbg_data->debug[cnt].bound)))
|
return err;
|
return err;
|
|
|
if (sk->bound_dev_if){
|
if (sk->bound_dev_if){
|
dev = dev_get_by_index(sk->bound_dev_if);
|
dev = dev_get_by_index(sk->bound_dev_if);
|
if (!dev)
|
if (!dev)
|
continue;
|
continue;
|
|
|
chan=dev->priv;
|
chan=dev->priv;
|
dev_put(dev);
|
dev_put(dev);
|
|
|
if ((err=put_user(chan->state, &dbg_data->debug[cnt].d_state)))
|
if ((err=put_user(chan->state, &dbg_data->debug[cnt].d_state)))
|
return err;
|
return err;
|
if ((err=put_user(chan->svc, &dbg_data->debug[cnt].svc)))
|
if ((err=put_user(chan->svc, &dbg_data->debug[cnt].svc)))
|
return err;
|
return err;
|
|
|
if ((err=put_user(atomic_read(&chan->command),
|
if ((err=put_user(atomic_read(&chan->command),
|
&dbg_data->debug[cnt].command)))
|
&dbg_data->debug[cnt].command)))
|
return err;
|
return err;
|
|
|
|
|
if (sk->protinfo.af_wanpipe){
|
if (sk->protinfo.af_wanpipe){
|
sdla_t *card = (sdla_t*)sk->protinfo.af_wanpipe->card;
|
sdla_t *card = (sdla_t*)sk->protinfo.af_wanpipe->card;
|
|
|
if (card){
|
if (card){
|
if ((err=put_user(atomic_read(&card->u.x.command_busy),
|
if ((err=put_user(atomic_read(&card->u.x.command_busy),
|
&dbg_data->debug[cnt].cmd_busy)))
|
&dbg_data->debug[cnt].cmd_busy)))
|
return err;
|
return err;
|
}
|
}
|
|
|
if ((err=put_user(sk->protinfo.af_wanpipe->lcn,
|
if ((err=put_user(sk->protinfo.af_wanpipe->lcn,
|
&dbg_data->debug[cnt].lcn)))
|
&dbg_data->debug[cnt].lcn)))
|
return err;
|
return err;
|
|
|
if (sk->protinfo.af_wanpipe->mbox){
|
if (sk->protinfo.af_wanpipe->mbox){
|
if ((err=put_user(1, &dbg_data->debug[cnt].mbox)))
|
if ((err=put_user(1, &dbg_data->debug[cnt].mbox)))
|
return err;
|
return err;
|
}
|
}
|
}
|
}
|
|
|
if ((err=put_user(atomic_read(&chan->receive_block),
|
if ((err=put_user(atomic_read(&chan->receive_block),
|
&dbg_data->debug[cnt].rblock)))
|
&dbg_data->debug[cnt].rblock)))
|
return err;
|
return err;
|
|
|
if (copy_to_user(dbg_data->debug[cnt].name, dev->name, strlen(dev->name)))
|
if (copy_to_user(dbg_data->debug[cnt].name, dev->name, strlen(dev->name)))
|
return -EFAULT;
|
return -EFAULT;
|
}
|
}
|
|
|
if (++cnt == MAX_NUM_DEBUG)
|
if (++cnt == MAX_NUM_DEBUG)
|
break;
|
break;
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* get_ioctl_cmd
|
* get_ioctl_cmd
|
*
|
*
|
* Pass up the contents of socket MBOX to the user.
|
* Pass up the contents of socket MBOX to the user.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int get_ioctl_cmd (struct sock *sk, void *arg)
|
static int get_ioctl_cmd (struct sock *sk, void *arg)
|
{
|
{
|
x25api_t *usr_data = (x25api_t *)arg;
|
x25api_t *usr_data = (x25api_t *)arg;
|
mbox_cmd_t *mbox_ptr;
|
mbox_cmd_t *mbox_ptr;
|
int err;
|
int err;
|
|
|
if (usr_data == NULL)
|
if (usr_data == NULL)
|
return -EINVAL;
|
return -EINVAL;
|
|
|
if (!sk->protinfo.af_wanpipe->mbox){
|
if (!sk->protinfo.af_wanpipe->mbox){
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
mbox_ptr = (mbox_cmd_t *)sk->protinfo.af_wanpipe->mbox;
|
mbox_ptr = (mbox_cmd_t *)sk->protinfo.af_wanpipe->mbox;
|
|
|
if ((err=put_user(mbox_ptr->cmd.qdm, &usr_data->hdr.qdm)))
|
if ((err=put_user(mbox_ptr->cmd.qdm, &usr_data->hdr.qdm)))
|
return err;
|
return err;
|
if ((err=put_user(mbox_ptr->cmd.cause, &usr_data->hdr.cause)))
|
if ((err=put_user(mbox_ptr->cmd.cause, &usr_data->hdr.cause)))
|
return err;
|
return err;
|
if ((err=put_user(mbox_ptr->cmd.diagn, &usr_data->hdr.diagn)))
|
if ((err=put_user(mbox_ptr->cmd.diagn, &usr_data->hdr.diagn)))
|
return err;
|
return err;
|
if ((err=put_user(mbox_ptr->cmd.length, &usr_data->hdr.length)))
|
if ((err=put_user(mbox_ptr->cmd.length, &usr_data->hdr.length)))
|
return err;
|
return err;
|
if ((err=put_user(mbox_ptr->cmd.result, &usr_data->hdr.result)))
|
if ((err=put_user(mbox_ptr->cmd.result, &usr_data->hdr.result)))
|
return err;
|
return err;
|
if ((err=put_user(mbox_ptr->cmd.lcn, &usr_data->hdr.lcn)))
|
if ((err=put_user(mbox_ptr->cmd.lcn, &usr_data->hdr.lcn)))
|
return err;
|
return err;
|
|
|
if (mbox_ptr->cmd.length > 0){
|
if (mbox_ptr->cmd.length > 0){
|
if (mbox_ptr->cmd.length > X25_MAX_DATA)
|
if (mbox_ptr->cmd.length > X25_MAX_DATA)
|
return -EINVAL;
|
return -EINVAL;
|
|
|
if (copy_to_user(usr_data->data, mbox_ptr->data, mbox_ptr->cmd.length)){
|
if (copy_to_user(usr_data->data, mbox_ptr->data, mbox_ptr->cmd.length)){
|
printk(KERN_INFO "wansock: Copy failed !!!\n");
|
printk(KERN_INFO "wansock: Copy failed !!!\n");
|
return -EFAULT;
|
return -EFAULT;
|
}
|
}
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*============================================================
|
/*============================================================
|
* set_ioctl_cmd
|
* set_ioctl_cmd
|
*
|
*
|
* Before command can be execute, socket MBOX must
|
* Before command can be execute, socket MBOX must
|
* be created, and initialized with user data.
|
* be created, and initialized with user data.
|
*===========================================================*/
|
*===========================================================*/
|
|
|
static int set_ioctl_cmd (struct sock *sk, void *arg)
|
static int set_ioctl_cmd (struct sock *sk, void *arg)
|
{
|
{
|
x25api_t *usr_data = (x25api_t *)arg;
|
x25api_t *usr_data = (x25api_t *)arg;
|
mbox_cmd_t *mbox_ptr;
|
mbox_cmd_t *mbox_ptr;
|
int err;
|
int err;
|
|
|
if (!sk->protinfo.af_wanpipe->mbox){
|
if (!sk->protinfo.af_wanpipe->mbox){
|
void *mbox_ptr;
|
void *mbox_ptr;
|
netdevice_t *dev = dev_get_by_index(sk->bound_dev_if);
|
netdevice_t *dev = dev_get_by_index(sk->bound_dev_if);
|
if (!dev)
|
if (!dev)
|
return -ENODEV;
|
return -ENODEV;
|
|
|
dev_put(dev);
|
dev_put(dev);
|
|
|
if ((mbox_ptr = kmalloc(sizeof(mbox_cmd_t), GFP_ATOMIC)) == NULL)
|
if ((mbox_ptr = kmalloc(sizeof(mbox_cmd_t), GFP_ATOMIC)) == NULL)
|
return -ENOMEM;
|
return -ENOMEM;
|
|
|
memset(mbox_ptr, 0, sizeof(mbox_cmd_t));
|
memset(mbox_ptr, 0, sizeof(mbox_cmd_t));
|
sk->protinfo.af_wanpipe->mbox = mbox_ptr;
|
sk->protinfo.af_wanpipe->mbox = mbox_ptr;
|
|
|
wanpipe_link_driver(dev,sk);
|
wanpipe_link_driver(dev,sk);
|
}
|
}
|
|
|
mbox_ptr = (mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox;
|
mbox_ptr = (mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox;
|
memset(mbox_ptr, 0, sizeof(mbox_cmd_t));
|
memset(mbox_ptr, 0, sizeof(mbox_cmd_t));
|
|
|
if (usr_data == NULL){
|
if (usr_data == NULL){
|
return 0;
|
return 0;
|
}
|
}
|
if ((err=get_user(mbox_ptr->cmd.qdm, &usr_data->hdr.qdm)))
|
if ((err=get_user(mbox_ptr->cmd.qdm, &usr_data->hdr.qdm)))
|
return err;
|
return err;
|
if ((err=get_user(mbox_ptr->cmd.cause, &usr_data->hdr.cause)))
|
if ((err=get_user(mbox_ptr->cmd.cause, &usr_data->hdr.cause)))
|
return err;
|
return err;
|
if ((err=get_user(mbox_ptr->cmd.diagn, &usr_data->hdr.diagn)))
|
if ((err=get_user(mbox_ptr->cmd.diagn, &usr_data->hdr.diagn)))
|
return err;
|
return err;
|
if ((err=get_user(mbox_ptr->cmd.length, &usr_data->hdr.length)))
|
if ((err=get_user(mbox_ptr->cmd.length, &usr_data->hdr.length)))
|
return err;
|
return err;
|
if ((err=get_user(mbox_ptr->cmd.result, &usr_data->hdr.result)))
|
if ((err=get_user(mbox_ptr->cmd.result, &usr_data->hdr.result)))
|
return err;
|
return err;
|
|
|
if (mbox_ptr->cmd.length > 0){
|
if (mbox_ptr->cmd.length > 0){
|
if (mbox_ptr->cmd.length > X25_MAX_DATA)
|
if (mbox_ptr->cmd.length > X25_MAX_DATA)
|
return -EINVAL;
|
return -EINVAL;
|
|
|
if (copy_from_user(mbox_ptr->data, usr_data->data, mbox_ptr->cmd.length)){
|
if (copy_from_user(mbox_ptr->data, usr_data->data, mbox_ptr->cmd.length)){
|
printk(KERN_INFO "Copy failed\n");
|
printk(KERN_INFO "Copy failed\n");
|
return -EFAULT;
|
return -EFAULT;
|
}
|
}
|
}
|
}
|
return 0;
|
return 0;
|
}
|
}
|
|
|
|
|
/*======================================================================
|
/*======================================================================
|
* wanpipe_poll
|
* wanpipe_poll
|
*
|
*
|
* Datagram poll: Again totally generic. This also handles
|
* Datagram poll: Again totally generic. This also handles
|
* sequenced packet sockets providing the socket receive queue
|
* sequenced packet sockets providing the socket receive queue
|
* is only ever holding data ready to receive.
|
* is only ever holding data ready to receive.
|
*
|
*
|
* Note: when you _don't_ use this routine for this protocol,
|
* Note: when you _don't_ use this routine for this protocol,
|
* and you use a different write policy from sock_writeable()
|
* and you use a different write policy from sock_writeable()
|
* then please supply your own write_space callback.
|
* then please supply your own write_space callback.
|
*=====================================================================*/
|
*=====================================================================*/
|
|
|
unsigned int wanpipe_poll(struct file * file, struct socket *sock, poll_table *wait)
|
unsigned int wanpipe_poll(struct file * file, struct socket *sock, poll_table *wait)
|
{
|
{
|
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
unsigned int mask;
|
unsigned int mask;
|
|
|
++sk->protinfo.af_wanpipe->poll_cnt;
|
++sk->protinfo.af_wanpipe->poll_cnt;
|
|
|
poll_wait(file, sk->sleep, wait);
|
poll_wait(file, sk->sleep, wait);
|
mask = 0;
|
mask = 0;
|
|
|
/* exceptional events? */
|
/* exceptional events? */
|
if (sk->err || !skb_queue_empty(&sk->error_queue)){
|
if (sk->err || !skb_queue_empty(&sk->error_queue)){
|
mask |= POLLPRI;
|
mask |= POLLPRI;
|
return mask;
|
return mask;
|
}
|
}
|
if (sk->shutdown & RCV_SHUTDOWN)
|
if (sk->shutdown & RCV_SHUTDOWN)
|
mask |= POLLHUP;
|
mask |= POLLHUP;
|
|
|
/* readable? */
|
/* readable? */
|
if (!skb_queue_empty(&sk->receive_queue)){
|
if (!skb_queue_empty(&sk->receive_queue)){
|
mask |= POLLIN | POLLRDNORM;
|
mask |= POLLIN | POLLRDNORM;
|
}
|
}
|
|
|
/* connection hasn't started yet */
|
/* connection hasn't started yet */
|
if (sk->state == WANSOCK_CONNECTING){
|
if (sk->state == WANSOCK_CONNECTING){
|
return mask;
|
return mask;
|
}
|
}
|
|
|
if (sk->state == WANSOCK_DISCONNECTED){
|
if (sk->state == WANSOCK_DISCONNECTED){
|
mask = POLLPRI;
|
mask = POLLPRI;
|
return mask;
|
return mask;
|
}
|
}
|
|
|
/* This check blocks the user process if there is
|
/* This check blocks the user process if there is
|
* a packet already queued in the socket write queue.
|
* a packet already queued in the socket write queue.
|
* This option is only for X25API protocol, for other
|
* This option is only for X25API protocol, for other
|
* protocol like chdlc enable streaming mode,
|
* protocol like chdlc enable streaming mode,
|
* where multiple packets can be pending in the socket
|
* where multiple packets can be pending in the socket
|
* transmit queue */
|
* transmit queue */
|
|
|
if (sk->num == htons(X25_PROT)){
|
if (sk->num == htons(X25_PROT)){
|
if (atomic_read(&sk->protinfo.af_wanpipe->packet_sent))
|
if (atomic_read(&sk->protinfo.af_wanpipe->packet_sent))
|
return mask;
|
return mask;
|
}
|
}
|
|
|
/* writable? */
|
/* writable? */
|
if (sock_writeable(sk)){
|
if (sock_writeable(sk)){
|
mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
|
mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
|
}else{
|
}else{
|
#ifdef LINUX_2_4
|
#ifdef LINUX_2_4
|
set_bit(SOCK_ASYNC_NOSPACE, &sk->socket->flags);
|
set_bit(SOCK_ASYNC_NOSPACE, &sk->socket->flags);
|
#else
|
#else
|
sk->socket->flags |= SO_NOSPACE;
|
sk->socket->flags |= SO_NOSPACE;
|
#endif
|
#endif
|
}
|
}
|
|
|
return mask;
|
return mask;
|
}
|
}
|
|
|
/*======================================================================
|
/*======================================================================
|
* wanpipe_listen
|
* wanpipe_listen
|
*
|
*
|
* X25API Specific function. Set a socket into LISTENING MODE.
|
* X25API Specific function. Set a socket into LISTENING MODE.
|
*=====================================================================*/
|
*=====================================================================*/
|
|
|
|
|
static int wanpipe_listen(struct socket *sock, int backlog)
|
static int wanpipe_listen(struct socket *sock, int backlog)
|
{
|
{
|
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
|
|
/* This is x25 specific area if protocol doesn't
|
/* This is x25 specific area if protocol doesn't
|
* match, return error */
|
* match, return error */
|
if (sk->num != htons(X25_PROT))
|
if (sk->num != htons(X25_PROT))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
if (sk->state == WANSOCK_BIND_LISTEN) {
|
if (sk->state == WANSOCK_BIND_LISTEN) {
|
|
|
sk->max_ack_backlog = backlog;
|
sk->max_ack_backlog = backlog;
|
sk->state = WANSOCK_LISTEN;
|
sk->state = WANSOCK_LISTEN;
|
return 0;
|
return 0;
|
}else{
|
}else{
|
printk(KERN_INFO "wansock: Listening sock was not binded\n");
|
printk(KERN_INFO "wansock: Listening sock was not binded\n");
|
}
|
}
|
|
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
/*======================================================================
|
/*======================================================================
|
* wanpipe_link_card
|
* wanpipe_link_card
|
*
|
*
|
* Connects the listening socket to the driver
|
* Connects the listening socket to the driver
|
*=====================================================================*/
|
*=====================================================================*/
|
|
|
static int wanpipe_link_card (struct sock *sk)
|
static int wanpipe_link_card (struct sock *sk)
|
{
|
{
|
sdla_t *card;
|
sdla_t *card;
|
|
|
card = (sdla_t*)sk->protinfo.af_wanpipe->card;
|
card = (sdla_t*)sk->protinfo.af_wanpipe->card;
|
if (!card)
|
if (!card)
|
return -ENOMEM;
|
return -ENOMEM;
|
|
|
if ((card->sk != NULL) || (card->func != NULL)){
|
if ((card->sk != NULL) || (card->func != NULL)){
|
printk(KERN_INFO "wansock: Listening queue is already established\n");
|
printk(KERN_INFO "wansock: Listening queue is already established\n");
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
card->sk=sk;
|
card->sk=sk;
|
card->func=wanpipe_listen_rcv;
|
card->func=wanpipe_listen_rcv;
|
sk->zapped=1;
|
sk->zapped=1;
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*======================================================================
|
/*======================================================================
|
* wanpipe_listen
|
* wanpipe_listen
|
*
|
*
|
* X25API Specific function. Disconnect listening socket from
|
* X25API Specific function. Disconnect listening socket from
|
* the driver.
|
* the driver.
|
*=====================================================================*/
|
*=====================================================================*/
|
|
|
static void wanpipe_unlink_card (struct sock *sk)
|
static void wanpipe_unlink_card (struct sock *sk)
|
{
|
{
|
sdla_t *card;
|
sdla_t *card;
|
|
|
card = (sdla_t*)sk->protinfo.af_wanpipe->card;
|
card = (sdla_t*)sk->protinfo.af_wanpipe->card;
|
|
|
if (card){
|
if (card){
|
card->sk=NULL;
|
card->sk=NULL;
|
card->func=NULL;
|
card->func=NULL;
|
}
|
}
|
}
|
}
|
|
|
/*======================================================================
|
/*======================================================================
|
* wanpipe_exec_cmd
|
* wanpipe_exec_cmd
|
*
|
*
|
* Ioctl function calls this function to execute user command.
|
* Ioctl function calls this function to execute user command.
|
* Connect() sytem call also calls this function to execute
|
* Connect() sytem call also calls this function to execute
|
* place call. This function blocks until command is executed.
|
* place call. This function blocks until command is executed.
|
*=====================================================================*/
|
*=====================================================================*/
|
|
|
static int wanpipe_exec_cmd(struct sock *sk, int cmd, unsigned int flags)
|
static int wanpipe_exec_cmd(struct sock *sk, int cmd, unsigned int flags)
|
{
|
{
|
int err = -EINVAL;
|
int err = -EINVAL;
|
mbox_cmd_t *mbox_ptr = (mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox;
|
mbox_cmd_t *mbox_ptr = (mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox;
|
|
|
if (!mbox_ptr){
|
if (!mbox_ptr){
|
printk(KERN_INFO "NO MBOX PTR !!!!!\n");
|
printk(KERN_INFO "NO MBOX PTR !!!!!\n");
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
/* This is x25 specific area if protocol doesn't
|
/* This is x25 specific area if protocol doesn't
|
* match, return error */
|
* match, return error */
|
if (sk->num != htons(X25_PROT))
|
if (sk->num != htons(X25_PROT))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
|
|
switch (cmd){
|
switch (cmd){
|
|
|
case SIOC_WANPIPE_ACCEPT_CALL:
|
case SIOC_WANPIPE_ACCEPT_CALL:
|
|
|
if (sk->state != WANSOCK_CONNECTING){
|
if (sk->state != WANSOCK_CONNECTING){
|
err = -EHOSTDOWN;
|
err = -EHOSTDOWN;
|
break;
|
break;
|
}
|
}
|
|
|
err = execute_command(sk,X25_ACCEPT_CALL,0);
|
err = execute_command(sk,X25_ACCEPT_CALL,0);
|
if (err < 0)
|
if (err < 0)
|
break;
|
break;
|
|
|
/* Update. Mar6 2000.
|
/* Update. Mar6 2000.
|
* Do not set the sock lcn number here, since
|
* Do not set the sock lcn number here, since
|
* it is done in wanpipe_listen_rcv().
|
* it is done in wanpipe_listen_rcv().
|
*/
|
*/
|
if (sk->state == WANSOCK_CONNECTED){
|
if (sk->state == WANSOCK_CONNECTED){
|
sk->protinfo.af_wanpipe->lcn =
|
sk->protinfo.af_wanpipe->lcn =
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.lcn;
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.lcn;
|
DBG_PRINTK(KERN_INFO "\nwansock: Accept OK %i\n",
|
DBG_PRINTK(KERN_INFO "\nwansock: Accept OK %i\n",
|
sk->protinfo.af_wanpipe->lcn );
|
sk->protinfo.af_wanpipe->lcn );
|
err = 0;
|
err = 0;
|
|
|
}else{
|
}else{
|
DBG_PRINTK (KERN_INFO "\nwansock: Accept Failed %i\n",
|
DBG_PRINTK (KERN_INFO "\nwansock: Accept Failed %i\n",
|
sk->protinfo.af_wanpipe->lcn);
|
sk->protinfo.af_wanpipe->lcn);
|
sk->protinfo.af_wanpipe->lcn = 0;
|
sk->protinfo.af_wanpipe->lcn = 0;
|
err = -ECONNREFUSED;
|
err = -ECONNREFUSED;
|
}
|
}
|
break;
|
break;
|
|
|
case SIOC_WANPIPE_CLEAR_CALL:
|
case SIOC_WANPIPE_CLEAR_CALL:
|
|
|
if (sk->state == WANSOCK_DISCONNECTED){
|
if (sk->state == WANSOCK_DISCONNECTED){
|
err = -EINVAL;
|
err = -EINVAL;
|
break;
|
break;
|
}
|
}
|
|
|
|
|
/* Check if data buffers are pending for transmission,
|
/* Check if data buffers are pending for transmission,
|
* if so, check whether user wants to wait until data
|
* if so, check whether user wants to wait until data
|
* is transmitted, or clear a call and drop packets */
|
* is transmitted, or clear a call and drop packets */
|
|
|
if (atomic_read(&sk->wmem_alloc) || check_driver_busy(sk)){
|
if (atomic_read(&sk->wmem_alloc) || check_driver_busy(sk)){
|
mbox_cmd_t *mbox = sk->protinfo.af_wanpipe->mbox;
|
mbox_cmd_t *mbox = sk->protinfo.af_wanpipe->mbox;
|
if (mbox->cmd.qdm & 0x80){
|
if (mbox->cmd.qdm & 0x80){
|
mbox->cmd.result = 0x35;
|
mbox->cmd.result = 0x35;
|
err = -EAGAIN;
|
err = -EAGAIN;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
sk->state = WANSOCK_DISCONNECTING;
|
sk->state = WANSOCK_DISCONNECTING;
|
|
|
err = execute_command(sk,X25_CLEAR_CALL,0);
|
err = execute_command(sk,X25_CLEAR_CALL,0);
|
if (err < 0)
|
if (err < 0)
|
break;
|
break;
|
|
|
err = -ECONNREFUSED;
|
err = -ECONNREFUSED;
|
if (sk->state == WANSOCK_DISCONNECTED){
|
if (sk->state == WANSOCK_DISCONNECTED){
|
DBG_PRINTK(KERN_INFO "\nwansock: CLEAR OK %i\n",
|
DBG_PRINTK(KERN_INFO "\nwansock: CLEAR OK %i\n",
|
sk->protinfo.af_wanpipe->lcn);
|
sk->protinfo.af_wanpipe->lcn);
|
sk->protinfo.af_wanpipe->lcn=0;
|
sk->protinfo.af_wanpipe->lcn=0;
|
err = 0;
|
err = 0;
|
}
|
}
|
break;
|
break;
|
|
|
case SIOC_WANPIPE_RESET_CALL:
|
case SIOC_WANPIPE_RESET_CALL:
|
|
|
if (sk->state != WANSOCK_CONNECTED){
|
if (sk->state != WANSOCK_CONNECTED){
|
err = -EINVAL;
|
err = -EINVAL;
|
break;
|
break;
|
}
|
}
|
|
|
|
|
/* Check if data buffers are pending for transmission,
|
/* Check if data buffers are pending for transmission,
|
* if so, check whether user wants to wait until data
|
* if so, check whether user wants to wait until data
|
* is transmitted, or reset a call and drop packets */
|
* is transmitted, or reset a call and drop packets */
|
|
|
if (atomic_read(&sk->wmem_alloc) || check_driver_busy(sk)){
|
if (atomic_read(&sk->wmem_alloc) || check_driver_busy(sk)){
|
mbox_cmd_t *mbox = sk->protinfo.af_wanpipe->mbox;
|
mbox_cmd_t *mbox = sk->protinfo.af_wanpipe->mbox;
|
if (mbox->cmd.qdm & 0x80){
|
if (mbox->cmd.qdm & 0x80){
|
mbox->cmd.result = 0x35;
|
mbox->cmd.result = 0x35;
|
err = -EAGAIN;
|
err = -EAGAIN;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
|
|
err = execute_command(sk, X25_RESET,0);
|
err = execute_command(sk, X25_RESET,0);
|
if (err < 0)
|
if (err < 0)
|
break;
|
break;
|
|
|
err = mbox_ptr->cmd.result;
|
err = mbox_ptr->cmd.result;
|
break;
|
break;
|
|
|
|
|
case X25_PLACE_CALL:
|
case X25_PLACE_CALL:
|
|
|
err=execute_command(sk,X25_PLACE_CALL,flags);
|
err=execute_command(sk,X25_PLACE_CALL,flags);
|
if (err < 0)
|
if (err < 0)
|
break;
|
break;
|
|
|
if (sk->state == WANSOCK_CONNECTED){
|
if (sk->state == WANSOCK_CONNECTED){
|
|
|
sk->protinfo.af_wanpipe->lcn =
|
sk->protinfo.af_wanpipe->lcn =
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.lcn;
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.lcn;
|
|
|
DBG_PRINTK(KERN_INFO "\nwansock: PLACE CALL OK %i\n",
|
DBG_PRINTK(KERN_INFO "\nwansock: PLACE CALL OK %i\n",
|
sk->protinfo.af_wanpipe->lcn);
|
sk->protinfo.af_wanpipe->lcn);
|
err = 0;
|
err = 0;
|
|
|
}else if (sk->state == WANSOCK_CONNECTING && (flags & O_NONBLOCK)){
|
}else if (sk->state == WANSOCK_CONNECTING && (flags & O_NONBLOCK)){
|
sk->protinfo.af_wanpipe->lcn =
|
sk->protinfo.af_wanpipe->lcn =
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.lcn;
|
((mbox_cmd_t*)sk->protinfo.af_wanpipe->mbox)->cmd.lcn;
|
DBG_PRINTK(KERN_INFO "\nwansock: Place Call OK: Waiting %i\n",
|
DBG_PRINTK(KERN_INFO "\nwansock: Place Call OK: Waiting %i\n",
|
sk->protinfo.af_wanpipe->lcn);
|
sk->protinfo.af_wanpipe->lcn);
|
|
|
err = 0;
|
err = 0;
|
|
|
}else{
|
}else{
|
DBG_PRINTK(KERN_INFO "\nwansock: Place call Failed\n");
|
DBG_PRINTK(KERN_INFO "\nwansock: Place call Failed\n");
|
err = -ECONNREFUSED;
|
err = -ECONNREFUSED;
|
}
|
}
|
|
|
break;
|
break;
|
|
|
default:
|
default:
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
return err;
|
return err;
|
}
|
}
|
|
|
static int check_driver_busy (struct sock *sk)
|
static int check_driver_busy (struct sock *sk)
|
{
|
{
|
netdevice_t *dev = dev_get_by_index(sk->bound_dev_if);
|
netdevice_t *dev = dev_get_by_index(sk->bound_dev_if);
|
wanpipe_common_t *chan;
|
wanpipe_common_t *chan;
|
|
|
if (!dev)
|
if (!dev)
|
return 0;
|
return 0;
|
|
|
dev_put(dev);
|
dev_put(dev);
|
|
|
if ((chan=dev->priv) == NULL)
|
if ((chan=dev->priv) == NULL)
|
return 0;
|
return 0;
|
|
|
return atomic_read(&chan->driver_busy);
|
return atomic_read(&chan->driver_busy);
|
}
|
}
|
|
|
|
|
/*======================================================================
|
/*======================================================================
|
* wanpipe_accept
|
* wanpipe_accept
|
*
|
*
|
* ACCEPT() System call. X25API Specific function.
|
* ACCEPT() System call. X25API Specific function.
|
* For each incoming call, create a new socket and
|
* For each incoming call, create a new socket and
|
* return it to the user.
|
* return it to the user.
|
*=====================================================================*/
|
*=====================================================================*/
|
|
|
static int wanpipe_accept(struct socket *sock, struct socket *newsock, int flags)
|
static int wanpipe_accept(struct socket *sock, struct socket *newsock, int flags)
|
{
|
{
|
struct sock *sk;
|
struct sock *sk;
|
struct sock *newsk;
|
struct sock *newsk;
|
struct sk_buff *skb;
|
struct sk_buff *skb;
|
DECLARE_WAITQUEUE(wait, current);
|
DECLARE_WAITQUEUE(wait, current);
|
int err=0;
|
int err=0;
|
|
|
if (newsock->sk != NULL){
|
if (newsock->sk != NULL){
|
wanpipe_kill_sock_accept(newsock->sk);
|
wanpipe_kill_sock_accept(newsock->sk);
|
newsock->sk=NULL;
|
newsock->sk=NULL;
|
}
|
}
|
|
|
if ((sk = sock->sk) == NULL)
|
if ((sk = sock->sk) == NULL)
|
return -EINVAL;
|
return -EINVAL;
|
|
|
if (sk->type != SOCK_RAW)
|
if (sk->type != SOCK_RAW)
|
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
|
|
if (sk->state != WANSOCK_LISTEN)
|
if (sk->state != WANSOCK_LISTEN)
|
return -EINVAL;
|
return -EINVAL;
|
|
|
if (sk->num != htons(X25_PROT))
|
if (sk->num != htons(X25_PROT))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
add_wait_queue(sk->sleep,&wait);
|
add_wait_queue(sk->sleep,&wait);
|
current->state = TASK_INTERRUPTIBLE;
|
current->state = TASK_INTERRUPTIBLE;
|
for (;;){
|
for (;;){
|
skb = skb_dequeue(&sk->receive_queue);
|
skb = skb_dequeue(&sk->receive_queue);
|
if (skb){
|
if (skb){
|
err=0;
|
err=0;
|
break;
|
break;
|
}
|
}
|
if (signal_pending(current)) {
|
if (signal_pending(current)) {
|
err = -ERESTARTSYS;
|
err = -ERESTARTSYS;
|
break;
|
break;
|
}
|
}
|
schedule();
|
schedule();
|
}
|
}
|
current->state = TASK_RUNNING;
|
current->state = TASK_RUNNING;
|
remove_wait_queue(sk->sleep,&wait);
|
remove_wait_queue(sk->sleep,&wait);
|
|
|
if (err != 0)
|
if (err != 0)
|
return err;
|
return err;
|
|
|
newsk = get_newsk_from_skb(skb);
|
newsk = get_newsk_from_skb(skb);
|
if (!newsk){
|
if (!newsk){
|
return -EINVAL;
|
return -EINVAL;
|
}
|
}
|
|
|
set_bit(1,&wanpipe_tx_critical);
|
set_bit(1,&wanpipe_tx_critical);
|
write_lock(&wanpipe_sklist_lock);
|
write_lock(&wanpipe_sklist_lock);
|
newsk->next = wanpipe_sklist;
|
newsk->next = wanpipe_sklist;
|
wanpipe_sklist = newsk;
|
wanpipe_sklist = newsk;
|
sock_hold(sk);
|
sock_hold(sk);
|
write_unlock(&wanpipe_sklist_lock);
|
write_unlock(&wanpipe_sklist_lock);
|
clear_bit(1,&wanpipe_tx_critical);
|
clear_bit(1,&wanpipe_tx_critical);
|
|
|
newsk->pair = NULL;
|
newsk->pair = NULL;
|
newsk->socket = newsock;
|
newsk->socket = newsock;
|
newsk->sleep = &newsock->wait;
|
newsk->sleep = &newsock->wait;
|
|
|
/* Now attach up the new socket */
|
/* Now attach up the new socket */
|
sk->ack_backlog--;
|
sk->ack_backlog--;
|
newsock->sk = newsk;
|
newsock->sk = newsk;
|
|
|
kfree_skb(skb);
|
kfree_skb(skb);
|
|
|
DBG_PRINTK(KERN_INFO "\nwansock: ACCEPT Got LCN %i\n",newsk->protinfo.af_wanpipe->lcn);
|
DBG_PRINTK(KERN_INFO "\nwansock: ACCEPT Got LCN %i\n",newsk->protinfo.af_wanpipe->lcn);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
/*======================================================================
|
/*======================================================================
|
* get_newsk_from_skb
|
* get_newsk_from_skb
|
*
|
*
|
* Accept() uses this function to get the address of the new
|
* Accept() uses this function to get the address of the new
|
* socket structure.
|
* socket structure.
|
*=====================================================================*/
|
*=====================================================================*/
|
|
|
struct sock * get_newsk_from_skb (struct sk_buff *skb)
|
struct sock * get_newsk_from_skb (struct sk_buff *skb)
|
{
|
{
|
netdevice_t *dev = skb->dev;
|
netdevice_t *dev = skb->dev;
|
wanpipe_common_t *chan;
|
wanpipe_common_t *chan;
|
|
|
if (!dev){
|
if (!dev){
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
if ((chan = dev->priv) == NULL){
|
if ((chan = dev->priv) == NULL){
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
if (!chan->sk){
|
if (!chan->sk){
|
return NULL;
|
return NULL;
|
}
|
}
|
return (struct sock *)chan->sk;
|
return (struct sock *)chan->sk;
|
}
|
}
|
|
|
/*======================================================================
|
/*======================================================================
|
* wanpipe_connect
|
* wanpipe_connect
|
*
|
*
|
* CONNECT() System Call. X25API specific function
|
* CONNECT() System Call. X25API specific function
|
* Check the state of the sock, and execute PLACE_CALL command.
|
* Check the state of the sock, and execute PLACE_CALL command.
|
* Connect can ether block or return without waiting for connection,
|
* Connect can ether block or return without waiting for connection,
|
* if specified by user.
|
* if specified by user.
|
*=====================================================================*/
|
*=====================================================================*/
|
|
|
static int wanpipe_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags)
|
static int wanpipe_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags)
|
{
|
{
|
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
struct wan_sockaddr_ll *addr = (struct wan_sockaddr_ll*)uaddr;
|
struct wan_sockaddr_ll *addr = (struct wan_sockaddr_ll*)uaddr;
|
netdevice_t *dev;
|
netdevice_t *dev;
|
int err;
|
int err;
|
|
|
if (sk->num != htons(X25_PROT))
|
if (sk->num != htons(X25_PROT))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
if (sk->state == WANSOCK_CONNECTED)
|
if (sk->state == WANSOCK_CONNECTED)
|
return -EISCONN; /* No reconnect on a seqpacket socket */
|
return -EISCONN; /* No reconnect on a seqpacket socket */
|
|
|
if (sk->state != WAN_DISCONNECTED){
|
if (sk->state != WAN_DISCONNECTED){
|
printk(KERN_INFO "wansock: Trying to connect on channel NON DISCONNECT\n");
|
printk(KERN_INFO "wansock: Trying to connect on channel NON DISCONNECT\n");
|
return -ECONNREFUSED;
|
return -ECONNREFUSED;
|
}
|
}
|
|
|
sk->state = WANSOCK_DISCONNECTED;
|
sk->state = WANSOCK_DISCONNECTED;
|
sock->state = SS_UNCONNECTED;
|
sock->state = SS_UNCONNECTED;
|
|
|
if (addr_len != sizeof(struct wan_sockaddr_ll))
|
if (addr_len != sizeof(struct wan_sockaddr_ll))
|
return -EINVAL;
|
return -EINVAL;
|
|
|
if (addr->sll_family != AF_WANPIPE)
|
if (addr->sll_family != AF_WANPIPE)
|
return -EINVAL;
|
return -EINVAL;
|
|
|
if ((dev = dev_get_by_index(sk->bound_dev_if)) == NULL)
|
if ((dev = dev_get_by_index(sk->bound_dev_if)) == NULL)
|
return -ENETUNREACH;
|
return -ENETUNREACH;
|
|
|
dev_put(dev);
|
dev_put(dev);
|
|
|
if (!sk->zapped) /* Must bind first - autobinding does not work */
|
if (!sk->zapped) /* Must bind first - autobinding does not work */
|
return -EINVAL;
|
return -EINVAL;
|
|
|
sock->state = SS_CONNECTING;
|
sock->state = SS_CONNECTING;
|
sk->state = WANSOCK_CONNECTING;
|
sk->state = WANSOCK_CONNECTING;
|
|
|
if (!sk->protinfo.af_wanpipe->mbox){
|
if (!sk->protinfo.af_wanpipe->mbox){
|
if (sk->protinfo.af_wanpipe->svc){
|
if (sk->protinfo.af_wanpipe->svc){
|
return -EINVAL;
|
return -EINVAL;
|
}else{
|
}else{
|
int err;
|
int err;
|
if ((err=set_ioctl_cmd(sk,NULL)) < 0)
|
if ((err=set_ioctl_cmd(sk,NULL)) < 0)
|
return err;
|
return err;
|
}
|
}
|
}
|
}
|
|
|
if ((err=wanpipe_exec_cmd(sk, X25_PLACE_CALL,flags)) != 0){
|
if ((err=wanpipe_exec_cmd(sk, X25_PLACE_CALL,flags)) != 0){
|
sock->state = SS_UNCONNECTED;
|
sock->state = SS_UNCONNECTED;
|
sk->state = WANSOCK_CONNECTED;
|
sk->state = WANSOCK_CONNECTED;
|
return err;
|
return err;
|
}
|
}
|
|
|
if (sk->state != WANSOCK_CONNECTED && (flags & O_NONBLOCK)){
|
if (sk->state != WANSOCK_CONNECTED && (flags & O_NONBLOCK)){
|
return 0;
|
return 0;
|
}
|
}
|
|
|
if (sk->state != WANSOCK_CONNECTED) {
|
if (sk->state != WANSOCK_CONNECTED) {
|
sock->state = SS_UNCONNECTED;
|
sock->state = SS_UNCONNECTED;
|
return -ECONNREFUSED;
|
return -ECONNREFUSED;
|
}
|
}
|
|
|
sock->state = SS_CONNECTED;
|
sock->state = SS_CONNECTED;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
#ifdef LINUX_2_4
|
#ifdef LINUX_2_4
|
struct proto_ops wanpipe_ops = {
|
struct proto_ops wanpipe_ops = {
|
family: PF_WANPIPE,
|
family: PF_WANPIPE,
|
|
|
release: wanpipe_release,
|
release: wanpipe_release,
|
bind: wanpipe_bind,
|
bind: wanpipe_bind,
|
connect: wanpipe_connect,
|
connect: wanpipe_connect,
|
socketpair: sock_no_socketpair,
|
socketpair: sock_no_socketpair,
|
accept: wanpipe_accept,
|
accept: wanpipe_accept,
|
getname: wanpipe_getname,
|
getname: wanpipe_getname,
|
poll: wanpipe_poll,
|
poll: wanpipe_poll,
|
ioctl: wanpipe_ioctl,
|
ioctl: wanpipe_ioctl,
|
listen: wanpipe_listen,
|
listen: wanpipe_listen,
|
shutdown: sock_no_shutdown,
|
shutdown: sock_no_shutdown,
|
setsockopt: sock_no_setsockopt,
|
setsockopt: sock_no_setsockopt,
|
getsockopt: sock_no_getsockopt,
|
getsockopt: sock_no_getsockopt,
|
sendmsg: wanpipe_sendmsg,
|
sendmsg: wanpipe_sendmsg,
|
recvmsg: wanpipe_recvmsg
|
recvmsg: wanpipe_recvmsg
|
};
|
};
|
#else
|
#else
|
struct proto_ops wanpipe_ops = {
|
struct proto_ops wanpipe_ops = {
|
PF_WANPIPE,
|
PF_WANPIPE,
|
|
|
sock_no_dup,
|
sock_no_dup,
|
wanpipe_release,
|
wanpipe_release,
|
wanpipe_bind,
|
wanpipe_bind,
|
wanpipe_connect,
|
wanpipe_connect,
|
sock_no_socketpair,
|
sock_no_socketpair,
|
wanpipe_accept,
|
wanpipe_accept,
|
wanpipe_getname,
|
wanpipe_getname,
|
wanpipe_poll,
|
wanpipe_poll,
|
wanpipe_ioctl,
|
wanpipe_ioctl,
|
wanpipe_listen,
|
wanpipe_listen,
|
sock_no_shutdown,
|
sock_no_shutdown,
|
sock_no_setsockopt,
|
sock_no_setsockopt,
|
sock_no_getsockopt,
|
sock_no_getsockopt,
|
sock_no_fcntl,
|
sock_no_fcntl,
|
wanpipe_sendmsg,
|
wanpipe_sendmsg,
|
wanpipe_recvmsg
|
wanpipe_recvmsg
|
};
|
};
|
#endif
|
#endif
|
|
|
|
|
static struct net_proto_family wanpipe_family_ops = {
|
static struct net_proto_family wanpipe_family_ops = {
|
PF_WANPIPE,
|
PF_WANPIPE,
|
wanpipe_create
|
wanpipe_create
|
};
|
};
|
|
|
struct notifier_block wanpipe_netdev_notifier={
|
struct notifier_block wanpipe_netdev_notifier={
|
wanpipe_notifier,
|
wanpipe_notifier,
|
NULL,
|
NULL,
|
0
|
0
|
};
|
};
|
|
|
|
|
#ifdef MODULE
|
#ifdef MODULE
|
void cleanup_module(void)
|
void cleanup_module(void)
|
{
|
{
|
printk(KERN_INFO "wansock: Cleaning up \n");
|
printk(KERN_INFO "wansock: Cleaning up \n");
|
unregister_netdevice_notifier(&wanpipe_netdev_notifier);
|
unregister_netdevice_notifier(&wanpipe_netdev_notifier);
|
sock_unregister(PF_WANPIPE);
|
sock_unregister(PF_WANPIPE);
|
return;
|
return;
|
}
|
}
|
|
|
|
|
int init_module(void)
|
int init_module(void)
|
{
|
{
|
|
|
printk(KERN_INFO "wansock: Registering Socket \n");
|
printk(KERN_INFO "wansock: Registering Socket \n");
|
sock_register(&wanpipe_family_ops);
|
sock_register(&wanpipe_family_ops);
|
register_netdevice_notifier(&wanpipe_netdev_notifier);
|
register_netdevice_notifier(&wanpipe_netdev_notifier);
|
return 0;
|
return 0;
|
}
|
}
|
#endif
|
#endif
|
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
|
|