• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Beken Corporation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __DHCP_BOOTP_H_
16 #define __DHCP_BOOTP_H_
17 
18 #define DHCP_SERVER_PORT    		67
19 #define DHCP_CLIENT_PORT    		68
20 
21 #define NAMESERVER_PORT    			53
22 
23 #define CTRL_PORT                   12679
24 
25 #define BOOTP_OP_REQUEST			1
26 #define BOOTP_OP_RESPONSE			2
27 
28 #define BOOTP_OPTION_SUBNET_MASK	1
29 #define BOOTP_OPTION_ROUTER			3
30 #define BOOTP_OPTION_NAMESERVER		6
31 #define BOOTP_OPTION_REQUESTED_IP	50
32 #define BOOTP_OPTION_ADDRESS_TIME	51
33 #define BOOTP_OPTION_DHCP_MESSAGE	53
34 #define BOOTP_OPTION_DHCP_SERVER_ID	54
35 #define BOOTP_END_OPTION			0xFF
36 
37 enum dhcp_message_type {
38 	DHCP_MESSAGE_DISCOVER = 1,
39 	DHCP_MESSAGE_OFFER = 2,
40 	DHCP_MESSAGE_REQUEST = 3,
41 	DHCP_MESSAGE_DECLINE = 4,
42 	DHCP_MESSAGE_ACK = 5,
43 	DHCP_MESSAGE_NAK = 6,
44 	DHCP_MESSAGE_RELEASE = 7,
45 	DHCP_MESSAGE_INFORM = 8,
46 	DHCP_NO_RESPONSE = 255
47 };
48 
49 struct bootp_header {
50 	uint8_t op;		/* message type */
51 	uint8_t htype;		/* hardware type (1 = ethernet) */
52 	uint8_t hlen;		/* hardware address length (6) */
53 	uint8_t hops;		/* (0) */
54 	uint32_t xid;		/* transaction ID */
55 	uint16_t secs;		/* seconds elapsed */
56 	uint16_t flags;		/* bootp flags */
57 	uint32_t ciaddr;		/* client IP address */
58 	uint32_t yiaddr;		/* your IP address */
59 	uint32_t siaddr;		/* next server IP address */
60 	uint32_t riaddr;		/* relay agent IP address */
61 	uint8_t chaddr[6];	/* client MAC address */
62 	uint8_t pad[10 + 192];	/* 10 octets of padding, 192 octets of
63 				   padding */
64 	uint32_t cookie;		/* magic cookie */
65 } __attribute__((packed));
66 
67 struct bootp_option {
68 	uint8_t type;
69 	uint8_t length;
70 	char value[0];
71 } __attribute__((packed));
72 #define ETH_P_RARP      0x8035
73 
74 #define ETH_HW_ADDR_LEN 6
75 #define IP_ADDR_LEN 4
76 #define ARP_FRAME_TYPE 0x0806
77 #define ETHER_HW_TYPE 1
78 #define IP_PROTO_TYPE 0x0800
79 #define OP_ARP_REQUEST 2
80 #define SOCK_PACKET 10
81 
82 struct arp_packet {
83 	uint8_t targ_hw_addr[ETH_HW_ADDR_LEN];
84 	uint8_t src_hw_addr[ETH_HW_ADDR_LEN];
85 	uint16_t frame_type;
86 	uint16_t hw_type;
87 	uint16_t prot_type;
88 	uint8_t hw_addr_size;
89 	uint8_t prot_addr_size;
90 	uint16_t op;
91 	uint8_t sndr_hw_addr[ETH_HW_ADDR_LEN];
92 	char sndr_ip_addr[IP_ADDR_LEN];
93 	uint8_t rcpt_hw_addr[ETH_HW_ADDR_LEN];
94 	char rcpt_ip_addr[IP_ADDR_LEN];
95 	uint8_t padding[18];
96 };
97 
98 #endif
99