Webserver+3d print

Dependents:   Nucleo

Committer:
Sergunb
Date:
Sat Feb 04 18:15:49 2017 +0000
Revision:
0:8918a71cdbe9
nothing else

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sergunb 0:8918a71cdbe9 1 /**
Sergunb 0:8918a71cdbe9 2 * @file dhcp_server.h
Sergunb 0:8918a71cdbe9 3 * @brief DHCP server (Dynamic Host Configuration Protocol)
Sergunb 0:8918a71cdbe9 4 *
Sergunb 0:8918a71cdbe9 5 * @section License
Sergunb 0:8918a71cdbe9 6 *
Sergunb 0:8918a71cdbe9 7 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
Sergunb 0:8918a71cdbe9 8 *
Sergunb 0:8918a71cdbe9 9 * This file is part of CycloneTCP Open.
Sergunb 0:8918a71cdbe9 10 *
Sergunb 0:8918a71cdbe9 11 * This program is free software; you can redistribute it and/or
Sergunb 0:8918a71cdbe9 12 * modify it under the terms of the GNU General Public License
Sergunb 0:8918a71cdbe9 13 * as published by the Free Software Foundation; either version 2
Sergunb 0:8918a71cdbe9 14 * of the License, or (at your option) any later version.
Sergunb 0:8918a71cdbe9 15 *
Sergunb 0:8918a71cdbe9 16 * This program is distributed in the hope that it will be useful,
Sergunb 0:8918a71cdbe9 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Sergunb 0:8918a71cdbe9 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Sergunb 0:8918a71cdbe9 19 * GNU General Public License for more details.
Sergunb 0:8918a71cdbe9 20 *
Sergunb 0:8918a71cdbe9 21 * You should have received a copy of the GNU General Public License
Sergunb 0:8918a71cdbe9 22 * along with this program; if not, write to the Free Software Foundation,
Sergunb 0:8918a71cdbe9 23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Sergunb 0:8918a71cdbe9 24 *
Sergunb 0:8918a71cdbe9 25 * @author Oryx Embedded SARL (www.oryx-embedded.com)
Sergunb 0:8918a71cdbe9 26 * @version 1.7.6
Sergunb 0:8918a71cdbe9 27 **/
Sergunb 0:8918a71cdbe9 28
Sergunb 0:8918a71cdbe9 29 #ifndef _DHCP_SERVER_H
Sergunb 0:8918a71cdbe9 30 #define _DHCP_SERVER_H
Sergunb 0:8918a71cdbe9 31
Sergunb 0:8918a71cdbe9 32 //Dependencies
Sergunb 0:8918a71cdbe9 33 #include "core/net.h"
Sergunb 0:8918a71cdbe9 34
Sergunb 0:8918a71cdbe9 35 //DHCP server support
Sergunb 0:8918a71cdbe9 36 #ifndef DHCP_SERVER_SUPPORT
Sergunb 0:8918a71cdbe9 37 #define DHCP_SERVER_SUPPORT DISABLED
Sergunb 0:8918a71cdbe9 38 #elif (DHCP_SERVER_SUPPORT != ENABLED && DHCP_SERVER_SUPPORT != DISABLED)
Sergunb 0:8918a71cdbe9 39 #error DHCP_SERVER_SUPPORT parameter is not valid
Sergunb 0:8918a71cdbe9 40 #endif
Sergunb 0:8918a71cdbe9 41
Sergunb 0:8918a71cdbe9 42 //DHCP server tick interval
Sergunb 0:8918a71cdbe9 43 #ifndef DHCP_SERVER_TICK_INTERVAL
Sergunb 0:8918a71cdbe9 44 #define DHCP_SERVER_TICK_INTERVAL 1000
Sergunb 0:8918a71cdbe9 45 #elif (DHCP_SERVER_TICK_INTERVAL < 10)
Sergunb 0:8918a71cdbe9 46 #error DHCP_SERVER_TICK_INTERVAL parameter is not valid
Sergunb 0:8918a71cdbe9 47 #endif
Sergunb 0:8918a71cdbe9 48
Sergunb 0:8918a71cdbe9 49 //Maximum number of clients
Sergunb 0:8918a71cdbe9 50 #ifndef DHCP_SERVER_MAX_CLIENTS
Sergunb 0:8918a71cdbe9 51 #define DHCP_SERVER_MAX_CLIENTS 16
Sergunb 0:8918a71cdbe9 52 #elif (DHCP_SERVER_MAX_CLIENTS < 1)
Sergunb 0:8918a71cdbe9 53 #error DHCP_SERVER_MAX_CLIENTS parameter is not valid
Sergunb 0:8918a71cdbe9 54 #endif
Sergunb 0:8918a71cdbe9 55
Sergunb 0:8918a71cdbe9 56 //Default lease time, in seconds
Sergunb 0:8918a71cdbe9 57 #ifndef DHCP_SERVER_DEFAULT_LEASE_TIME
Sergunb 0:8918a71cdbe9 58 #define DHCP_SERVER_DEFAULT_LEASE_TIME 86400
Sergunb 0:8918a71cdbe9 59 #elif (DHCP_SERVER_DEFAULT_LEASE_TIME < 1)
Sergunb 0:8918a71cdbe9 60 #error DHCP_SERVER_DEFAULT_LEASE_TIME parameter is not valid
Sergunb 0:8918a71cdbe9 61 #endif
Sergunb 0:8918a71cdbe9 62
Sergunb 0:8918a71cdbe9 63 //Maximum number of DNS servers
Sergunb 0:8918a71cdbe9 64 #ifndef DHCP_SERVER_MAX_DNS_SERVERS
Sergunb 0:8918a71cdbe9 65 #define DHCP_SERVER_MAX_DNS_SERVERS 2
Sergunb 0:8918a71cdbe9 66 #elif (DHCP_SERVER_MAX_DNS_SERVERS < 1)
Sergunb 0:8918a71cdbe9 67 #error DHCP_SERVER_MAX_DNS_SERVERS parameter is not valid
Sergunb 0:8918a71cdbe9 68 #endif
Sergunb 0:8918a71cdbe9 69
Sergunb 0:8918a71cdbe9 70
Sergunb 0:8918a71cdbe9 71 /**
Sergunb 0:8918a71cdbe9 72 * @brief DHCP binding
Sergunb 0:8918a71cdbe9 73 *
Sergunb 0:8918a71cdbe9 74 * A binding is a collection of configuration parameters associated
Sergunb 0:8918a71cdbe9 75 * with a DHCP client
Sergunb 0:8918a71cdbe9 76 *
Sergunb 0:8918a71cdbe9 77 **/
Sergunb 0:8918a71cdbe9 78
Sergunb 0:8918a71cdbe9 79 typedef struct
Sergunb 0:8918a71cdbe9 80 {
Sergunb 0:8918a71cdbe9 81 MacAddr macAddr; ///<Client's MAC address
Sergunb 0:8918a71cdbe9 82 Ipv4Addr ipAddr; ///<Client's IPv4 address
Sergunb 0:8918a71cdbe9 83 bool_t validLease; ///<Valid lease
Sergunb 0:8918a71cdbe9 84 systime_t timestamp; ///<Timestamp
Sergunb 0:8918a71cdbe9 85 } DhcpServerBinding;
Sergunb 0:8918a71cdbe9 86
Sergunb 0:8918a71cdbe9 87
Sergunb 0:8918a71cdbe9 88 /**
Sergunb 0:8918a71cdbe9 89 * @brief DHCP server settings
Sergunb 0:8918a71cdbe9 90 **/
Sergunb 0:8918a71cdbe9 91
Sergunb 0:8918a71cdbe9 92 typedef struct
Sergunb 0:8918a71cdbe9 93 {
Sergunb 0:8918a71cdbe9 94 NetInterface *interface; ///<Underlying network interface
Sergunb 0:8918a71cdbe9 95 bool_t rapidCommit; ///<Quick configuration using rapid commit
Sergunb 0:8918a71cdbe9 96 uint32_t leaseTime; ///<Lease time, in seconds, assigned to the DHCP clients
Sergunb 0:8918a71cdbe9 97 Ipv4Addr ipAddrRangeMin; ///<Lowest IP address in the pool that is available for dynamic address assignment
Sergunb 0:8918a71cdbe9 98 Ipv4Addr ipAddrRangeMax; ///<Highest IP address in the pool that is available for dynamic address assignment
Sergunb 0:8918a71cdbe9 99 Ipv4Addr subnetMask; ///<Subnet mask
Sergunb 0:8918a71cdbe9 100 Ipv4Addr defaultGateway; ///<Default gateway
Sergunb 0:8918a71cdbe9 101 Ipv4Addr dnsServer[DHCP_SERVER_MAX_DNS_SERVERS]; ///<DNS servers
Sergunb 0:8918a71cdbe9 102 } DhcpServerSettings;
Sergunb 0:8918a71cdbe9 103
Sergunb 0:8918a71cdbe9 104
Sergunb 0:8918a71cdbe9 105 /**
Sergunb 0:8918a71cdbe9 106 * @brief DHCP server context
Sergunb 0:8918a71cdbe9 107 **/
Sergunb 0:8918a71cdbe9 108
Sergunb 0:8918a71cdbe9 109 typedef struct
Sergunb 0:8918a71cdbe9 110 {
Sergunb 0:8918a71cdbe9 111 DhcpServerSettings settings; ///<DHCP server settings
Sergunb 0:8918a71cdbe9 112 bool_t running; ///<This flag tells whether the DHCP server is running or not
Sergunb 0:8918a71cdbe9 113 Ipv4Addr nextIpAddr; ///<Next IP address to be assigned
Sergunb 0:8918a71cdbe9 114 DhcpServerBinding clientBinding[DHCP_SERVER_MAX_CLIENTS]; ///<List of bindings
Sergunb 0:8918a71cdbe9 115 } DhcpServerContext;
Sergunb 0:8918a71cdbe9 116
Sergunb 0:8918a71cdbe9 117
Sergunb 0:8918a71cdbe9 118 //Tick counter to handle periodic operations
Sergunb 0:8918a71cdbe9 119 extern systime_t dhcpServerTickCounter;
Sergunb 0:8918a71cdbe9 120
Sergunb 0:8918a71cdbe9 121 //DHCP server related functions
Sergunb 0:8918a71cdbe9 122 void dhcpServerGetDefaultSettings(DhcpServerSettings *settings);
Sergunb 0:8918a71cdbe9 123 error_t dhcpServerInit(DhcpServerContext *context, const DhcpServerSettings *settings);
Sergunb 0:8918a71cdbe9 124 error_t dhcpServerStart(DhcpServerContext *context);
Sergunb 0:8918a71cdbe9 125 error_t dhcpServerStop(DhcpServerContext *context);
Sergunb 0:8918a71cdbe9 126
Sergunb 0:8918a71cdbe9 127 void dhcpServerTick(DhcpServerContext *context);
Sergunb 0:8918a71cdbe9 128
Sergunb 0:8918a71cdbe9 129 void dhcpServerProcessMessage(NetInterface *interface,
Sergunb 0:8918a71cdbe9 130 const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader,
Sergunb 0:8918a71cdbe9 131 const NetBuffer *buffer, size_t offset, void *params);
Sergunb 0:8918a71cdbe9 132
Sergunb 0:8918a71cdbe9 133 void dhcpServerParseDiscover(DhcpServerContext *context,
Sergunb 0:8918a71cdbe9 134 const DhcpMessage *message, size_t length);
Sergunb 0:8918a71cdbe9 135
Sergunb 0:8918a71cdbe9 136 void dhcpServerParseRequest(DhcpServerContext *context,
Sergunb 0:8918a71cdbe9 137 const DhcpMessage *message, size_t length);
Sergunb 0:8918a71cdbe9 138
Sergunb 0:8918a71cdbe9 139 void dhcpServerParseDecline(DhcpServerContext *context,
Sergunb 0:8918a71cdbe9 140 const DhcpMessage *message, size_t length);
Sergunb 0:8918a71cdbe9 141
Sergunb 0:8918a71cdbe9 142 void dhcpServerParseRelease(DhcpServerContext *context,
Sergunb 0:8918a71cdbe9 143 const DhcpMessage *message, size_t length);
Sergunb 0:8918a71cdbe9 144
Sergunb 0:8918a71cdbe9 145 void dhcpServerParseInform(DhcpServerContext *context,
Sergunb 0:8918a71cdbe9 146 const DhcpMessage *message, size_t length);
Sergunb 0:8918a71cdbe9 147
Sergunb 0:8918a71cdbe9 148 error_t dhcpServerSendReply(DhcpServerContext *context, uint8_t type,
Sergunb 0:8918a71cdbe9 149 Ipv4Addr yourIpAddr, const DhcpMessage *request, size_t length);
Sergunb 0:8918a71cdbe9 150
Sergunb 0:8918a71cdbe9 151 DhcpServerBinding *dhcpServerCreateBinding(DhcpServerContext *context);
Sergunb 0:8918a71cdbe9 152
Sergunb 0:8918a71cdbe9 153 DhcpServerBinding *dhcpServerFindBindingByMacAddr(DhcpServerContext *context,
Sergunb 0:8918a71cdbe9 154 const MacAddr* macAddr);
Sergunb 0:8918a71cdbe9 155
Sergunb 0:8918a71cdbe9 156 DhcpServerBinding *dhcpServerFindBindingByIpAddr(DhcpServerContext *context,
Sergunb 0:8918a71cdbe9 157 Ipv4Addr ipAddr);
Sergunb 0:8918a71cdbe9 158
Sergunb 0:8918a71cdbe9 159 error_t dhcpServerGetNextIpAddr(DhcpServerContext *context, Ipv4Addr *ipAddr);
Sergunb 0:8918a71cdbe9 160
Sergunb 0:8918a71cdbe9 161 #endif
Sergunb 0:8918a71cdbe9 162