• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2008, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _WIFI_DHCP_H_
18 #define _WIFI_DHCP_H_
19 
20 #include <sys/types.h>
21 
22 #define PORT_BOOTP_SERVER 67
23 #define PORT_BOOTP_CLIENT 68
24 
25 /* RFC 2131 p 9 */
26 typedef struct dhcp_msg dhcp_msg;
27 
28 #define OP_BOOTREQUEST 1
29 #define OP_BOOTREPLY   2
30 
31 #define FLAGS_BROADCAST 0x8000
32 
33 #define HTYPE_ETHER    1
34 
35 struct dhcp_msg
36 {
37     uint8_t op;           /* BOOTREQUEST / BOOTREPLY    */
38     uint8_t htype;        /* hw addr type               */
39     uint8_t hlen;         /* hw addr len                */
40     uint8_t hops;         /* client set to 0            */
41 
42     uint32_t xid;         /* transaction id             */
43 
44     uint16_t secs;        /* seconds since start of acq */
45     uint16_t flags;
46 
47     uint32_t ciaddr;      /* client IP addr             */
48     uint32_t yiaddr;      /* your (client) IP addr      */
49     uint32_t siaddr;      /* ip addr of next server     */
50                           /* (DHCPOFFER and DHCPACK)    */
51     uint32_t giaddr;      /* relay agent IP addr        */
52 
53     uint8_t chaddr[16];  /* client hw addr             */
54     char sname[64];      /* asciiz server hostname     */
55     char file[128];      /* asciiz boot file name      */
56 
57     uint8_t options[1024];  /* optional parameters        */
58 };
59 
60 #define DHCP_MSG_FIXED_SIZE 236
61 
62 /* first four bytes of options are a cookie to indicate that
63 ** the payload are DHCP options as opposed to some other BOOTP
64 ** extension.
65 */
66 #define OPT_COOKIE1          0x63
67 #define OPT_COOKIE2          0x82
68 #define OPT_COOKIE3          0x53
69 #define OPT_COOKIE4          0x63
70 
71 /* BOOTP/DHCP options - see RFC 2132 */
72 #define OPT_PAD              0
73 
74 #define OPT_SUBNET_MASK      1     /* 4 <ipaddr> */
75 #define OPT_TIME_OFFSET      2     /* 4 <seconds> */
76 #define OPT_GATEWAY          3     /* 4*n <ipaddr> * n */
77 #define OPT_DNS              6     /* 4*n <ipaddr> * n */
78 #define OPT_DOMAIN_NAME      15    /* n <domainnamestring> */
79 #define OPT_BROADCAST_ADDR   28    /* 4 <ipaddr> */
80 
81 #define OPT_REQUESTED_IP     50    /* 4 <ipaddr> */
82 #define OPT_LEASE_TIME       51    /* 4 <seconds> */
83 #define OPT_MESSAGE_TYPE     53    /* 1 <msgtype> */
84 #define OPT_SERVER_ID        54    /* 4 <ipaddr> */
85 #define OPT_PARAMETER_LIST   55    /* n <optcode> * n */
86 #define OPT_MESSAGE          56    /* n <errorstring> */
87 #define OPT_CLASS_ID         60    /* n <opaque> */
88 #define OPT_CLIENT_ID        61    /* n <opaque> */
89 #define OPT_END              255
90 
91 /* DHCP message types */
92 #define DHCPDISCOVER         1
93 #define DHCPOFFER            2
94 #define DHCPREQUEST          3
95 #define DHCPDECLINE          4
96 #define DHCPACK              5
97 #define DHCPNAK              6
98 #define DHCPRELEASE          7
99 #define DHCPINFORM           8
100 
101 int init_dhcp_discover_msg(dhcp_msg *msg, void *hwaddr, uint32_t xid);
102 
103 int init_dhcp_request_msg(dhcp_msg *msg, void *hwaddr, uint32_t xid,
104                           uint32_t ipaddr, uint32_t serveraddr);
105 
106 #endif
107