wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copied from LiMon - BOOTP. |
| 3 | * |
| 4 | * Copyright 1994, 1995, 2000 Neil Russell. |
| 5 | * (See License) |
| 6 | * Copyright 2000 Paolo Scaffardi |
| 7 | */ |
| 8 | |
| 9 | #ifndef __BOOTP_H__ |
| 10 | #define __BOOTP_H__ |
| 11 | |
| 12 | #ifndef __NET_H__ |
Joe Hershberger | 3090b7e3 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 13 | #include <net.h> |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 14 | #endif /* __NET_H__ */ |
| 15 | |
| 16 | /**********************************************************************/ |
| 17 | |
| 18 | /* |
| 19 | * BOOTP header. |
| 20 | */ |
Jon Loeliger | 643d1ab | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 21 | #if defined(CONFIG_CMD_DHCP) |
Joe Hershberger | 3090b7e3 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 22 | /* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */ |
Joe Hershberger | f831573 | 2012-05-23 07:58:14 +0000 | [diff] [blame] | 23 | #define OPT_FIELD_SIZE 312 |
Joe Hershberger | 3090b7e3 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 24 | #if defined(CONFIG_BOOTP_VENDOREX) |
| 25 | extern u8 *dhcp_vendorex_prep(u8 *e); /*rtn new e after add own opts. */ |
| 26 | extern u8 *dhcp_vendorex_proc(u8 *e); /*rtn next e if mine,else NULL */ |
| 27 | #endif |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 28 | #else |
Joe Hershberger | f831573 | 2012-05-23 07:58:14 +0000 | [diff] [blame] | 29 | #define OPT_FIELD_SIZE 64 |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 30 | #endif |
| 31 | |
Joe Hershberger | 7044c6b | 2015-04-08 01:41:09 -0500 | [diff] [blame] | 32 | struct bootp_hdr { |
Sergey Temerkhanov | 717234e | 2015-04-08 01:41:23 -0500 | [diff] [blame] | 33 | u8 bp_op; /* Operation */ |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 34 | # define OP_BOOTREQUEST 1 |
| 35 | # define OP_BOOTREPLY 2 |
Sergey Temerkhanov | 717234e | 2015-04-08 01:41:23 -0500 | [diff] [blame] | 36 | u8 bp_htype; /* Hardware type */ |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 37 | # define HWT_ETHER 1 |
Sergey Temerkhanov | 717234e | 2015-04-08 01:41:23 -0500 | [diff] [blame] | 38 | u8 bp_hlen; /* Hardware address length */ |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 39 | # define HWL_ETHER 6 |
Sergey Temerkhanov | 717234e | 2015-04-08 01:41:23 -0500 | [diff] [blame] | 40 | u8 bp_hops; /* Hop count (gateway thing) */ |
Sergey Temerkhanov | 5917e7d | 2015-04-08 01:41:22 -0500 | [diff] [blame] | 41 | u32 bp_id; /* Transaction ID */ |
Sergey Temerkhanov | 717234e | 2015-04-08 01:41:23 -0500 | [diff] [blame] | 42 | u16 bp_secs; /* Seconds since boot */ |
| 43 | u16 bp_spare1; /* Alignment */ |
Joe Hershberger | 049a95a | 2015-04-08 01:41:01 -0500 | [diff] [blame] | 44 | struct in_addr bp_ciaddr; /* Client IP address */ |
| 45 | struct in_addr bp_yiaddr; /* Your (client) IP address */ |
| 46 | struct in_addr bp_siaddr; /* Server IP address */ |
| 47 | struct in_addr bp_giaddr; /* Gateway IP address */ |
Sergey Temerkhanov | 717234e | 2015-04-08 01:41:23 -0500 | [diff] [blame] | 48 | u8 bp_chaddr[16]; /* Client hardware address */ |
Joe Hershberger | 3090b7e3 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 49 | char bp_sname[64]; /* Server host name */ |
| 50 | char bp_file[128]; /* Boot file name */ |
Joe Hershberger | f831573 | 2012-05-23 07:58:14 +0000 | [diff] [blame] | 51 | char bp_vend[OPT_FIELD_SIZE]; /* Vendor information */ |
Denis Pynkin | 704f3ac | 2017-07-21 19:28:42 +0300 | [diff] [blame] | 52 | } __attribute__((packed)); |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 53 | |
Joe Hershberger | 7044c6b | 2015-04-08 01:41:09 -0500 | [diff] [blame] | 54 | #define BOOTP_HDR_SIZE sizeof(struct bootp_hdr) |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 55 | |
| 56 | /**********************************************************************/ |
| 57 | /* |
| 58 | * Global functions and variables. |
| 59 | */ |
| 60 | |
| 61 | /* bootp.c */ |
Sergey Temerkhanov | 5917e7d | 2015-04-08 01:41:22 -0500 | [diff] [blame] | 62 | extern u32 bootp_id; /* ID of cur BOOTP request */ |
Joe Hershberger | 7044c6b | 2015-04-08 01:41:09 -0500 | [diff] [blame] | 63 | extern int bootp_try; |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 64 | |
| 65 | |
| 66 | /* Send a BOOTP request */ |
Joe Hershberger | 7044c6b | 2015-04-08 01:41:09 -0500 | [diff] [blame] | 67 | void bootp_reset(void); |
| 68 | void bootp_request(void); |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 69 | |
| 70 | /****************** DHCP Support *********************/ |
Joe Hershberger | 7044c6b | 2015-04-08 01:41:09 -0500 | [diff] [blame] | 71 | void dhcp_request(void); |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 72 | |
| 73 | /* DHCP States */ |
| 74 | typedef enum { INIT, |
| 75 | INIT_REBOOT, |
| 76 | REBOOTING, |
| 77 | SELECTING, |
| 78 | REQUESTING, |
| 79 | REBINDING, |
| 80 | BOUND, |
| 81 | RENEWING } dhcp_state_t; |
| 82 | |
| 83 | #define DHCP_DISCOVER 1 |
| 84 | #define DHCP_OFFER 2 |
| 85 | #define DHCP_REQUEST 3 |
| 86 | #define DHCP_DECLINE 4 |
| 87 | #define DHCP_ACK 5 |
| 88 | #define DHCP_NAK 6 |
| 89 | #define DHCP_RELEASE 7 |
| 90 | |
wdenk | efee170 | 2002-07-20 20:14:13 +0000 | [diff] [blame] | 91 | /**********************************************************************/ |
| 92 | |
| 93 | #endif /* __BOOTP_H__ */ |