CDC/ECM driver for mbed, based on USBDevice by mbed-official. Uses PicoTCP to access Ethernet USB device. License: GPLv2

Dependents:   USBEthernet_TEST

Fork of USB_Ethernet by Daniele Lacamera

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pico_dhcp_common.h Source File

pico_dhcp_common.h

00001 /*********************************************************************
00002 PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved.
00003 See LICENSE and COPYING for usage.
00004 
00005 .
00006 
00007 *********************************************************************/
00008 #ifndef _INCLUDE_PICO_DHCP_COMMON
00009 #define _INCLUDE_PICO_DHCP_COMMON
00010 
00011 
00012 #include <stdint.h>
00013 
00014 //minimum size is 576, cfr RFC
00015 #define DHCPC_DATAGRAM_SIZE 576
00016 #define DHCPD_DATAGRAM_SIZE 576
00017 
00018 
00019 #define PICO_DHCPD_PORT (short_be(67))
00020 #define PICO_DHCP_CLIENT_PORT (short_be(68))
00021 
00022 #define PICO_DHCP_OP_REQUEST 1
00023 #define PICO_DHCP_OP_REPLY   2
00024 
00025 #define PICO_HTYPE_ETHER 1
00026 #define PICO_HLEN_ETHER  6
00027 
00028 #define PICO_DHCPD_MAGIC_COOKIE (long_be(0x63825363))
00029 
00030 /* DHCP OPTIONS, RFC2132 */
00031 #define PICO_DHCPOPT_PAD                     0x00
00032 #define PICO_DHCPOPT_NETMASK                 0x01
00033 #define PICO_DHCPOPT_TIME                    0x02
00034 #define PICO_DHCPOPT_ROUTER                  0x03
00035 #define PICO_DHCPOPT_DNS                     0x06
00036 #define PICO_DHCPOPT_HOSTNAME                0x0c
00037 #define PICO_DHCPOPT_DOMAINNAME              0x0f
00038 #define PICO_DHCPOPT_MTU                     0x1a
00039 #define PICO_DHCPOPT_BCAST                   0x1c
00040 #define PICO_DHCPOPT_NETBIOSNS               0x2c
00041 #define PICO_DHCPOPT_NETBIOSSCOPE            0x2f
00042 
00043 #define PICO_DHCPOPT_REQIP                   0x32
00044 #define PICO_DHCPOPT_LEASETIME               0x33
00045 #define PICO_DHCPOPT_OPTIONOVERLOAD          0x34
00046 #define PICO_DHCPOPT_MSGTYPE                 0x35
00047 #define PICO_DHCPOPT_SERVERID                0x36
00048 #define PICO_DHCPOPT_PARMLIST                0x37
00049 #define PICO_DHCPOPT_MAXMSGSIZE              0x39
00050 #define PICO_DHCPOPT_RENEWALTIME             0x3a
00051 #define PICO_DHCPOPT_REBINDINGTIME           0x3b
00052 #define PICO_DHCPOPT_DOMAINSEARCH            0x77
00053 #define PICO_DHCPOPT_STATICROUTE             0x79
00054 #define PICO_DHCPOPT_END                     0xFF
00055 
00056 /* DHCP MESSAGE TYPE */
00057 #define PICO_DHCP_MSG_DISCOVER               1
00058 #define PICO_DHCP_MSG_OFFER                  2
00059 #define PICO_DHCP_MSG_REQUEST                3
00060 #define PICO_DHCP_MSG_DECLINE                4
00061 #define PICO_DHCP_MSG_ACK                    5
00062 #define PICO_DHCP_MSG_NAK                    6
00063 #define PICO_DHCP_MSG_RELEASE                7
00064 #define PICO_DHCP_MSG_INFORM                 8
00065 
00066 
00067 enum dhcp_negotiation_state {
00068         DHCPSTATE_DISCOVER = 0,
00069         DHCPSTATE_OFFER,
00070         DHCPSTATE_REQUEST,
00071         DHCPSTATE_BOUND,
00072         DHCPSTATE_RENEWING
00073 };
00074 
00075 
00076 struct __attribute__((packed)) pico_dhcphdr
00077 {
00078     uint8_t op;
00079     uint8_t htype;
00080     uint8_t hlen;
00081     uint8_t hops; //zero
00082     uint32_t xid; //store this in the request
00083     uint16_t secs; // ignore
00084     uint16_t flags;
00085     uint32_t ciaddr; // client address - if asking for renewal
00086     uint32_t yiaddr; // your address (client)
00087     uint32_t siaddr; // dhcp offered address
00088     uint32_t giaddr; // relay agent, bootp.
00089     uint8_t hwaddr[6];
00090     uint8_t hwaddr_padding[10];
00091     char    hostname[64];
00092     char    bootp_filename[128];
00093     uint32_t dhcp_magic;
00094     uint8_t options[0];
00095 };
00096 
00097 
00098 //common functions for client and server
00099 
00100 uint8_t dhcp_get_next_option(uint8_t *begin, uint8_t *data, int *len, uint8_t **nextopt);
00101 int is_options_valid(uint8_t *opt_buffer, int len); 
00102 #endif