/* Check packet length, pad short packets, round up odd length */ 
/* Length of the packet body */ /* FIXME: what if the skb is smaller than this? */ 
static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev){	struct orinoco_private *priv = netdev_priv(dev);	struct net_device_stats *stats = &priv->stats;	hermes_t *hw = &priv->hw;	int err = 0;	u16 txfid = priv->txfid;	char *p;	struct ethhdr *eh;	int len, data_len, data_off;	struct hermes_tx_descriptor desc;	unsigned long flags;	TRACE_ENTER(dev->name);	if (! netif_running(dev)) {		printk(KERN_ERR "%s: Tx on stopped device!\n",		       dev->name);		TRACE_EXIT(dev->name);		return 1;	}		if (netif_queue_stopped(dev)) {		printk(KERN_DEBUG "%s: Tx while transmitter busy!\n", 		       dev->name);		TRACE_EXIT(dev->name);		return 1;	}		if (orinoco_lock(priv, &flags) != 0) {		printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",		       dev->name);		TRACE_EXIT(dev->name);		return 1;	}	if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {		/* Oops, the firmware hasn't established a connection,                   silently drop the packet (this seems to be the                   safest approach). */		stats->tx_errors++;		orinoco_unlock(priv, &flags);		dev_kfree_skb(skb);		TRACE_EXIT(dev->name);		return 0;	}	/* Check packet length, pad short packets, round up odd length */	len = max_t(int, ALIGN(skb->len, 2), ETH_ZLEN);	skb = skb_padto(skb, len);	if (skb == NULL)		goto fail;	len -= ETH_HLEN;	eh = (struct ethhdr *)skb->data;	memset(&desc, 0, sizeof(desc)); 	desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);	err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);	if (err) {		if (net_ratelimit())			printk(KERN_ERR "%s: Error %d writing Tx descriptor "			       "to BAP\n", dev->name, err);		stats->tx_errors++;		goto fail;	}	/* Clear the 802.11 header and data length fields - some	 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused	 * if this isn't done. */	hermes_clear_words(hw, HERMES_DATA0,			   HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);	/* Encapsulate Ethernet-II frames */	if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */		struct header_struct hdr;		data_len = len;		data_off = HERMES_802_3_OFFSET + sizeof(hdr);		p = skb->data + ETH_HLEN;		/* 802.3 header */		memcpy(hdr.dest, eh->h_dest, ETH_ALEN);		memcpy(hdr.src, eh->h_source, ETH_ALEN);		hdr.len = htons(data_len + ENCAPS_OVERHEAD);				/* 802.2 header */		memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));					hdr.ethertype = eh->h_proto;		err  = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),					 txfid, HERMES_802_3_OFFSET);		if (err) {			if (net_ratelimit())				printk(KERN_ERR "%s: Error %d writing packet "				       "header to BAP\n", dev->name, err);			stats->tx_errors++;			goto fail;		}	} else { /* IEEE 802.3 frame */		data_len = len + ETH_HLEN;		data_off = HERMES_802_3_OFFSET;		p = skb->data;	}	err = hermes_bap_pwrite(hw, USER_BAP, p, data_len,				txfid, data_off);	if (err) {		printk(KERN_ERR "%s: Error %d writing packet to BAP\n",		       dev->name, err);		stats->tx_errors++;		goto fail;	}	/* Finally, we actually initiate the send */	netif_stop_queue(dev);	err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,				txfid, NULL);	if (err) {		netif_start_queue(dev);		if (net_ratelimit())			printk(KERN_ERR "%s: Error %d transmitting packet\n",				dev->name, err);		stats->tx_errors++;		goto fail;	}	dev->trans_start = jiffies;	stats->tx_bytes += data_off + data_len;	orinoco_unlock(priv, &flags);	dev_kfree_skb(skb);	TRACE_EXIT(dev->name);	return 0; fail:	TRACE_EXIT(dev->name);	orinoco_unlock(priv, &flags);	return err;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/63f57fb69b017230c77c40f1713e40885ae6d159/orinoco.c/buggy/drivers/net/wireless/orinoco.c