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