Example #1
0
static int hsr_header_create(struct sk_buff *skb, struct net_device *dev,
			     unsigned short type, const void *daddr,
			     const void *saddr, unsigned int len)
{
	int res;

	/* Make room for the HSR tag now. We will fill it in later (in
	 * hsr_dev_xmit)
	 */
	if (skb_headroom(skb) < HSR_TAGLEN + ETH_HLEN)
		return -ENOBUFS;
	skb_push(skb, HSR_TAGLEN);

	/* To allow VLAN/HSR combos we should probably use
	 * res = dev_hard_header(skb, dev, type, daddr, saddr, len + HSR_TAGLEN);
	 * here instead. It would require other changes too, though - e.g.
	 * separate headers for each slave etc...
	 */
	res = eth_header(skb, dev, type, daddr, saddr, len + HSR_TAGLEN);
	if (res <= 0)
		return res;
	skb_reset_mac_header(skb);

	return res + HSR_TAGLEN;
}
Example #2
0
BOOL ethernet_test(void)
{
    int t, len;
    static BYTE *tx;
    
    if(!cs8900a_detect()) {
        printf("No cs8900a detected.\n");
        return FALSE;
    }
    
    cs8900a_init();
    
    // prepare to send broadcast packet
    eth_header(&tx_buffer[0], 0x0800);
    ip_header (&tx_buffer[14], 270, 17, 0L, 0xFFFFFFFF);
    udp_header(&tx_buffer[34], 262, 68, 67);
    
    // payload
    tx = &tx_buffer[42];

    // generate DHCP Discovery
    *(tx++) = 0x01; // Boot request
    *(tx++) = 0x01; // Htype = Ethernet
    *(tx++) = 0x06; // Address length = 6
    *(tx++) = 0x00; // Hops = 0
    
    *(tx++) = 0x39; // ID
    *(tx++) = 0x03;
    *(tx++) = 0xF3;
    *(tx++) = 0x26;

    for(t=0;t<20;t++) {
        *(tx++) = 0;
    }

    for(t=0;t<6;t++) {
        *(tx++) = mac[t];
    }

    for(t=6;t<208;t++) {
        *(tx++) = 0;
    }

    *(tx++) = 0x63; // Magic cookie
    *(tx++) = 0x82; // 
    *(tx++) = 0x53; // 
    *(tx++) = 0x63; // 
    
    *(tx++) = 0x35; // DHCP Discover option
    *(tx++) = 0x01; // Length = 1
    *(tx++) = 0x01; // 

    *(tx++) = 0x3D; // DHCP Client ID option
    *(tx++) = 0x07; // Length = 7
    *(tx++) = 0x01; // 
    for(t=0;t<6;t++) {
        *(tx++) = mac[t];
    }

    *(tx++) = 0x37; // DHCP Request list
    *(tx++) = 0x06; // Length = 1

    *(tx++) = 0x01; // Subnet Mask
    *(tx++) = 0x0F; // Domain Name
    *(tx++) = 0x03; // Router
    *(tx++) = 0x06; // DNS
    *(tx++) = 0x1F; // Router discover
    *(tx++) = 0x21; // Static Route

    *(tx++) = 0xFF; // DHCP End
    *(tx++) = 0x00; // Length = 0
    *(tx++) = 0x00; // Length = 0

    // send packet
    cs8900a_tx_frame(tx_buffer, 304);
    
    // we should receive a response!
    for(t=0;t<5000;t++) {
        len = cs8900a_rx_frame(rx_buffer);
        if(len > 10) {
            printf("Frame received: Len = %d.\n", len);
            dump_hex(rx_buffer, 128);
            return TRUE;
        }
        TIMER = 250;
        while(TIMER)
            ;
    }
    printf("No frame received.\n");

    // send packet
    cs8900a_tx_frame(tx_buffer, 304);
    
    // we should receive a response!
    for(t=0;t<5000;t++) {
        len = cs8900a_rx_frame(rx_buffer);
        if(len > 10) {
            printf("Frame received: Len = %d.\n", len);
            dump_hex(rx_buffer, 128);
            return TRUE;
        }
        TIMER = 250;
        while(TIMER)
            ;
    }
    printf("No frame received.\n");


    return FALSE;
}