netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Bjørn Mork" <bjorn@mork.no>
To: netdev@vger.kernel.org
Cc: linux-usb@vger.kernel.org, "Oliver Neukum" <oliver@neukum.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Alexey Orishko" <alexey.orishko@gmail.com>,
	"Greg Suarez" <gpsuarez2512@gmail.com>,
	"Fangxiaozhi (Franko)" <fangxiaozhi@huawei.com>,
	"Dan Williams" <dcbw@redhat.com>,
	"Aleksander Morgado" <aleksander@lanedo.com>,
	"Bjørn Mork" <bjorn@mork.no>
Subject: [PATCH net-next 14/14] net: cdc_mbim: Device Service Stream support
Date: Thu, 18 Oct 2012 22:41:07 +0200	[thread overview]
Message-ID: <1350592867-25651-15-git-send-email-bjorn@mork.no> (raw)
In-Reply-To: <1350592867-25651-1-git-send-email-bjorn@mork.no>

MBIM devices can support up to 256 generic streams called
Device Service Streams (DSS). The MBIM spec says

   The format of the Device Service Stream payload depends
   on the device service (as identified by the corresponding
   UUID) that is used when opening the data stream.

Example use cases are serial AT command interfaces and NMEA
data streams. We cannot make any assumptions about these
device services.

Adding support for Device Service Stream by extending
the MBIM session to VLAN mapping scheme, allocating
VLAN IDs 256 to 511 for DSS, using the DSS SessionID
as the lower 8bit of the VLAN ID.

Using a netdev for DSS keeps the device framing intact and
allows userspace to do whatever it want with the streams.
For example, exporting an AT command interface using DSS
session #0 to a PTY for use with a terminal application like
minicom:

  vconfig add wwan0 256
  ip link set dev wwan0 up
  ip link set dev wwan0.256 up
  socat INTERFACE:wwan0.256,type=2 PTY:,echo=0,link=/tmp/modem

Device configuration must be done using MBIM control commands
over the /dev/cdc-wdmx device. The userspace management
application should coordinate host VLAN configuration and the
device MBIM configuration using the device capabilities to
find out if it needs to set up PTY mappings etc.

Signed-off-by: Bjørn Mork <bjorn@mork.no>
---
 drivers/net/usb/cdc_mbim.c |   58 ++++++++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 23 deletions(-)

diff --git a/drivers/net/usb/cdc_mbim.c b/drivers/net/usb/cdc_mbim.c
index 45f5f50..42f51c7 100644
--- a/drivers/net/usb/cdc_mbim.c
+++ b/drivers/net/usb/cdc_mbim.c
@@ -149,12 +149,27 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb
 		/* mapping VLANs to MBIM sessions:
 		 *   no tag     => IPS session <0>
 		 *   1 - 255    => IPS session <vlanid>
-		 *   256 - 4095 => unsupported, drop
+		 *   256 - 511  => DSS session <vlanid - 256>
+		 *   512 - 4095 => unsupported, drop
 		 */
 		vlan_get_tag(skb, &tci);
 
 		switch (tci & 0x0f00) {
 		case 0x0000: /* VLAN ID 0 - 255 */
+			/* verify that 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):
+				break;
+			default:
+				goto error;
+			}
+			c = (u8 *)&sign;
+			c[3] = tci;
+			break;
+		case 0x0100: /* VLAN ID 256 - 511 */
+			sign = cpu_to_le32(USB_CDC_MBIM_NDP16_DSS_SIGN);
 			c = (u8 *)&sign;
 			c[3] = tci;
 			break;
@@ -163,16 +178,7 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb
 				  "unsupported tci=0x%04x\n", tci);
 			goto error;
 		}
-
-		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);
-			break;
-		default:
-			goto error;
-		}
+		skb_pull(skb, ETH_HLEN);
 	}
 
 	spin_lock_bh(&ctx->mtx);
