From: Ken Mills <[email protected]>

Subject: [PATCH] n_gsm: Network interface name is hard coded.

The application should be able to set the network format string. Also that
string is not currently being passed down to alloc_netdev() properly.

Added a field to the gsm_netconfig structure so the network interface name 
format
string can be passed down upon network enable. If the string is null, then the
default string is "gsm%d and will be passed to alloc_netdev(). The resulting 
network
name is passed back to the application.

Signed-off-by: Ken Mills <[email protected]>
---
 drivers/tty/n_gsm.c    |   20 +++++++++++++-------
 include/linux/gsmmux.h |    1 +
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 0f159f9..18596ca 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -58,11 +58,11 @@
 #include <linux/serial.h>
 #include <linux/kfifo.h>
 #include <linux/skbuff.h>
-#include <linux/gsmmux.h>
 #include <net/arp.h>
 #include <linux/ip.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
+#include <linux/gsmmux.h>
 
 static int debug;
 module_param(debug, int, 0600);
@@ -2610,9 +2610,8 @@ static void gsm_destroy_network(struct gsm_dlci *dlci)
 
 static int gsm_create_network(struct gsm_dlci *dlci, struct gsm_netconfig *nc)
 {
-       char netname[6];
+       char *netname;
        int retval = 0;
-       int channel = dlci->addr;
        struct net_device *net;
        struct gsm_mux_net *mux_net;
 
@@ -2630,8 +2629,10 @@ static int gsm_create_network(struct gsm_dlci *dlci, 
struct gsm_netconfig *nc)
                return -EPROTONOSUPPORT;
 
        pr_debug("create network interface");
-       netname[5] = 0;
-       snprintf(netname, 6, "gsm%02d", channel);
+
+       netname = "gsm%d";
+       if (nc->if_name[0] != '\0')
+               netname = nc->if_name;
        net = alloc_netdev(sizeof(struct gsm_mux_net),
                        netname,
                        gsm_mux_net_init);
@@ -2655,6 +2656,7 @@ static int gsm_create_network(struct gsm_dlci *dlci, 
struct gsm_netconfig *nc)
                pr_err("network register fail %d\n", retval);
                goto error_ret;
        }
+       strncpy(nc->if_name, net->name, IFNAMSIZ); /* return net name */
        return net->ifindex;    /* return network index */
 
 error_ret:
@@ -2864,14 +2866,18 @@ static int gsmtty_ioctl(struct tty_struct *tty, struct 
file *filp,
 {
        struct gsm_dlci *dlci = tty->driver_data;
        struct gsm_netconfig nc;
-
+       int index;
 
        switch (cmd) {
        case GSMIOC_ENABLE_NET:
                if (copy_from_user(&nc, (void __user *)arg, sizeof(nc)))
                        return -EFAULT;
+               nc.if_name[IFNAMSIZ-1] = '\0';
                /* return net interface index or error code */
-               return  gsm_create_network(dlci, &nc);
+               index = gsm_create_network(dlci, &nc);
+               if (copy_to_user((void __user *)arg, &nc, sizeof(nc)))
+                       return -EFAULT;
+               return index;
        case GSMIOC_DISABLE_NET:
                if (!capable(CAP_NET_ADMIN))
                        return -EPERM;
diff --git a/include/linux/gsmmux.h b/include/linux/gsmmux.h
index c26e993..775430b 100644
--- a/include/linux/gsmmux.h
+++ b/include/linux/gsmmux.h
@@ -26,6 +26,7 @@ struct gsm_netconfig
        unsigned int adaption;  /* Adaption to use in network mode */
        unsigned short protocol;/* Protocol to use - only ETH_P_IP supported */
        unsigned short unused2;
+       char if_name[IFNAMSIZ]; /* interface name format string */
        __u8 unused[28];        /* For future use */
 };
 
-- 
1.7.0.4
_______________________________________________
MeeGo-kernel mailing list
[email protected]
http://lists.meego.com/listinfo/meego-kernel

Reply via email to