Re: MC 7304 ipv4v6



Bjørn Mork <bjorn mork no> writes:
Dan Williams <dcbw redhat com> writes:
On Tue, 2015-11-24 at 22:51 +0100, Bjørn Mork wrote:

My vote would be sysfs, with values "raw-ip" or "802.3" that you can
read and write to the file.  At least then they are human-readable. 
 It's also easier to use from scripts than parsing ethtool output.

Maybe even easier with a boolean qmi/raw_ip file, since we are only going
to offer two alternatives anyway?  Then you don't have to figure out
what strings are accepted, and we won't end up having to parse
'raw-ip/rawip/raw_ip/rwa-ip/rawIP/etc'.

Including a demo patch (not tested...) to illustrate what I mean:

 $ cat /sys/class/net/wwan1/qmi/raw_ip 
 N
 # echo Y >/sys/class/net/wwan1/qmi/raw_ip

etc

From 97df402dab83feb14a7cb61fb7fa950e0bcf8c1d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B8rn=20Mork?= <bjorn mork no>
Date: Mon, 15 Apr 2013 21:55:34 +0200
Subject: [PATCH] net: qmi_wwan: add raw IP support with fake ethernet headers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Bjørn Mork <bjorn mork no>
---
 drivers/net/usb/qmi_wwan.c | 66 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 65 insertions(+), 1 deletion(-)

diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index af1267fb1139..428b46453efc 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -48,11 +48,55 @@
 struct qmi_wwan_state {
        struct usb_driver *subdriver;
        atomic_t pmcount;
-       unsigned long unused;
+       unsigned long flags;
        struct usb_interface *control;
        struct usb_interface *data;
 };
 
+enum qmi_wwan_flags {
+       QMI_WWAN_FLAG_RAWIP = 1 << 0,
+};
+
+static ssize_t raw_ip_show(struct device *d, struct device_attribute *attr, char *buf)
+{
+       struct usbnet *dev = netdev_priv(to_net_dev(d));
+       struct qmi_wwan_state *info = (void *)&dev->data;
+
+       return sprintf(buf, "%c\n", info->flags & QMI_WWAN_FLAG_RAWIP ? 'Y' : 'N');
+}
+
+static ssize_t raw_ip_store(struct device *d,  struct device_attribute *attr, const char *buf, size_t len)
+{
+       struct usbnet *dev = netdev_priv(to_net_dev(d));
+       struct qmi_wwan_state *info = (void *)&dev->data;
+       bool enable;
+
+       if (strtobool(buf, &enable))
+               return -EINVAL;
+
+       if (enable) {
+               info->flags |= QMI_WWAN_FLAG_RAWIP;
+               /* cannot do arp in raw IP mode, but must do in 802.3 mode */
+               dev->net->flags |= IFF_NOARP;
+       } else {
+               info->flags &= ~QMI_WWAN_FLAG_RAWIP;
+               dev->net->flags &= ~IFF_NOARP;
+       }
+       return len;
+}
+
+static DEVICE_ATTR_RW(raw_ip);
+
+static struct attribute *qmi_wwan_sysfs_attrs[] = {
+       &dev_attr_raw_ip.attr,
+       NULL,
+};
+
+static struct attribute_group qmi_wwan_sysfs_attr_group = {
+       .name = "qmi",
+       .attrs = qmi_wwan_sysfs_attrs,
+};
+
 /* default ethernet address used by the modem */
 static const u8 default_modem_addr[ETH_ALEN] = {0x02, 0x50, 0xf3};
 
@@ -114,6 +158,24 @@ fix_dest:
        return 1;
 }
 
+static struct sk_buff *qmi_wwan_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
+{
+       struct qmi_wwan_state *info = (void *)&dev->data;
+
+       if ((skb->len <= ETH_HLEN) || !(info->flags & QMI_WWAN_FLAG_RAWIP))
+               goto out;
+
+       /* only pull header if datagram is IPv4 or IPv6 */
+       skb_reset_mac_header(skb);
+       switch (eth_hdr(skb)->h_proto) {
+       case htons(ETH_P_IP):
+       case htons(ETH_P_IPV6):
+               skb_pull(skb, ETH_HLEN);
+       }
+out:
+       return skb;
+}
+
 /* very simplistic detection of IPv4 or IPv6 headers */
 static bool possibly_iphdr(const char *data)
 {
@@ -312,6 +374,7 @@ static int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf)
                dev->net->dev_addr[0] &= 0xbf;  /* clear "IP" bit */
        }
        dev->net->netdev_ops = &qmi_wwan_netdev_ops;
+       dev->net->sysfs_groups[0] = &qmi_wwan_sysfs_attr_group;
 err:
        return status;
 }
@@ -397,6 +460,7 @@ static const struct driver_info     qmi_wwan_info = {
        .unbind         = qmi_wwan_unbind,
        .manage_power   = qmi_wwan_manage_power,
        .rx_fixup       = qmi_wwan_rx_fixup,
+       .tx_fixup       = qmi_wwan_tx_fixup,
 };
 
 #define HUAWEI_VENDOR_ID       0x12D1
-- 
2.1.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]