Beispiel #1
0
Datei: comx.c Projekt: nhanh0/hah
int comx_debug_bytes(struct net_device *dev, unsigned char *bytes, int len,
                     char *msg)
{
    int pos = 0;
    struct comx_channel *ch = dev->priv;

    if (!ch->debug_area) return 0;

    comx_debug(dev, "%s: %s len %d\n", dev->name, msg, len);

    while (pos != len) {
        char line[80];
        int i = 0;

        memset(line, 0, 80);
        sprintf(line,"%04d ", pos);
        do {
            sprintf(line + 5 + (pos % 16) * 3, "%02x", bytes[pos]);
            sprintf(line + 60 + (pos % 16), "%c",
                    isprint(bytes[pos]) ? bytes[pos] : '.');
            pos++;
        } while (pos != len && pos % 16);

        while ( i++ != 78 ) if (line[i] == 0) line[i] = ' ';
        line[77] = '\n';
        line[78] = 0;

        comx_debug(dev, "%s", line);
    }
    comx_debug(dev, "\n");
    return 0;
}
Beispiel #2
0
Datei: comx.c Projekt: nhanh0/hah
int comx_debug_skb(struct net_device *dev, struct sk_buff *skb, char *msg)
{
    struct comx_channel *ch = dev->priv;

    if (!ch->debug_area) return 0;
    if (!skb) comx_debug(dev, "%s: %s NULL skb\n\n", dev->name, msg);
    if (!skb->len) comx_debug(dev, "%s: %s empty skb\n\n", dev->name, msg);

    return comx_debug_bytes(dev, skb->data, skb->len, msg);
}
Beispiel #3
0
static int LOCOMX_send_packet(struct net_device *dev, struct sk_buff *skb) 
{
	struct comx_channel *ch = netdev_priv(dev);
	struct locomx_data *hw = ch->HW_privdata;

	if (ch->debug_flags & DEBUG_HW_TX) {
		comx_debug_bytes(dev, skb->data, skb->len, "LOCOMX_send_packet");
	}

	if (!(ch->line_status & LINE_UP)) {
		return FRAME_DROPPED;
	}

	if(z8530_queue_xmit(&hw->board.chanA,skb)) {
		printk(KERN_WARNING "%s: FRAME_DROPPED\n",dev->name);
		return FRAME_DROPPED;
	}

	if (ch->debug_flags & DEBUG_HW_TX) {
		comx_debug(dev, "%s: LOCOMX_send_packet was successful\n\n", dev->name);
	}

	if(!hw->board.chanA.tx_next_skb) {
		return FRAME_QUEUED;
	} else {
		return FRAME_ACCEPTED;
	}
}
static int comxlapb_exit(struct net_device *dev) 
{
	struct comx_channel *ch = dev->priv;

	dev->flags		= 0;
	dev->type		= 0;
	dev->mtu		= 0;
	dev->hard_header_len    = 0;

	ch->LINE_rx	= NULL;
	ch->LINE_tx	= NULL;
	ch->LINE_status = NULL;
	ch->LINE_open	= NULL;
	ch->LINE_close	= NULL;
	ch->LINE_xmit	= NULL;
	ch->LINE_header	= NULL;
	ch->LINE_statistics = NULL;

	if (ch->debug_flags & DEBUG_COMX_LAPB) {
		comx_debug(dev, "%s: unregistering lapb\n", dev->name);
	}
	lapb_unregister(dev->priv);

	remove_proc_entry(FILENAME_T1, ch->procdir);
	remove_proc_entry(FILENAME_T2, ch->procdir);
	remove_proc_entry(FILENAME_N2, ch->procdir);
	remove_proc_entry(FILENAME_MODE, ch->procdir);
	remove_proc_entry(FILENAME_WINDOW, ch->procdir);

	MOD_DEC_USE_COUNT;
	return 0;
}
static int comxlapb_init(struct net_device *dev)
{
	struct comx_channel *ch = dev->priv;
	struct lapb_register_struct lapbreg;

	dev->mtu		= 1500;
	dev->hard_header_len    = 4;
	dev->addr_len		= 0;

	ch->LINE_rx	= comxlapb_rx;
	ch->LINE_tx	= comxlapb_tx;
	ch->LINE_status = comxlapb_status;
	ch->LINE_open	= comxlapb_open;
	ch->LINE_close	= comxlapb_close;
	ch->LINE_xmit	= comxlapb_xmit;
	ch->LINE_header	= comxlapb_header;
	ch->LINE_statistics = comxlapb_statistics;

	lapbreg.connect_confirmation = comxlapb_connected;
	lapbreg.connect_indication = comxlapb_connected;
	lapbreg.disconnect_confirmation = comxlapb_disconnected;
	lapbreg.disconnect_indication = comxlapb_disconnected;
	lapbreg.data_indication = comxlapb_data_indication;
	lapbreg.data_transmit = comxlapb_data_transmit;
	if (lapb_register(dev->priv, &lapbreg)) {
		return -ENOMEM;
	}
	if (ch->debug_flags & DEBUG_COMX_LAPB) {
		comx_debug(dev, "%s: lapb registered\n", dev->name);
	}

	if (!create_comxlapb_proc_entry(FILENAME_T1, 0644, 8, ch->procdir)) {
		return -ENOMEM;
	}
	if (!create_comxlapb_proc_entry(FILENAME_T2, 0644, 8, ch->procdir)) {
		return -ENOMEM;
	}
	if (!create_comxlapb_proc_entry(FILENAME_N2, 0644, 8, ch->procdir)) {
		return -ENOMEM;
	}
	if (!create_comxlapb_proc_entry(FILENAME_MODE, 0644, 14, ch->procdir)) {
		return -ENOMEM;
	}
	if (!create_comxlapb_proc_entry(FILENAME_WINDOW, 0644, 0, ch->procdir)) {
		return -ENOMEM;
	}

	MOD_INC_USE_COUNT;
	return 0;
}
Beispiel #6
0
static int MIXCOM_send_packet(struct net_device *dev, struct sk_buff *skb) 
{
	struct comx_channel *ch = dev->priv;
	struct mixcom_privdata *hw = ch->HW_privdata;
	unsigned long flags;

	if (ch->debug_flags & DEBUG_HW_TX) {
		comx_debug_bytes(dev, skb->data, skb->len, "MIXCOM_send_packet");
	}

	if (!(ch->line_status & LINE_UP)) {
		return FRAME_DROPPED;
	}

	if (skb->len > HSCX_MTU) {
		ch->stats.tx_errors++;	
		return FRAME_ERROR;
	}

	save_flags(flags); cli();

	if (test_and_set_bit(0, &hw->txbusy)) {
		printk(KERN_ERR "%s: transmitter called while busy... dropping frame (length %d)\n", dev->name, skb->len);
		restore_flags(flags);
		return FRAME_DROPPED;
	}


	hw->sending = skb;
	hw->tx_ptr = 0;
	hw->txbusy = 1;
//	atomic_inc(&skb->users);	// save it
	hscx_fill_fifo(dev);
	restore_flags(flags);

	ch->stats.tx_packets++;
	ch->stats.tx_bytes += skb->len; 

	if (ch->debug_flags & DEBUG_HW_TX) {
		comx_debug(dev, "MIXCOM_send_packet was successful\n\n");
	}

	return FRAME_ACCEPTED;
}
static int comxlapb_close(struct net_device *dev)
{
	struct comx_channel *ch = dev->priv;

	if (!(ch->init_status & HW_OPEN)) {
		return -ENODEV;
	}

	if (ch->debug_flags & DEBUG_COMX_LAPB) {
		comx_debug(dev, "%s: lapb closed\n", dev->name);
	}

	lapb_disconnect_request(ch);

	ch->init_status &= ~LINE_OPEN;
	ch->line_status &= ~PROTO_UP;
	MOD_DEC_USE_COUNT;
	return 0;
}
static int comxlapb_open(struct net_device *dev)
{
	struct comx_channel *ch = dev->priv;
	int err = 0;

	if (!(ch->init_status & HW_OPEN)) {
		return -ENODEV;
	}

	err = lapb_connect_request(ch);

	if (ch->debug_flags & DEBUG_COMX_LAPB) {
		comx_debug(dev, "%s: lapb opened, error code: %d\n", 
			dev->name, err);
	}

	if (!err) {
		ch->init_status |= LINE_OPEN;
		MOD_INC_USE_COUNT;
	}
	return err;
}
static void comxlapb_connected(void *token, int reason)
{
	struct comx_channel *ch = token; 
	struct proc_dir_entry *comxdir = ch->procdir->subdir;

	if (ch->debug_flags & DEBUG_COMX_LAPB) {
		comx_debug(ch->dev, "%s: lapb connected, reason: %d\n", 
			ch->dev->name, reason);
	}

	if (ch->dev->type == ARPHRD_X25) {
		unsigned char *p;
		struct sk_buff *skb;

		if ((skb = dev_alloc_skb(1)) == NULL) {
			printk(KERN_ERR "comxlapb: out of memory!\n");
			return;
		}
		p = skb_put(skb,1);
		*p = 0x01;		// link established
		skb->dev = ch->dev;
		skb->protocol = htons(ETH_P_X25);
		skb->mac.raw = skb->data;
		skb->pkt_type = PACKET_HOST;

		netif_rx(skb);
		ch->dev->last_rx = jiffies;
	}

	for (; comxdir; comxdir = comxdir->next) {
		if (strcmp(comxdir->name, FILENAME_MODE) == 0) {
			comxdir->mode = S_IFREG | 0444;
		}
	}


	ch->line_status |= PROTO_UP;
	comx_status(ch->dev, ch->line_status);
}