dhcpmsg.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #ifndef _WIFI_DHCP_H_
  17. #define _WIFI_DHCP_H_
  18. #include <sys/types.h>
  19. #define PORT_BOOTP_SERVER 67
  20. #define PORT_BOOTP_CLIENT 68
  21. /* RFC 2131 p 9 */
  22. typedef struct dhcp_msg dhcp_msg;
  23. #define OP_BOOTREQUEST 1
  24. #define OP_BOOTREPLY 2
  25. #define FLAGS_BROADCAST 0x8000
  26. #define HTYPE_ETHER 1
  27. struct dhcp_msg
  28. {
  29. uint8_t op; /* BOOTREQUEST / BOOTREPLY */
  30. uint8_t htype; /* hw addr type */
  31. uint8_t hlen; /* hw addr len */
  32. uint8_t hops; /* client set to 0 */
  33. uint32_t xid; /* transaction id */
  34. uint16_t secs; /* seconds since start of acq */
  35. uint16_t flags;
  36. uint32_t ciaddr; /* client IP addr */
  37. uint32_t yiaddr; /* your (client) IP addr */
  38. uint32_t siaddr; /* ip addr of next server */
  39. /* (DHCPOFFER and DHCPACK) */
  40. uint32_t giaddr; /* relay agent IP addr */
  41. uint8_t chaddr[16]; /* client hw addr */
  42. char sname[64]; /* asciiz server hostname */
  43. char file[128]; /* asciiz boot file name */
  44. uint8_t options[1024]; /* optional parameters */
  45. };
  46. #define DHCP_MSG_FIXED_SIZE 236
  47. /* first four bytes of options are a cookie to indicate that
  48. ** the payload are DHCP options as opposed to some other BOOTP
  49. ** extension.
  50. */
  51. #define OPT_COOKIE1 0x63
  52. #define OPT_COOKIE2 0x82
  53. #define OPT_COOKIE3 0x53
  54. #define OPT_COOKIE4 0x63
  55. /* BOOTP/DHCP options - see RFC 2132 */
  56. #define OPT_PAD 0
  57. #define OPT_SUBNET_MASK 1 /* 4 <ipaddr> */
  58. #define OPT_TIME_OFFSET 2 /* 4 <seconds> */
  59. #define OPT_GATEWAY 3 /* 4*n <ipaddr> * n */
  60. #define OPT_DNS 6 /* 4*n <ipaddr> * n */
  61. #define OPT_DOMAIN_NAME 15 /* n <domainnamestring> */
  62. #define OPT_BROADCAST_ADDR 28 /* 4 <ipaddr> */
  63. #define OPT_REQUESTED_IP 50 /* 4 <ipaddr> */
  64. #define OPT_LEASE_TIME 51 /* 4 <seconds> */
  65. #define OPT_MESSAGE_TYPE 53 /* 1 <msgtype> */
  66. #define OPT_SERVER_ID 54 /* 4 <ipaddr> */
  67. #define OPT_PARAMETER_LIST 55 /* n <optcode> * n */
  68. #define OPT_MESSAGE 56 /* n <errorstring> */
  69. #define OPT_CLASS_ID 60 /* n <opaque> */
  70. #define OPT_CLIENT_ID 61 /* n <opaque> */
  71. #define OPT_END 255
  72. /* DHCP message types */
  73. #define DHCPDISCOVER 1
  74. #define DHCPOFFER 2
  75. #define DHCPREQUEST 3
  76. #define DHCPDECLINE 4
  77. #define DHCPACK 5
  78. #define DHCPNAK 6
  79. #define DHCPRELEASE 7
  80. #define DHCPINFORM 8
  81. int init_dhcp_discover_msg(dhcp_msg *msg, void *hwaddr, uint32_t xid);
  82. int init_dhcp_request_msg(dhcp_msg *msg, void *hwaddr, uint32_t xid,
  83. uint32_t ipaddr, uint32_t serveraddr);
  84. #endif