Commit fd0812f6 authored by François Romieu's avatar François Romieu Committed by Jeff Garzik

WAN drivers update 3/5:

Clean up WAN driver ioctl handling to be more independent
of line settings structure changes.
parent 10e9aaa7
......@@ -179,9 +179,10 @@ static int c101_close(struct net_device *dev)
static int c101_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
union line_settings *line = &ifr->ifr_settings->ifs_line;
const size_t size = sizeof(sync_serial_settings);
hdlc_device *hdlc = dev_to_hdlc(dev);
port_t *port = hdlc_to_port(hdlc);
const size_t size = sizeof(sync_serial_settings);
#ifdef CONFIG_HDLC_DEBUG_RINGS
if (cmd == SIOCDEVPRIVATE) {
......@@ -192,28 +193,18 @@ static int c101_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
if (cmd != SIOCWANDEV)
return hdlc_ioctl(dev, ifr, cmd);
switch(ifr->ifr_settings.type) {
switch(ifr->ifr_settings->type) {
case IF_GET_IFACE:
ifr->ifr_settings.type = IF_IFACE_SYNC_SERIAL;
if (ifr->ifr_settings.data_length == 0)
return 0; /* return interface type only */
if (ifr->ifr_settings.data_length < size)
return -ENOMEM; /* buffer too small */
if (copy_to_user(ifr->ifr_settings.data,
&port->settings, size))
ifr->ifr_settings->type = IF_IFACE_SYNC_SERIAL;
if (copy_to_user(&line->sync, &port->settings, size))
return -EFAULT;
ifr->ifr_settings.data_length = size;
return 0;
case IF_IFACE_SYNC_SERIAL:
if(!capable(CAP_NET_ADMIN))
return -EPERM;
if (ifr->ifr_settings.data_length != size)
return -ENOMEM; /* incorrect data length */
if (copy_from_user(&port->settings,
ifr->ifr_settings.data, size))
if (copy_from_user(&port->settings, &line->sync, size))
return -EFAULT;
/* FIXME - put sanity checks here */
return c101_set_iface(port);
......
......@@ -1065,8 +1065,8 @@ static int dscc4_set_clock(struct net_device *dev, u32 *bps, u32 *state)
static int dscc4_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
union line_settings *line = &ifr->ifr_settings->ifs_line;
struct dscc4_dev_priv *dpriv = dscc4_priv(dev);
struct if_settings *if_s = &ifr->ifr_settings;
const size_t size = sizeof(dpriv->settings);
int ret = 0;
......@@ -1076,26 +1076,18 @@ static int dscc4_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
if (cmd != SIOCWANDEV)
return -EOPNOTSUPP;
switch(ifr->ifr_settings.type) {
switch(ifr->ifr_settings->type) {
case IF_GET_IFACE:
if_s->type = IF_IFACE_SYNC_SERIAL;
if (if_s->data_length == 0)
return 0;
if (if_s->data_length < size)
return -ENOMEM;
if (copy_to_user(if_s->data, &dpriv->settings, size))
ifr->ifr_settings->type = IF_IFACE_SYNC_SERIAL;
if (copy_to_user(&line->sync, &dpriv->settings, size))
return -EFAULT;
if_s->data_length = size;
break;
case IF_IFACE_SYNC_SERIAL:
if(!capable(CAP_NET_ADMIN))
return -EPERM;
if (if_s->data_length != size)
return -ENOMEM;
if (copy_from_user(&dpriv->settings, if_s->data, size))
if (copy_from_user(&dpriv->settings, &line->sync, size))
return -EFAULT;
ret = dscc4_set_iface(dev);
break;
......
......@@ -1013,25 +1013,19 @@ static int
fst_set_iface ( struct fst_card_info *card, struct fst_port_info *port,
struct ifreq *ifr )
{
union line_settings *line = &ifr->ifr_settings->ifs_line;
sync_serial_settings sync;
int i;
if ( ifr->ifr_settings.data_length != sizeof ( sync ))
{
return -ENOMEM;
}
if ( copy_from_user ( &sync, ifr->ifr_settings.data, sizeof ( sync )))
{
if ( copy_from_user ( &sync, &line->sync, sizeof ( sync )))
return -EFAULT;
}
if ( sync.loopback )
return -EINVAL;
i = port->index;
switch ( ifr->ifr_settings.type )
switch ( ifr->ifr_settings->type )
{
case IF_IFACE_V35:
FST_WRW ( card, portConfig[i].lineInterface, V35 );
......@@ -1076,6 +1070,7 @@ static int
fst_get_iface ( struct fst_card_info *card, struct fst_port_info *port,
struct ifreq *ifr )
{
union line_settings *line = &ifr->ifr_settings->ifs_line;
sync_serial_settings sync;
int i;
......@@ -1086,25 +1081,16 @@ fst_get_iface ( struct fst_card_info *card, struct fst_port_info *port,
switch ( port->hwif )
{
case V35:
ifr->ifr_settings.type = IF_IFACE_V35;
ifr->ifr_settings->type = IF_IFACE_V35;
break;
case V24:
ifr->ifr_settings.type = IF_IFACE_V24;
ifr->ifr_settings->type = IF_IFACE_V24;
break;
case X21:
default:
ifr->ifr_settings.type = IF_IFACE_X21;
ifr->ifr_settings->type = IF_IFACE_X21;
break;
}
if ( ifr->ifr_settings.data_length == 0 )
{
return 0; /* only type requested */
}
if ( ifr->ifr_settings.data_length < sizeof ( sync ))
{
return -ENOMEM;
}
i = port->index;
sync.clock_rate = FST_RDL ( card, portConfig[i].lineSpeed );
......@@ -1112,12 +1098,9 @@ fst_get_iface ( struct fst_card_info *card, struct fst_port_info *port,
sync.clock_type = FST_RDB ( card, portConfig[i].internalClock );
sync.loopback = 0;
if ( copy_to_user ( ifr->ifr_settings.data, &sync, sizeof ( sync )))
{
if ( copy_to_user (&line->sync, &sync, sizeof ( sync )))
return -EFAULT;
}
ifr->ifr_settings.data_length = sizeof ( sync );
return 0;
}
......@@ -1241,7 +1224,7 @@ fst_ioctl ( struct net_device *dev, struct ifreq *ifr, int cmd )
return set_conf_from_info ( card, port, &info );
case SIOCWANDEV:
switch ( ifr->ifr_settings.type )
switch ( ifr->ifr_settings->type )
{
case IF_GET_IFACE:
return fst_get_iface ( card, port, ifr );
......
......@@ -250,9 +250,10 @@ static int n2_close(struct net_device *dev)
static int n2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
{
union line_settings *line = &ifr->ifr_settings->ifs_line;
const size_t size = sizeof(sync_serial_settings);
hdlc_device *hdlc = dev_to_hdlc(dev);
port_t *port = hdlc_to_port(hdlc);
const size_t size = sizeof(sync_serial_settings);
#ifdef CONFIG_HDLC_DEBUG_RINGS
if (cmd == SIOCDEVPRIVATE) {
......@@ -263,28 +264,18 @@ static int n2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
if (cmd != SIOCWANDEV)
return hdlc_ioctl(dev, ifr, cmd);
switch(ifr->ifr_settings.type) {
switch(ifr->ifr_settings->type) {
case IF_GET_IFACE:
ifr->ifr_settings.type = IF_IFACE_SYNC_SERIAL;
if (ifr->ifr_settings.data_length == 0)
return 0; /* return interface type only */
if (ifr->ifr_settings.data_length < size)
return -ENOMEM; /* buffer too small */
if (copy_to_user(ifr->ifr_settings.data,
&port->settings, size))
ifr->ifr_settings->type = IF_IFACE_SYNC_SERIAL;
if (copy_to_user(&line->sync, &port->settings, size))
return -EFAULT;
ifr->ifr_settings.data_length = size;
return 0;
case IF_IFACE_SYNC_SERIAL:
if(!capable(CAP_NET_ADMIN))
return -EPERM;
if (ifr->ifr_settings.data_length != size)
return -ENOMEM; /* incorrect data length */
if (copy_from_user(&port->settings,
ifr->ifr_settings.data, size))
if (copy_from_user(&port->settings, &line->sync, size))
return -EFAULT;
/* FIXME - put sanity checks here */
return n2_set_iface(port);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment