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