summaryrefslogtreecommitdiffstats
path: root/net/irda/wrapper.c
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>1999-06-13 16:29:25 +0000
committerRalf Baechle <ralf@linux-mips.org>1999-06-13 16:29:25 +0000
commitdb7d4daea91e105e3859cf461d7e53b9b77454b2 (patch)
tree9bb65b95440af09e8aca63abe56970dd3360cc57 /net/irda/wrapper.c
parent9c1c01ead627bdda9211c9abd5b758d6c687d8ac (diff)
Merge with Linux 2.2.8.
Diffstat (limited to 'net/irda/wrapper.c')
-rw-r--r--net/irda/wrapper.c197
1 files changed, 103 insertions, 94 deletions
diff --git a/net/irda/wrapper.c b/net/irda/wrapper.c
index fdebb5788..c4822e2c6 100644
--- a/net/irda/wrapper.c
+++ b/net/irda/wrapper.c
@@ -1,12 +1,12 @@
/*********************************************************************
*
* Filename: wrapper.c
- * Version:
- * Description: IrDA Wrapper layer
+ * Version: 1.1
+ * Description: SIR wrapper layer
* Status: Experimental.
* Author: Dag Brattli <dagb@cs.uit.no>
* Created at: Mon Aug 4 20:40:53 1997
- * Modified at: Sat Jan 16 22:05:45 1999
+ * Modified at: Wed Apr 21 12:45:55 1999
* Modified by: Dag Brattli <dagb@cs.uit.no>
*
* Copyright (c) 1998 Dag Brattli <dagb@cs.uit.no>,
@@ -34,9 +34,7 @@
#include <net/irda/irlap_frame.h>
#include <net/irda/irda_device.h>
-#define MIN_LENGTH 14
-
-__inline__ static int stuff_byte( __u8 byte, __u8 *buf);
+inline static int stuff_byte(__u8 byte, __u8 *buf);
/*
* Function async_wrap (skb, *tx_buff)
@@ -44,28 +42,25 @@ __inline__ static int stuff_byte( __u8 byte, __u8 *buf);
* Makes a new buffer with wrapping and stuffing, should check that
* we don't get tx buffer overflow.
*/
-int async_wrap_skb( struct sk_buff *skb, __u8 *tx_buff, int buffsize)
+int async_wrap_skb(struct sk_buff *skb, __u8 *tx_buff, int buffsize)
{
- __u8 byte;
- int i, n;
+ int i;
+ int n;
int xbofs;
union {
__u16 value;
__u8 bytes[2];
} fcs;
-
- DEBUG( 6, __FUNCTION__ "()\n");
- ASSERT( skb != NULL, return 0;);
+ ASSERT(skb != NULL, return 0;);
/* Initialize variables */
fcs.value = INIT_FCS;
n = 0;
- if ( skb->len > 2048) {
- DEBUG( 0,"async_xmit: Warning size=%d of sk_buff to big!\n",
- (int) skb->len);
-
+ if (skb->len > 2048) {
+ DEBUG(0, __FUNCTION__ "Warning size=%d of sk_buff to big!\n",
+ (int) skb->len);
return 0;
}
@@ -73,43 +68,55 @@ int async_wrap_skb( struct sk_buff *skb, __u8 *tx_buff, int buffsize)
* Send XBOF's for required min. turn time and for the negotiated
* additional XBOFS
*/
- xbofs = ((struct irlap_skb_cb *)(skb->cb))->xbofs;
- for ( i=0; i<xbofs; i++) {
- tx_buff[n++] = XBOF;
- }
+ if (((struct irlap_skb_cb *)(skb->cb))->magic != LAP_MAGIC) {
+ DEBUG(1, __FUNCTION__ "(), wrong magic in skb!\n");
+ xbofs = 10;
+ } else
+ xbofs = ((struct irlap_skb_cb *)(skb->cb))->xbofs;
+#if 0
+ for (i=0; i<xbofs; i++)
+ tx_buff[n++] = XBOF;
+#else
+ memset(tx_buff+n, XBOF, xbofs);
+ n += xbofs;
+#endif
/* Start of packet character BOF */
tx_buff[n++] = BOF;
/* Insert frame and calc CRC */
- for( i=0; i < skb->len; i++) {
- byte = skb->data[i];
-
+ for (i=0; i < skb->len; i++) {
/*
* Check for the possibility of tx buffer overflow. We use
* bufsize-5 since the maximum number of bytes that can be
* transmitted after this point is 5.
*/
- if ( n > buffsize-5) {
- printk( KERN_WARNING
- "IrDA Wrapper: TX-buffer overflow!\n");
- return n;
- }
- n+=stuff_byte( byte, tx_buff+n);
- fcs.value = IR_FCS( fcs.value, byte);
+ ASSERT(n < (buffsize-5), return n;);
+
+ n += stuff_byte(skb->data[i], tx_buff+n);
+ fcs.value = IR_FCS(fcs.value, skb->data[i]);
}
/* Insert CRC in little endian format (LSB first) */
fcs.value = ~fcs.value;
#ifdef __LITTLE_ENDIAN
- n += stuff_byte( fcs.bytes[0], tx_buff+n);
- n += stuff_byte( fcs.bytes[1], tx_buff+n);
+ n += stuff_byte(fcs.bytes[0], tx_buff+n);
+ n += stuff_byte(fcs.bytes[1], tx_buff+n);
#else ifdef __BIG_ENDIAN
- n += stuff_byte( fcs.bytes[1], tx_buff+n);
- n += stuff_byte( fcs.bytes[0], tx_buff+n);
+ n += stuff_byte(fcs.bytes[1], tx_buff+n);
+ n += stuff_byte(fcs.bytes[0], tx_buff+n);
#endif
tx_buff[n++] = EOF;
-
+
+#if 0
+ {
+ int i;
+
+ for (i=0;i<n;i++)
+ printk("%02x", tx_buff[i]);
+ printk("\n");
+ }
+#endif
return n;
}
@@ -119,62 +126,62 @@ int async_wrap_skb( struct sk_buff *skb, __u8 *tx_buff, int buffsize)
* Got a frame, make a copy of it, and pass it up the stack!
*
*/
-static __inline__ void async_bump( struct irda_device *idev, __u8 *buf,
- int len)
+static inline void async_bump(struct irda_device *idev, __u8 *buf, int len)
{
struct sk_buff *skb;
-
- skb = dev_alloc_skb( len+1);
- if (skb == NULL) {
- printk( KERN_INFO __FUNCTION__ "() memory squeeze, "
- "dropping frame.\n");
+
+ skb = dev_alloc_skb(len+1);
+ if (!skb) {
idev->stats.rx_dropped++;
return;
}
- /* Align to 20 bytes */
- skb_reserve( skb, 1);
+ /* Align IP header to 20 bytes */
+ skb_reserve(skb, 1);
- ASSERT( len-2 > 0, return;);
-
/* Copy data without CRC */
- skb_put( skb, len-2);
- memcpy( skb->data, buf, len-2);
+ memcpy(skb_put(skb, len-2), buf, len-2);
- idev->rx_buff.len = 0;
/*
* Feed it to IrLAP layer
*/
- /* memcpy(skb_put(skb,count), ax->rbuff, count); */
skb->dev = &idev->netdev;
skb->mac.raw = skb->data;
skb->protocol = htons(ETH_P_IRDA);
- netif_rx( skb);
+ netif_rx(skb);
idev->stats.rx_packets++;
idev->stats.rx_bytes += skb->len;
}
-
+
/*
* Function async_unwrap (skb)
*
* Parse and de-stuff frame received from the IR-port
*
*/
-void async_unwrap_char( struct irda_device *idev, __u8 byte)
+void async_unwrap_char(struct irda_device *idev, __u8 byte)
{
/* State machine for receiving frames */
- switch( idev->rx_buff.state) {
+ switch (idev->rx_buff.state) {
case OUTSIDE_FRAME:
- if ( byte == BOF) {
+ switch(byte) {
+ case BOF:
idev->rx_buff.state = BEGIN_FRAME;
idev->rx_buff.in_frame = TRUE;
- } else if ( byte == EOF) {
+ break;
+ case XBOF:
+ /* idev->xbofs++; */
+ break;
+ case EOF:
irda_device_set_media_busy( idev, TRUE);
+ break;
+ default:
+ break;
}
break;
case BEGIN_FRAME:
- switch ( byte) {
+ switch (byte) {
case BOF:
/* Continue */
break;
@@ -191,33 +198,29 @@ void async_unwrap_char( struct irda_device *idev, __u8 byte)
break;
default:
/* Got first byte of frame */
- if ( idev->rx_buff.len < idev->rx_buff.truesize) {
- idev->rx_buff.data[ idev->rx_buff.len++] = byte;
+ idev->rx_buff.data = idev->rx_buff.head;
+ idev->rx_buff.len = 0;
+
+ idev->rx_buff.data[idev->rx_buff.len++] = byte;
- idev->rx_buff.fcs = IR_FCS( INIT_FCS, byte);
- idev->rx_buff.state = INSIDE_FRAME;
- } else
- printk( "Rx buffer overflow\n");
+ idev->rx_buff.fcs = IR_FCS(INIT_FCS, byte);
+ idev->rx_buff.state = INSIDE_FRAME;
break;
}
break;
case LINK_ESCAPE:
- switch ( byte) {
+ switch (byte) {
case BOF:
/* New frame? */
- DEBUG( 4, "New frame?\n");
idev->rx_buff.state = BEGIN_FRAME;
- idev->rx_buff.len = 0;
- irda_device_set_media_busy( idev, TRUE);
+ irda_device_set_media_busy(idev, TRUE);
break;
case CE:
- DEBUG( 4, "WARNING: State not defined\n");
+ DEBUG(4, "WARNING: State not defined\n");
break;
case EOF:
/* Abort frame */
- DEBUG( 0, "Abort frame (2)\n");
idev->rx_buff.state = OUTSIDE_FRAME;
- idev->rx_buff.len = 0;
break;
default:
/*
@@ -225,23 +228,25 @@ void async_unwrap_char( struct irda_device *idev, __u8 byte)
* following CE, IrLAP p.114
*/
byte ^= IR_TRANS;
- if ( idev->rx_buff.len < idev->rx_buff.truesize) {
- idev->rx_buff.data[ idev->rx_buff.len++] = byte;
-
- idev->rx_buff.fcs = IR_FCS( idev->rx_buff.fcs, byte);
+ if (idev->rx_buff.len < idev->rx_buff.truesize) {
+ idev->rx_buff.data[idev->rx_buff.len++] = byte;
+ idev->rx_buff.fcs = IR_FCS(idev->rx_buff.fcs,
+ byte);
idev->rx_buff.state = INSIDE_FRAME;
- } else
- printk( "Rx buffer overflow\n");
+ } else {
+ DEBUG(1, __FUNCTION__
+ "(), Rx buffer overflow, aborting\n");
+ idev->rx_buff.state = OUTSIDE_FRAME;
+ }
break;
}
break;
case INSIDE_FRAME:
- switch ( byte) {
+ switch (byte) {
case BOF:
/* New frame? */
idev->rx_buff.state = BEGIN_FRAME;
- idev->rx_buff.len = 0;
- irda_device_set_media_busy( idev, TRUE);
+ irda_device_set_media_busy(idev, TRUE);
break;
case CE:
/* Stuffed char */
@@ -255,13 +260,12 @@ void async_unwrap_char( struct irda_device *idev, __u8 byte)
/*
* Test FCS and deliver frame if it's good
*/
- if ( idev->rx_buff.fcs == GOOD_FCS) {
- async_bump( idev, idev->rx_buff.data,
- idev->rx_buff.len);
+ if (idev->rx_buff.fcs == GOOD_FCS) {
+ async_bump(idev, idev->rx_buff.data,
+ idev->rx_buff.len);
} else {
/* Wrong CRC, discard frame! */
- irda_device_set_media_busy( idev, TRUE);
- idev->rx_buff.len = 0;
+ irda_device_set_media_busy(idev, TRUE);
idev->stats.rx_errors++;
idev->stats.rx_crc_errors++;
@@ -269,12 +273,15 @@ void async_unwrap_char( struct irda_device *idev, __u8 byte)
break;
default:
/* Next byte of frame */
- if ( idev->rx_buff.len < idev->rx_buff.truesize) {
- idev->rx_buff.data[ idev->rx_buff.len++] = byte;
-
- idev->rx_buff.fcs = IR_FCS( idev->rx_buff.fcs, byte);
- } else
- printk( "Rx buffer overflow\n");
+ if (idev->rx_buff.len < idev->rx_buff.truesize) {
+ idev->rx_buff.data[idev->rx_buff.len++] = byte;
+ idev->rx_buff.fcs = IR_FCS(idev->rx_buff.fcs,
+ byte);
+ } else {
+ DEBUG(1, __FUNCTION__
+ "(), Rx buffer overflow, aborting\n");
+ idev->rx_buff.state = OUTSIDE_FRAME;
+ }
break;
}
break;
@@ -288,11 +295,11 @@ void async_unwrap_char( struct irda_device *idev, __u8 byte)
* buf. The buffer must at all times be able to have two bytes inserted.
*
*/
-__inline__ static int stuff_byte( __u8 byte, __u8 *buf)
+inline static int stuff_byte(__u8 byte, __u8 *buf)
{
- switch ( byte) {
- case BOF:
- case EOF:
+ switch (byte) {
+ case BOF: /* FALLTHROUGH */
+ case EOF: /* FALLTHROUGH */
case CE:
/* Insert transparently coded */
buf[0] = CE; /* Send link escape */
@@ -308,3 +315,5 @@ __inline__ static int stuff_byte( __u8 byte, __u8 *buf)
}
+
+