@@ -189,21 +195,23 @@ error:
 
 static struct sk_buff *cdc_mbim_process_dgram(struct usbnet *dev, u8 *buf, size_t len, u16 tci)
 {
-	__be16 proto;
+	__be16 proto = htons(ETH_P_802_3);
 	struct sk_buff *skb = NULL;
 
-	if (len < sizeof(struct iphdr))
-		goto err;
+	if (tci < 256) { /* IPS session? */
+		if (len < sizeof(struct iphdr))
+			goto err;
 
-	switch (*buf & 0xf0) {
-	case 0x40:
-		proto = htons(ETH_P_IP);
-		break;
-	case 0x60:
-		proto = htons(ETH_P_IPV6);
-		break;
-	default:
-		goto err;
+		switch (*buf & 0xf0) {
+		case 0x40:
+			proto = htons(ETH_P_IP);
+			break;
+		case 0x60:
+			proto = htons(ETH_P_IPV6);
+			break;
+		default:
+			goto err;
+		}
 	}
 
 	skb = netdev_alloc_skb_ip_align(dev->net,  len + ETH_HLEN);
@@ -259,6 +267,10 @@ next_ndp:
 		c = (u8 *)&ndp16->dwSignature;
 		tci = c[3];
 		break;
+	case cpu_to_le32(USB_CDC_MBIM_NDP16_DSS_SIGN):
+		c = (u8 *)&ndp16->dwSignature;
+		tci = c[3] + 256;
+		break;
 	default:
 		netif_dbg(dev, rx_err, dev->net,
 			  "unsupported NDP signature <0x%08x>\n",
-- 
1.7.10.4

  parent reply	other threads:[~2012-10-18 21:22 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-18 20:40 [PATCH net-next 00/14] Adding a USB CDC MBIM driver Bjørn Mork
2012-10-18 20:40 ` [PATCH net-next 01/14] net: usbnet: make sure the queue lenght is at least 1 Bjørn Mork
2012-10-18 20:40 ` [PATCH net-next 02/14] net: cdc_ncm: use device rx_max value if update failed Bjørn Mork
     [not found]   ` <1350592867-25651-3-git-send-email-bjorn-yOkvZcmFvRU@public.gmane.org>
2012-10-18 21:45     ` Oliver Neukum
2012-10-18 22:09       ` Bjørn Mork
2012-10-18 23:30         ` Alexey Orishko
2012-10-19  6:41           ` Bjørn Mork
2012-10-19  9:30             ` Bjørn Mork
     [not found]               ` <871uguvmfy.fsf-lbf33ChDnrE/G1V5fR+Y7Q@public.gmane.org>
2012-10-19 10:01                 ` Alexey Orishko
     [not found]                   ` <CAL_Kpj3QX_bpLh5yX5VXKaqq+TSO9+aVxt+1TrU9e1BamKdFkA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19 10:30                     ` Bjørn Mork
     [not found]                       ` <87vce6u52w.fsf-lbf33ChDnrE/G1V5fR+Y7Q@public.gmane.org>
2012-10-19 11:36                         ` [RFC] net: cdc_ncm: workaround NTB input size firmware bug Bjørn Mork
2012-10-19 12:18                     ` [PATCH net-next 02/14] net: cdc_ncm: use device rx_max value if update failed Bjørn Mork
     [not found]                       ` <878vb2u03g.fsf-lbf33ChDnrE/G1V5fR+Y7Q@public.gmane.org>
2012-10-19 13:53                         ` Alexey Orishko
     [not found]                           ` <CAL_Kpj3tT6qfcD-Tpeqgof-k-PX-EPv_cMFo_NeEdLHfyN8Qfw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-19 14:09                             ` Bjørn Mork
2012-10-18 20:40 ` [PATCH net-next 04/14] net: cdc_ncm: adding MBIM support to ncm_setup Bjørn Mork
2012-10-18 20:40 ` [PATCH net-next 06/14] net: cdc_ncm: process chained NDPs Bjørn Mork
2012-10-18 20:41 ` [PATCH net-next 08/14] net: cdc_ncm: refactoring for tx multiplexing Bjørn Mork
2012-10-18 20:41 ` [PATCH net-next 11/14] net: cdc_mbim: build the MBIM driver Bjørn Mork
2012-10-18 20:41 ` [PATCH net-next 12/14] net: cdc_ncm: do not bind to NCM compatible MBIM devices Bjørn Mork
2012-10-18 20:41 ` Bjørn Mork [this message]
     [not found] ` <1350592867-25651-1-git-send-email-bjorn-yOkvZcmFvRU@public.gmane.org>
2012-10-18 20:40   ` [PATCH net-next 03/14] USB: cdc: add MBIM constants and structures Bjørn Mork
     [not found]     ` <1350592867-25651-4-git-send-email-bjorn-yOkvZcmFvRU@public.gmane.org>
2012-10-18 21:14       ` Greg Kroah-Hartman
2012-10-18 20:40   ` [PATCH net-next 05/14] net: cdc_ncm: refactor bind preparing for MBIM support Bjørn Mork
2012-10-18 20:41   ` [PATCH net-next 07/14] net: cdc_ncm: splitting rx_fixup for code reuse Bjørn Mork
2012-10-18 20:41   ` [PATCH net-next 09/14] net: cdc_ncm: export shared symbols and definitions Bjørn Mork
2012-10-18 20:41   ` [PATCH net-next 10/14] net: cdc_mbim: adding MBIM driver Bjørn Mork
2012-10-18 20:41   ` [PATCH net-next 13/14] net: cdc_ncm: map MBIM IPS SessionID to VLAN ID Bjørn Mork
2012-10-18 21:04   ` [PATCH net-next 00/14] Adding a USB CDC MBIM driver David Miller
2012-10-18 21:08     ` Bjørn Mork
2012-10-18 21:16 ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350592867-25651-15-git-send-email-bjorn@mork.no \
    --to=bjorn@mork.no \
    --cc=aleksander@lanedo.com \
    --cc=alexey.orishko@gmail.com \
    --cc=dcbw@redhat.com \
    --cc=fangxiaozhi@huawei.com \
    --cc=gpsuarez2512@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oliver@neukum.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).