/* * Function async_unwrap_eof(dev, byte) * * Handle End Of Frame character received within a frame * */ static inline void async_unwrap_eof(struct net_device *dev, struct net_device_stats *stats, iobuff_t *rx_buff, __u8 byte) { #ifdef POSTPONE_RX_CRC int i; #endif switch(rx_buff->state) { case OUTSIDE_FRAME: /* Probably missed the BOF */ stats->rx_errors++; stats->rx_missed_errors++; irda_device_set_media_busy(dev, TRUE); break; case BEGIN_FRAME: case LINK_ESCAPE: case INSIDE_FRAME: default: /* Note : in the case of BEGIN_FRAME and LINK_ESCAPE, * the fcs will most likely not match and generate an * error, as expected - Jean II */ rx_buff->state = OUTSIDE_FRAME; rx_buff->in_frame = FALSE; #ifdef POSTPONE_RX_CRC /* If we haven't done the CRC as we receive bytes, we * must do it now... Jean II */ for(i = 0; i < rx_buff->len; i++) rx_buff->fcs = irda_fcs(rx_buff->fcs, rx_buff->data[i]); #endif /* Test FCS and signal success if the frame is good */ if (rx_buff->fcs == GOOD_FCS) { /* Deliver frame */ async_bump(dev, stats, rx_buff); break; } else { /* Wrong CRC, discard frame! */ irda_device_set_media_busy(dev, TRUE); IRDA_DEBUG(1, "%s(), crc error\n", __FUNCTION__); stats->rx_errors++; stats->rx_crc_errors++; } break; } }
/* * Function async_unwrap_bof(dev, byte) * * Handle Beginning Of Frame character received within a frame * */ static inline void async_unwrap_bof(struct net_device *dev, struct net_device_stats *stats, iobuff_t *rx_buff, __u8 byte) { switch(rx_buff->state) { case LINK_ESCAPE: case INSIDE_FRAME: /* Not supposed to happen, the previous frame is not * finished - Jean II */ IRDA_DEBUG(1, "%s(), Discarding incomplete frame\n", __FUNCTION__); stats->rx_errors++; stats->rx_missed_errors++; irda_device_set_media_busy(dev, TRUE); break; case OUTSIDE_FRAME: case BEGIN_FRAME: default: /* We may receive multiple BOF at the start of frame */ break; } /* Now receiving frame */ rx_buff->state = BEGIN_FRAME; rx_buff->in_frame = TRUE; /* Time to initialize receive buffer */ rx_buff->data = rx_buff->head; rx_buff->len = 0; rx_buff->fcs = INIT_FCS; }
/* * Function async_unwrap_other(dev, byte) * * Handle other characters received within a frame * */ static inline void async_unwrap_other(struct net_device *dev, struct net_device_stats *stats, iobuff_t *rx_buff, __u8 byte) { switch(rx_buff->state) { /* This is on the critical path, case are ordered by * probability (most frequent first) - Jean II */ case INSIDE_FRAME: /* Must be the next byte of the frame */ if (rx_buff->len < rx_buff->truesize) { rx_buff->data[rx_buff->len++] = byte; #ifndef POSTPONE_RX_CRC rx_buff->fcs = irda_fcs(rx_buff->fcs, byte); #endif } else { IRDA_DEBUG(1, "%s(), Rx buffer overflow, aborting\n", __FUNCTION__); rx_buff->state = OUTSIDE_FRAME; } break; case LINK_ESCAPE: /* * Stuffed char, complement bit 5 of byte * following CE, IrLAP p.114 */ byte ^= IRDA_TRANS; if (rx_buff->len < rx_buff->truesize) { rx_buff->data[rx_buff->len++] = byte; #ifndef POSTPONE_RX_CRC rx_buff->fcs = irda_fcs(rx_buff->fcs, byte); #endif rx_buff->state = INSIDE_FRAME; } else { IRDA_DEBUG(1, "%s(), Rx buffer overflow, aborting\n", __FUNCTION__); rx_buff->state = OUTSIDE_FRAME; } break; case OUTSIDE_FRAME: /* Activate carrier sense */ if(byte != XBOF) irda_device_set_media_busy(dev, TRUE); break; case BEGIN_FRAME: default: rx_buff->data[rx_buff->len++] = byte; #ifndef POSTPONE_RX_CRC rx_buff->fcs = irda_fcs(rx_buff->fcs, byte); #endif rx_buff->state = INSIDE_FRAME; break; } }
static int omap1610_irda_ioctl(struct net_device *dev, struct ifreq *ifreq, int cmd) { struct if_irda_req *rq = (struct if_irda_req *)ifreq; struct omap1610_irda *si = dev->priv; int ret = -EOPNOTSUPP; __ECHO_IN; switch (cmd) { case SIOCSBANDWIDTH: if (capable(CAP_NET_ADMIN)) { /* * We are unable to set the speed if the * device is not running. */ if (si->open) { ret = omap1610_irda_set_speed(dev, rq->ifr_baudrate); } else { printk (KERN_ERR "omap_irda_ioctl: SIOCSBANDWIDTH: !netif_running\n"); ret = 0; } } break; case SIOCSMEDIABUSY: ret = -EPERM; if (capable(CAP_NET_ADMIN)) { irda_device_set_media_busy(dev, TRUE); ret = 0; } break; case SIOCGRECEIVING: rq->ifr_receiving = rx_state; break; default: break; } __ECHO_OUT; return ret; }
int sirdev_receive(struct sir_dev *dev, const unsigned char *cp, size_t count) { if (!dev || !dev->netdev) { IRDA_WARNING("%s(), not ready yet!\n", __func__); return -1; } if (!dev->irlap) { IRDA_WARNING("%s - too early: %p / %zd!\n", __func__, cp, count); return -1; } if (cp==NULL) { /* error already at lower level receive * just update stats and set media busy */ irda_device_set_media_busy(dev->netdev, TRUE); dev->netdev->stats.rx_dropped++; IRDA_DEBUG(0, "%s; rx-drop: %zd\n", __func__, count); return 0; } /* Read the characters into the buffer */ if (likely(atomic_read(&dev->enable_rx))) { while (count--) /* Unwrap and destuff one byte */ async_unwrap_char(dev->netdev, &dev->netdev->stats, &dev->rx_buff, *cp++); } else { while (count--) { /* rx not enabled: save the raw bytes and never * trigger any netif_rx. The received bytes are flushed * later when we re-enable rx but might be read meanwhile * by the dongle driver. */ dev->rx_buff.data[dev->rx_buff.len++] = *cp++; /* What should we do when the buffer is full? */ if (unlikely(dev->rx_buff.len == dev->rx_buff.truesize)) dev->rx_buff.len = 0; } } return 0; }
static int pxa_irda_ioctl(struct net_device *dev, struct ifreq *ifreq, int cmd) { struct if_irda_req *rq = (struct if_irda_req *)ifreq; struct pxa_irda *si = netdev_priv(dev); int ret; switch (cmd) { case SIOCSBANDWIDTH: ret = -EPERM; if (capable(CAP_NET_ADMIN)) { /* * We are unable to set the speed if the * device is not running. */ if (netif_running(dev)) { ret = pxa_irda_set_speed(si, rq->ifr_baudrate); } else { printk(KERN_INFO "pxa_ir: SIOCSBANDWIDTH: !netif_running\n"); ret = 0; } } break; case SIOCSMEDIABUSY: ret = -EPERM; if (capable(CAP_NET_ADMIN)) { irda_device_set_media_busy(dev, TRUE); ret = 0; } break; case SIOCGRECEIVING: ret = 0; rq->ifr_receiving = IS_FIR(si) ? 0 : si->rx_buff.state != OUTSIDE_FRAME; break; default: ret = -EOPNOTSUPP; break; } return ret; }
static int omap_irda_ioctl(struct net_device *dev, struct ifreq *ifreq, int cmd) { struct if_irda_req *rq = (struct if_irda_req *)ifreq; struct omap_irda *omap_ir = netdev_priv(dev); int ret = -EOPNOTSUPP; switch (cmd) { case SIOCSBANDWIDTH: if (capable(CAP_NET_ADMIN)) { /* * We are unable to set the speed if the * device is not running. */ if (omap_ir->open) ret = omap_irda_set_speed(dev, rq->ifr_baudrate); else { printk(KERN_ERR "omap_ir: SIOCSBANDWIDTH:" " !netif_running\n"); ret = 0; } } break; case SIOCSMEDIABUSY: ret = -EPERM; if (capable(CAP_NET_ADMIN)) { irda_device_set_media_busy(dev, TRUE); ret = 0; } break; case SIOCGRECEIVING: rq->ifr_receiving = 0; break; default: break; } return ret; }
/* * This function handles network interface ioctls passed to this driver.. * * @param dev net device structure * @param ifreq user request data * @param cmd command issued * * @return The function returns 0 on success and a non-zero value on * failure. */ static int mxc_irda_ioctl(struct net_device *dev, struct ifreq *ifreq, int cmd) { struct if_irda_req *rq = (struct if_irda_req *)ifreq; struct mxc_irda *si = netdev_priv(dev); int ret = -EOPNOTSUPP; switch (cmd) { /* This function will be used by IrLAP to change the speed */ case SIOCSBANDWIDTH: dev_dbg(si->dev, "%s:with cmd SIOCSBANDWIDTH\n", __FUNCTION__); if (capable(CAP_NET_ADMIN)) { /* * We are unable to set the speed if the * device is not running. */ if (si->open) { ret = mxc_irda_set_speed(si, rq->ifr_baudrate); } else { dev_err(si->dev, "mxc_ir_ioctl: SIOCSBANDWIDTH:\ !netif_running\n"); ret = 0; } } break; case SIOCSMEDIABUSY: dev_dbg(si->dev, "%s:with cmd SIOCSMEDIABUSY\n", __FUNCTION__); ret = -EPERM; if (capable(CAP_NET_ADMIN)) { irda_device_set_media_busy(dev, TRUE); ret = 0; } break; case SIOCGRECEIVING: rq->ifr_receiving = IS_SIR(si) ? si->rx_buff.state != OUTSIDE_FRAME : 0; ret = 0; break; default: break; } return ret; }
static int bfin_sir_ioctl(struct net_device *dev, struct ifreq *ifreq, int cmd) { struct if_irda_req *rq = (struct if_irda_req *)ifreq; struct bfin_sir_self *self = netdev_priv(dev); struct bfin_sir_port *port = self->sir_port; int ret = 0; switch (cmd) { case SIOCSBANDWIDTH: if (capable(CAP_NET_ADMIN)) { if (self->open) { ret = bfin_sir_set_speed(port, rq->ifr_baudrate); bfin_sir_enable_rx(port); } else { dev_warn(&dev->dev, "SIOCSBANDWIDTH: !netif_running\n"); ret = 0; } } break; case SIOCSMEDIABUSY: ret = -EPERM; if (capable(CAP_NET_ADMIN)) { irda_device_set_media_busy(dev, TRUE); ret = 0; } break; case SIOCGRECEIVING: rq->ifr_receiving = bfin_sir_is_receiving(dev); break; default: ret = -EOPNOTSUPP; break; } return ret; }
/* * IOCTLs : Extra out-of-band network commands... */ static int kingsun_net_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) { struct if_irda_req *irq = (struct if_irda_req *) rq; struct kingsun_cb *kingsun = netdev_priv(netdev); int ret = 0; switch (cmd) { case SIOCSBANDWIDTH: /* Set bandwidth */ if (!capable(CAP_NET_ADMIN)) return -EPERM; /* Check if the device is still there */ if (netif_device_present(kingsun->netdev)) /* No observed commands for speed change */ ret = -EOPNOTSUPP; break; case SIOCSMEDIABUSY: /* Set media busy */ if (!capable(CAP_NET_ADMIN)) return -EPERM; /* Check if the IrDA stack is still there */ if (netif_running(kingsun->netdev)) irda_device_set_media_busy(kingsun->netdev, TRUE); break; case SIOCGRECEIVING: /* Only approximately true */ irq->ifr_receiving = kingsun->receiving; break; default: ret = -EOPNOTSUPP; } return ret; }
static int kingsun_net_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) { struct if_irda_req *irq = (struct if_irda_req *) rq; struct kingsun_cb *kingsun = netdev_priv(netdev); int ret = 0; switch (cmd) { case SIOCSBANDWIDTH: if (!capable(CAP_NET_ADMIN)) return -EPERM; if (netif_device_present(kingsun->netdev)) ret = -EOPNOTSUPP; break; case SIOCSMEDIABUSY: if (!capable(CAP_NET_ADMIN)) return -EPERM; if (netif_running(kingsun->netdev)) irda_device_set_media_busy(kingsun->netdev, TRUE); break; case SIOCGRECEIVING: irq->ifr_receiving = kingsun->receiving; break; default: ret = -EOPNOTSUPP; } return ret; }
/* * Function async_unwrap_ce(dev, byte) * * Handle Character Escape character received within a frame * */ static inline void async_unwrap_ce(struct net_device *dev, struct net_device_stats *stats, iobuff_t *rx_buff, __u8 byte) { switch(rx_buff->state) { case OUTSIDE_FRAME: /* Activate carrier sense */ irda_device_set_media_busy(dev, TRUE); break; case LINK_ESCAPE: IRDA_WARNING("%s: state not defined\n", __FUNCTION__); break; case BEGIN_FRAME: case INSIDE_FRAME: default: /* Stuffed byte coming */ rx_buff->state = LINK_ESCAPE; break; } }
int sirdev_receive(struct sir_dev *dev, const unsigned char *cp, size_t count) { int i; unsigned char c[32]; unsigned char *eofp, *ebufp; int framelen; if (!dev || !dev->netdev) { IRDA_WARNING("%s(), not ready yet!\n", __func__); return -1; } if (!dev->irlap) { IRDA_WARNING("%s - too early: %p / %zd!\n", __func__, cp, count); return -1; } if (cp==NULL) { /* error already at lower level receive * just update stats and set media busy */ irda_device_set_media_busy(dev->netdev, TRUE); dev->netdev->stats.rx_dropped++; IRDA_DEBUG(0, "%s; rx-drop: %zd\n", __func__, count); return 0; } IRDA_DEBUG(3, "%s; get rx: %zd\n", __func__, count); /* Read the characters into the buffer */ if (likely(atomic_read(&dev->enable_rx))) { rx_count_log = count; if (count >0){ for(i= 0; i<32; i ++){ if (i<count){ c[i] = cp[i]; } else { c[i] = 0x00; } } IRDA_DEBUG(3, "RcvData= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", c[0], c[1], c[2], c[3], c[4], c[5],c[6], c[7], c[8], c[9], c[10], c[11], c[12], c[13],c[14],c[15], c[16], c[17], c[18], c[19], c[20], c[21],c[22], c[23], c[24], c[25], c[26], c[27], c[28], c[29],c[30],c[31] ); } if (count >= 32){ for(i= 0; i<32; i ++){ if ( i < count-32){ c[i] = cp[i+32]; } else { c[i] = 0x00; } } IRDA_DEBUG(3, "RcvData= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", c[0], c[1], c[2], c[3], c[4], c[5],c[6], c[7], c[8], c[9], c[10], c[11], c[12], c[13],c[14],c[15], c[16], c[17], c[18], c[19], c[20], c[21],c[22], c[23], c[24], c[25], c[26], c[27], c[28], c[29],c[30],c[31] ); } if (count >= 64){ for(i= 0; i< 32; i ++){ if ( i < count-64){ c[i] = cp[i+64]; } else { c[i] = 0x00; } } IRDA_DEBUG(3, "RcvData= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", c[0], c[1], c[2], c[3], c[4], c[5],c[6], c[7], c[8], c[9], c[10], c[11], c[12], c[13],c[14],c[15], c[16], c[17], c[18], c[19], c[20], c[21],c[22], c[23], c[24], c[25], c[26], c[27], c[28], c[29],c[30],c[31] ); } if (count >=96){ for(i= 0; i<32; i ++){ if ( i < count-96){ c[i] = cp[i+96]; } else { c[i] = 0x00; } } IRDA_DEBUG(3, "RcvData= %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", c[0], c[1], c[2], c[3], c[4], c[5],c[6], c[7], c[8], c[9], c[10], c[11], c[12], c[13],c[14],c[15], c[16], c[17], c[18], c[19], c[20], c[21],c[22], c[23], c[24], c[25], c[26], c[27], c[28], c[29],c[30],c[31] ); } ebufp = localechobuf; if ( ( count < 20) && localechodata > 0 && dev->rx_buff.state == OUTSIDE_FRAME){ if ( count > localechodata){ if (!memcmp(localechobuf, cp + count - localechodata, localechodata)){ IRDA_DEBUG(4, "%s; data mutch trush %d byte!\n", __func__, count); localechodata = 0; cp += count; count = 0; } } else { if (!memcmp(localechobuf + localechodata - count, cp , count)){ IRDA_DEBUG(4, "%s; data mutch trush %d byte!\n", __func__, count); localechodata = 0; cp += count; count = 0; } } } while (count--){ if (localechodata > 0 && dev->rx_buff.state == OUTSIDE_FRAME){ switch(*cp) { case BOF: if ( count > 1 && *(cp + 1) == BOF){ ebufp ++; localechodata--; cp++; continue; break; } else { eofp = (unsigned char *)memchr( (void *)cp, (int)EOF, count); if ( eofp == NULL){ IRDA_DEBUG(4, "%s; not find eof, get start of next frame.\n", __func__); localechodata = 0; break; } else { framelen = eofp - cp +1 ; if ( framelen <= localechodata && !memcmp((void *)cp, ebufp + localechodata - framelen, framelen)){ IRDA_DEBUG(4, "%s; find one frame, skip it\n", __func__); cp += framelen; count -= framelen; localechodata = 0; break; } else { IRDA_DEBUG(4, "%s; frame line =%d, localechodata = %d.\n", __func__, framelen, localechodata); IRDA_DEBUG(4, "%s; find start of next frame.\n", __func__); localechodata = 0; break; } } } case EOF: IRDA_DEBUG(4, "%s; find end of trush data!\n", __func__); ebufp ++; localechodata = 0; cp++; continue; break; default: ebufp ++; localechodata--; cp++; continue; break; } } async_unwrap_char(dev->netdev, &dev->netdev->stats, &dev->rx_buff, *cp++); } } else { while (count--) { /* rx not enabled: save the raw bytes and never * trigger any netif_rx. The received bytes are flushed * later when we re-enable rx but might be read meanwhile * by the dongle driver. */ dev->rx_buff.data[dev->rx_buff.len++] = *cp++; /* What should we do when the buffer is full? */ if (unlikely(dev->rx_buff.len == dev->rx_buff.truesize)) dev->rx_buff.len = 0; } } return 0; }