Home | History | Annotate | Line # | Download | only in sboot
      1 /*	$NetBSD: etherfun.h,v 1.5 2011/02/02 17:53:41 chuck Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 Charles D. Cranor and Seth Widoff
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 /* etherfun.h */
     28 
     29 /* constants */
     30 /* ether header */
     31 #define ETYPE_RARP 0x8035  /* ethertype is RARP */
     32 #define ETYPE_IP   0x800   /* ethertype is IP   */
     33 
     34 /* rev arp */
     35 #define PTYPE_IP 0x800     /* Protocol type is IP      */
     36 #define OPCODE_RARP 3      /* Optype is REVARP request */
     37 #define OPCODE_REPLY 4     /* Optype is REVARP reply   */
     38 
     39 /* ip header */
     40 #define  IPP_UDP 17        /* IP Protocol is UDP       */
     41 #define  IP_VERSION 4      /* IP version number        */
     42 #define  IP_HLEN 5         /* IP header length is a fixed 50 bytes */
     43 #define N 1536
     44 
     45 /* tftp header */
     46 #define FTPOP_ACKN 4      /* Opcode is acknowledge     */
     47 #define FTPOP_ERR 5       /* Opcode is Error	       */
     48 #define FTP_PORT 69       /* Standard TFTP port number */
     49 #define MSG "\0\1xxxxxxxx.147\0octet\0" /* implicit NULL */
     50 
     51 /* data structures */
     52 
     53 struct  ether_header {
     54 	u_char  ether_dhost[6];
     55 	u_char  ether_shost[6];
     56 	u_short ether_type;
     57 };
     58 
     59 struct  ether_arp {
     60 	u_short ar_hrd;		/* format of hardware address */
     61 	u_short ar_pro;		/* format of protocol address */
     62 	u_char  ar_hln;		/* length of hardware address */
     63 	u_char  ar_pln;		/* length of protocol address */
     64 	u_short ar_op;
     65 	u_char  arp_sha[6];	/* sender hardware address */
     66 	u_char  arp_spa[4];	/* sender protocol address */
     67 	u_char  arp_tha[6];	/* target hardware address */
     68 	u_char  arp_tpa[4];	/* target protocol address */
     69 };
     70 
     71 struct ip {
     72 	u_char  ip_v:4,			/* version */
     73 		ip_hl:4;		/* header length */
     74 	u_char  ip_tos;			/* type of service */
     75 	short   ip_len;			/* total length */
     76 	u_short ip_id;			/* identification */
     77 	short   ip_off;			/* fragment offset field */
     78 #define IP_DF 0x4000			/* dont fragment flag */
     79 #define IP_MF 0x2000			/* more fragments flag */
     80 #define IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
     81 	u_char  ip_ttl;			/* time to live */
     82 	u_char  ip_p;			/* protocol */
     83 	u_short ip_sum;			/* checksum */
     84 	u_char  ip_src[4];
     85 	u_char  ip_dst[4];		/* source and dest address */
     86 };
     87 
     88 struct udp {
     89 	u_short uh_sport;
     90 	u_short uh_dport;
     91 	short uh_ulen;
     92 	u_short uh_sum;
     93 };
     94 
     95 struct tftph {
     96 	u_short op_code;
     97 	u_short block;
     98 };
     99 
    100 struct tftphr {
    101 	struct tftph info;
    102 	char data[1];
    103 };
    104 
    105 /* globals */
    106 int last_ack;
    107 u_char buf[N];
    108 struct ether_header *eh = (struct ether_header *)buf;
    109 struct ether_arp *rarp =
    110     (struct ether_arp *)(buf + sizeof(struct ether_header));
    111 struct ip *iph = (struct ip *)(buf + sizeof(struct ether_header));
    112 struct udp *udph = (struct udp *)(buf + sizeof(struct ether_header) +
    113     sizeof(struct ip));
    114 u_char *tftp_r = buf + sizeof(struct ether_header) + sizeof(struct ip) +
    115     sizeof(struct udp);
    116 struct tftph *tftp_a = (struct tftph *)(buf + sizeof(struct ether_header) +
    117     sizeof(struct ip) + sizeof(struct udp));
    118 struct tftphr *tftp = (struct tftphr *)(buf + sizeof(struct ether_header) +
    119     sizeof(struct ip) + sizeof(struct udp));
    120