forked from mfulz_github/qmk_firmware
Clean up Webserver project - add more Doxygen documentation for the new DHCP client functions and defines.
This commit is contained in:
parent
a960e4b3b2
commit
cec699ac59
|
@ -88,7 +88,7 @@
|
|||
|
||||
/** Sends a byte to the currently addressed device on the TWI bus.
|
||||
*
|
||||
* \param Byte Byte to send to the currently addressed device
|
||||
* \param[in] Byte Byte to send to the currently addressed device
|
||||
*
|
||||
* \return Boolean true if the recipient ACKed the byte, false otherwise
|
||||
*/
|
||||
|
@ -103,8 +103,8 @@
|
|||
|
||||
/** Receives a byte from the currently addressed device on the TWI bus.
|
||||
*
|
||||
* \param Byte Location where the read byte is to be stored
|
||||
* \param LastByte Indicates if the byte should be ACKed if false, NAKed if true
|
||||
* \param[in] Byte Location where the read byte is to be stored
|
||||
* \param[in] LastByte Indicates if the byte should be ACKed if false, NAKed if true
|
||||
*
|
||||
* \return Boolean true if the byte reception sucessfully completed, false otherwise
|
||||
*/
|
||||
|
@ -125,7 +125,7 @@
|
|||
/* Function Prototypes: */
|
||||
/** Begins a master mode TWI bus communication with the given slave device address.
|
||||
*
|
||||
* \param SlaveAddress Address of the slave TWI device to communicate with
|
||||
* \param[in] SlaveAddress Address of the slave TWI device to communicate with
|
||||
*
|
||||
* \return Boolean true if the device is ready for data, false otherwise
|
||||
*/
|
||||
|
|
|
@ -51,7 +51,7 @@ static void TINYNVM_SendPointerAddress(const uint16_t AbsoluteAddress)
|
|||
|
||||
/** Sends a SIN command to the target with the specified I/O address, ready for the data byte to be written.
|
||||
*
|
||||
* \param Address 6-bit I/O address to write to in the target's I/O memory space
|
||||
* \param[in] Address 6-bit I/O address to write to in the target's I/O memory space
|
||||
*/
|
||||
static void TINYNVM_SendReadNVMRegister(uint8_t Address)
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ static void TINYNVM_SendReadNVMRegister(uint8_t Address)
|
|||
|
||||
/** Sends a SOUT command to the target with the specified I/O address, ready for the data byte to be read.
|
||||
*
|
||||
* \param Address 6-bit I/O address to read from in the target's I/O memory space
|
||||
* \param[in] Address 6-bit I/O address to read from in the target's I/O memory space
|
||||
*/
|
||||
static void TINYNVM_SendWriteNVMRegister(uint8_t Address)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
#include "DHCPApp.h"
|
||||
|
||||
#if defined(ENABLE_DHCP)
|
||||
#if defined(ENABLE_DHCP) || defined(__DOXYGEN__)
|
||||
/** Timer for managing the timeout period for a DHCP server to respond */
|
||||
struct timer DHCPTimer;
|
||||
|
||||
|
@ -90,10 +90,10 @@ void DHCPApp_Callback(void)
|
|||
|
||||
/* Reset the timeout timer, progress to next state */
|
||||
timer_reset(&DHCPTimer);
|
||||
AppState->CurrentState = DHCP_STATE_WaitForResponse;
|
||||
AppState->CurrentState = DHCP_STATE_WaitForOffer;
|
||||
|
||||
break;
|
||||
case DHCP_STATE_WaitForResponse:
|
||||
case DHCP_STATE_WaitForOffer:
|
||||
if (!(uip_newdata()))
|
||||
{
|
||||
/* Check if the DHCP timeout period has expired while waiting for a response */
|
||||
|
@ -166,6 +166,15 @@ void DHCPApp_Callback(void)
|
|||
}
|
||||
}
|
||||
|
||||
/** Fills the DHCP packet response with the appropriate BOOTP header for DHCP. This fills out all the required
|
||||
* fields, leaving only the additional DHCP options to be added to the packet before it is sent to the DHCP server.
|
||||
*
|
||||
* \param[out] DHCPHeader Location in the packet buffer where the BOOTP header should be written to
|
||||
* \param[in] DHCPMessageType DHCP Message type, such as DHCP_DISCOVER
|
||||
* \param[in] AppState Application state of the current UDP connection
|
||||
*
|
||||
* \return Size in bytes of the created DHCP packet
|
||||
*/
|
||||
uint16_t DHCPApp_FillDHCPHeader(DHCP_Header_t* DHCPHeader, uint8_t DHCPMessageType, uip_udp_appstate_t* AppState)
|
||||
{
|
||||
/* Erase existing packet data so that we start will all 0x00 DHCP header data */
|
||||
|
@ -195,7 +204,17 @@ uint16_t DHCPApp_FillDHCPHeader(DHCP_Header_t* DHCPHeader, uint8_t DHCPMessageTy
|
|||
return (sizeof(DHCP_Header_t) + 4);
|
||||
}
|
||||
|
||||
uint8_t DHCPApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataLen, void* Source)
|
||||
/** Sets the given DHCP option in the DHCP packet's option list. This automatically moves the
|
||||
* end of options terminator past the new option in the options list.
|
||||
*
|
||||
* \param[in,out] DHCPOptionList Pointer to the start of the DHCP packet's options list
|
||||
* \param[in] Option DHCP option to add to the list
|
||||
* \param[in] DataLen Size in bytes of the option data to add
|
||||
* \param[in] OptionData Buffer where the option's data is to be sourced from
|
||||
*
|
||||
* \return Number of bytes added to the DHCP packet
|
||||
*/
|
||||
uint8_t DHCPApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataLen, void* OptionData)
|
||||
{
|
||||
/* Skip through the DHCP options list until the terminator option is found */
|
||||
while (*DHCPOptionList != DHCP_OPTION_END)
|
||||
|
@ -204,13 +223,21 @@ uint8_t DHCPApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataL
|
|||
/* Overwrite the existing terminator with the new option, add a new terminator at the end of the list */
|
||||
DHCPOptionList[0] = Option;
|
||||
DHCPOptionList[1] = DataLen;
|
||||
memcpy(&DHCPOptionList[2], Source, DataLen);
|
||||
memcpy(&DHCPOptionList[2], OptionData, DataLen);
|
||||
DHCPOptionList[2 + DataLen] = DHCP_OPTION_END;
|
||||
|
||||
/* Calculate the total number of bytes added to the outgoing packet */
|
||||
return (2 + DataLen);
|
||||
}
|
||||
|
||||
/** Retrieves the given option's data (if present) from the DHCP packet's options list.
|
||||
*
|
||||
* \param[in,out] DHCPOptionList Pointer to the start of the DHCP packet's options list
|
||||
* \param[in] Option DHCP option to retrieve to the list
|
||||
* \param[out] Destination Buffer where the option's data is to be written to if found
|
||||
*
|
||||
* \return Boolean true if the option was found in the DHCP packet's options list, false otherwise
|
||||
*/
|
||||
bool DHCPApp_GetOption(uint8_t* DHCPOptionList, uint8_t Option, void* Destination)
|
||||
{
|
||||
/* Look through the incomming DHCP packet's options list for the requested option */
|
||||
|
@ -233,5 +260,4 @@ bool DHCPApp_GetOption(uint8_t* DHCPOptionList, uint8_t Option, void* Destinatio
|
|||
/* Requested option not found in the incomming packet's DHCP options list */
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -44,36 +44,76 @@
|
|||
#include "../Webserver.h"
|
||||
|
||||
/* Macros: */
|
||||
/** UDP listen port for a BOOTP server */
|
||||
#define DHCPC_SERVER_PORT 67
|
||||
|
||||
/** UDP listen port for a BOOTP client */
|
||||
#define DHCPC_CLIENT_PORT 68
|
||||
|
||||
/** BOOTP message type for a BOOTP REQUEST message */
|
||||
#define DHCP_OP_BOOTREQUEST 0x01
|
||||
|
||||
/** BOOTP message type for a BOOTP REPLY message */
|
||||
#define DHCP_OP_BOOTREPLY 0x02
|
||||
|
||||
/** BOOTP flag for a BOOTP broadcast message */
|
||||
#define BOOTP_BROADCAST 0x8000
|
||||
|
||||
/** Magic DHCP cookie for a BOOTP message to identify it as a DHCP message */
|
||||
#define DHCP_MAGIC_COOKIE 0x63538263
|
||||
|
||||
/** Unique transaction ID used to identify DHCP responses to the client */
|
||||
#define DHCP_TRANSACTION_ID 0x13245466
|
||||
|
||||
/** DHCP message type for a DISCOVER message */
|
||||
#define DHCP_DISCOVER 1
|
||||
|
||||
/** DHCP message type for an OFFER message */
|
||||
#define DHCP_OFFER 2
|
||||
|
||||
/** DHCP message type for a REQUEST message */
|
||||
#define DHCP_REQUEST 3
|
||||
|
||||
/** DHCP message type for a DECLINE message */
|
||||
#define DHCP_DECLINE 4
|
||||
|
||||
/** DHCP message type for an ACK message */
|
||||
#define DHCP_ACK 5
|
||||
|
||||
/** DHCP message type for a NAK message */
|
||||
#define DHCP_NAK 6
|
||||
|
||||
/** DHCP message type for a RELEASE message */
|
||||
#define DHCP_RELEASE 7
|
||||
|
||||
/** DHCP medium type for standard Ethernet */
|
||||
#define DHCP_HTYPE_ETHERNET 1
|
||||
|
||||
/** DHCP message option for the network subnet mask */
|
||||
#define DHCP_OPTION_SUBNET_MASK 1
|
||||
|
||||
/** DHCP message option for the network gateway IP */
|
||||
#define DHCP_OPTION_ROUTER 3
|
||||
|
||||
/** DHCP message option for the network DNS server */
|
||||
#define DHCP_OPTION_DNS_SERVER 6
|
||||
|
||||
/** DHCP message option for the requested client IP address */
|
||||
#define DHCP_OPTION_REQ_IPADDR 50
|
||||
|
||||
/** DHCP message option for the IP address lease time */
|
||||
#define DHCP_OPTION_LEASE_TIME 51
|
||||
|
||||
/** DHCP message option for the DHCP message type */
|
||||
#define DHCP_OPTION_MSG_TYPE 53
|
||||
|
||||
/** DHCP message option for the DHCP server IP */
|
||||
#define DHCP_OPTION_SERVER_ID 54
|
||||
|
||||
/** DHCP message option for the list of required options from the server */
|
||||
#define DHCP_OPTION_REQ_LIST 55
|
||||
|
||||
/** DHCP message option for the options list terminator */
|
||||
#define DHCP_OPTION_END 255
|
||||
|
||||
/* Type Defines: */
|
||||
|
@ -105,13 +145,14 @@
|
|||
} DHCP_Header_t;
|
||||
|
||||
/* Enums: */
|
||||
/** States for each DHCP connection to a DHCP client. */
|
||||
enum DHCP_States_t
|
||||
{
|
||||
DHCP_STATE_SendDiscover,
|
||||
DHCP_STATE_WaitForResponse,
|
||||
DHCP_STATE_SendRequest,
|
||||
DHCP_STATE_WaitForACK,
|
||||
DHCP_STATE_AddressLeased,
|
||||
DHCP_STATE_SendDiscover, /**< Send DISCOVER packet to retrieve DHCP lease offers */
|
||||
DHCP_STATE_WaitForOffer, /**< Waiting for OFFER packet giving available DHCP leases */
|
||||
DHCP_STATE_SendRequest, /**< Send REQUEST packet to request a DHCP lease */
|
||||
DHCP_STATE_WaitForACK, /**< Wait for ACK packet to complete the DHCP lease */
|
||||
DHCP_STATE_AddressLeased, /**< DHCP address has been leased from a DHCP server */
|
||||
};
|
||||
|
||||
/* Function Prototypes: */
|
||||
|
@ -119,7 +160,7 @@
|
|||
void DHCPApp_Callback(void);
|
||||
|
||||
uint16_t DHCPApp_FillDHCPHeader(DHCP_Header_t* DHCPHeader, uint8_t DHCPMessageType, uip_udp_appstate_t* AppState);
|
||||
uint8_t DHCPApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataLen, void* Source);
|
||||
uint8_t DHCPApp_SetOption(uint8_t* DHCPOptionList, uint8_t Option, uint8_t DataLen, void* OptionData);
|
||||
bool DHCPApp_GetOption(uint8_t* DHCPOptionList, uint8_t Option, void* Destination);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -45,14 +45,16 @@
|
|||
#include <uip.h>
|
||||
|
||||
/* Enums: */
|
||||
/** States for each HTTP connection to the webserver. */
|
||||
enum Webserver_States_t
|
||||
{
|
||||
WEBSERVER_STATE_SendHeaders,
|
||||
WEBSERVER_STATE_SendData,
|
||||
WEBSERVER_STATE_Closed,
|
||||
WEBSERVER_STATE_SendHeaders, /**< Currently sending HTTP headers to the client */
|
||||
WEBSERVER_STATE_SendData, /**< Currently sending HTTP page data to the client */
|
||||
WEBSERVER_STATE_Closed, /**< Connection closed after all data sent */
|
||||
};
|
||||
|
||||
/* Macros: */
|
||||
/** TCP listen port for incomming HTTP traffic */
|
||||
#define HTTP_SERVER_PORT 80
|
||||
|
||||
/* Function Prototypes: */
|
||||
|
|
|
@ -113,6 +113,12 @@ typedef unsigned short uip_stats_t;
|
|||
*/
|
||||
#define UIP_CONF_UDP_CONNS 1
|
||||
|
||||
/**
|
||||
* Host identifier define (e.g. MAC address). If defined as 0,
|
||||
* this will use the internal MAC ethernet address define.
|
||||
*/
|
||||
#define UIP_NEIGHBOR_CONF_ADDRTYPE 0
|
||||
|
||||
//Include app configuration
|
||||
#include "apps-conf.h"
|
||||
|
||||
|
|
|
@ -149,6 +149,7 @@ int main(void)
|
|||
}
|
||||
}
|
||||
|
||||
/** Processes incomming packets to the server from the connected RNDIS device, creating responses as needed. */
|
||||
void ProcessIncommingPacket(void)
|
||||
{
|
||||
if (RNDIS_Host_IsPacketReceived(&Ethernet_RNDIS_Interface))
|
||||
|
@ -194,6 +195,7 @@ void ProcessIncommingPacket(void)
|
|||
}
|
||||
}
|
||||
|
||||
/** Manages the currently open network connections, including TCP and (if enabled) UDP. */
|
||||
void ManageConnections(void)
|
||||
{
|
||||
/* Manage open connections */
|
||||
|
|
Loading…
Reference in New Issue