MDIO added

MDIO Folder Added
This commit is contained in:
James YS Kim
2018-05-28 17:05:15 +09:00
parent 2166370f1d
commit 1c6b068fa0
19 changed files with 1947 additions and 1469 deletions

View File

@ -1,3 +1,16 @@
/*******************************************************************************************************************************************************
* Copyright <20><>I 2016 <WIZnet Co.,Ltd.>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the <20><><EFBFBD><EFBFBD>Software<72><65><EFBFBD><EFBFBD>),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED <20><><EFBFBD><EFBFBD>AS IS<49><53><EFBFBD><EFBFBD>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************************************************************************/
//*****************************************************************************
//
//! \file dhcp.c
@ -49,7 +62,6 @@
//
//*****************************************************************************
#include "socket.h"
#include "dhcp.h"
/* If you want to display debug & procssing message, Define _DHCP_DEBUG_ in dhcp.h */
@ -112,7 +124,7 @@ enum
cookieServer = 8,
lprServer = 9,
impressServer = 10,
resourceLocationServer = 11,
resourceLocationServer = 11,
hostName = 12,
bootFileSize = 13,
meritDumpFile = 14,
@ -146,7 +158,7 @@ enum
ntpServers = 42,
vendorSpecificInfo = 43,
netBIOSnameServer = 44,
netBIOSdgramDistServer = 45,
netBIOSdgramDistServer = 45,
netBIOSnodeType = 46,
netBIOSscope = 47,
xFontServer = 48,
@ -214,7 +226,7 @@ RIP_MSG* pDHCPMSG; // Buffer pointer for DHCP processing
uint8_t HOST_NAME[] = DCHP_HOST_NAME;
uint8_t DHCP_CHADDR[6]; // DHCP Client MAC address.
uint8_t DHCP_CHADDR[6] = {0, }; // DHCP Client MAC address.
/* The default callback function */
void default_ip_assign(void);
@ -291,10 +303,11 @@ void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_co
/* make the common DHCP message */
void makeDHCPMSG(void)
{
uint8_t bk_mac[6];
uint8_t* ptmp;
uint8_t i;
getSHAR(bk_mac);
//uint8_t bk_mac[6];
uint8_t* ptmp;
uint8_t i;
//getSHAR(bk_mac);
pDHCPMSG->op = DHCP_BOOTREQUEST;
pDHCPMSG->htype = DHCP_HTYPE10MB;
pDHCPMSG->hlen = DHCP_HLENETHERNET;
@ -302,7 +315,7 @@ void makeDHCPMSG(void)
ptmp = (uint8_t*)(&pDHCPMSG->xid);
*(ptmp+0) = (uint8_t)((DHCP_XID & 0xFF000000) >> 24);
*(ptmp+1) = (uint8_t)((DHCP_XID & 0x00FF0000) >> 16);
*(ptmp+2) = (uint8_t)((DHCP_XID & 0x0000FF00) >> 8);
*(ptmp+2) = (uint8_t)((DHCP_XID & 0x0000FF00) >> 8);
*(ptmp+3) = (uint8_t)((DHCP_XID & 0x000000FF) >> 0);
pDHCPMSG->secs = DHCP_SECS;
ptmp = (uint8_t*)(&pDHCPMSG->flags);
@ -353,11 +366,15 @@ void send_DHCP_DISCOVER(void)
uint16_t i;
uint8_t ip[4];
uint16_t k = 0;
makeDHCPMSG();
#ifdef _DHCP_DEBUG_
int32_t ret = 0;
#endif
makeDHCPMSG();
k = 4; // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
k = 4; // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
// Option Request Param
pDHCPMSG->OPT[k++] = dhcpMessageType;
pDHCPMSG->OPT[k++] = 0x01;
@ -406,7 +423,13 @@ void send_DHCP_DISCOVER(void)
printf("> Send DHCP_DISCOVER\r\n");
#endif
#ifdef _DHCP_DEBUG_
ret = sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
printf("> %d, %d\r\n", ret, RIP_MSG_SIZE);
#else
sendto(DHCP_SOCKET, (uint8_t *)pDHCPMSG, RIP_MSG_SIZE, ip, DHCP_SERVER_PORT);
#endif
}
/* SEND DHCP REQUEST */
@ -675,7 +698,7 @@ uint8_t DHCP_run(void)
if(dhcp_state == STATE_DHCP_STOP) return DHCP_STOPPED;
if(getSn_SR(DHCP_SOCKET) != SOCK_UDP)
socket(DHCP_SOCKET, Sn_MR_UDP, DHCP_CLIENT_PORT, 0x00);
socket(DHCP_SOCKET, Sn_MR_UDP, DHCP_CLIENT_PORT, 0x00);
ret = DHCP_RUNNING;
type = parseDHCPMSG();
@ -710,11 +733,10 @@ uint8_t DHCP_run(void)
#ifdef _DHCP_DEBUG_
printf("> Receive DHCP_ACK\r\n");
#endif
if (check_DHCP_leasedIP()) {
if (check_DHCP_leasedIP()) {
// Network info assignment from DHCP
dhcp_ip_assign();
reset_DHCP_timeout();
dhcp_state = STATE_DHCP_LEASED;
} else {
// IP address conflict occurred
@ -729,7 +751,6 @@ uint8_t DHCP_run(void)
#endif
reset_DHCP_timeout();
dhcp_state = STATE_DHCP_DISCOVER;
} else ret = check_DHCP_timeout();
break;
@ -769,14 +790,13 @@ uint8_t DHCP_run(void)
{
ret = DHCP_IP_CHANGED;
dhcp_ip_update();
#ifdef _DHCP_DEBUG_
printf(">IP changed.\r\n");
#endif
#ifdef _DHCP_DEBUG_
printf("> IP changed\r\n");
#endif
}
#ifdef _DHCP_DEBUG_
else printf(">IP is continued.\r\n");
#endif
#ifdef _DHCP_DEBUG_
else printf("> IP is continued\r\n");
#endif
reset_DHCP_timeout();
dhcp_state = STATE_DHCP_LEASED;
} else if (type == DHCP_NAK) {
@ -797,10 +817,10 @@ uint8_t DHCP_run(void)
return ret;
}
void DHCP_stop(void)
void DHCP_stop(void)
{
close(DHCP_SOCKET);
dhcp_state = STATE_DHCP_STOP;
close(DHCP_SOCKET);
dhcp_state = STATE_DHCP_STOP;
}
uint8_t check_DHCP_timeout(void)
@ -867,13 +887,13 @@ int8_t check_DHCP_leasedIP(void)
// IP conflict detection : ARP request - ARP reply
// Broadcasting ARP Request for check the IP conflict using UDP sendto() function
//printf("%d %d %d %d\r\n", DHCP_allocated_ip[0], DHCP_allocated_ip[1], DHCP_allocated_ip[2], DHCP_allocated_ip[3]);
ret = sendto(DHCP_SOCKET, (uint8_t *)"CHECK_IP_CONFLICT", 17, DHCP_allocated_ip, 5000);
// RCR value restore
setRCR(tmp);
if(ret == SOCKERR_TIMEOUT) {
// UDP send Timeout occurred : allocated IP address is unique, DHCP Success
// UDP send Timeout occurred : allocated IP address is unique, DHCP Success
#ifdef _DHCP_DEBUG_
printf("\r\n> Check leased IP - OK\r\n");
@ -885,7 +905,7 @@ int8_t check_DHCP_leasedIP(void)
send_DHCP_DECLINE();
ret = dhcp_tick_1s;
while((dhcp_tick_1s - ret) < 2) ; // wait for 1s over; wait to complete to send DECLINE message;
while((dhcp_tick_1s - ret) < 2); // wait for 1s over; wait to complete to send DECLINE message;
return 0;
}
@ -893,24 +913,35 @@ int8_t check_DHCP_leasedIP(void)
void DHCP_init(uint8_t s, uint8_t * buf)
{
uint8_t zeroip[4] = {0,0,0,0};
getSHAR(DHCP_CHADDR);
if((DHCP_CHADDR[0] | DHCP_CHADDR[1] | DHCP_CHADDR[2] | DHCP_CHADDR[3] | DHCP_CHADDR[4] | DHCP_CHADDR[5]) == 0x00)
{
// assing temporary mac address, you should be set SHAR before call this function.
DHCP_CHADDR[0] = 0x00;
DHCP_CHADDR[1] = 0x08;
DHCP_CHADDR[2] = 0xdc;
DHCP_CHADDR[3] = 0x00;
DHCP_CHADDR[4] = 0x00;
DHCP_CHADDR[5] = 0x00;
setSHAR(DHCP_CHADDR);
}
uint8_t zeroip[4] = {0,0,0,0};
getSHAR(DHCP_CHADDR);
if((DHCP_CHADDR[0] | DHCP_CHADDR[1] | DHCP_CHADDR[2] | DHCP_CHADDR[3] | DHCP_CHADDR[4] | DHCP_CHADDR[5]) == 0x00)
{
// assing temporary mac address, you should be set SHAR before call this function.
DHCP_CHADDR[0] = 0x00;
DHCP_CHADDR[1] = 0x08;
DHCP_CHADDR[2] = 0xdc;
DHCP_CHADDR[3] = 0x00;
DHCP_CHADDR[4] = 0x00;
DHCP_CHADDR[5] = 0x00;
setSHAR(DHCP_CHADDR);
}
DHCP_SOCKET = s; // SOCK_DHCP
pDHCPMSG = (RIP_MSG*)buf;
DHCP_XID = 0x12345678;
// ## 20160428 Added by Eric, Each of the devices have to has a different XID.
//DHCP_XID += (DHCP_CHADDR[3] + DHCP_CHADDR[4] + DHCP_CHADDR[5]);
{
DHCP_XID += DHCP_CHADDR[3];
DHCP_XID += DHCP_CHADDR[4];
DHCP_XID += DHCP_CHADDR[5];
DHCP_XID += (DHCP_CHADDR[3] ^ DHCP_CHADDR[4] ^ DHCP_CHADDR[5]);
}
// WIZchip Netinfo Clear
setSIPR(zeroip);
setSIPR(zeroip);
@ -938,7 +969,7 @@ void getIPfromDHCP(uint8_t* ip)
{
ip[0] = DHCP_allocated_ip[0];
ip[1] = DHCP_allocated_ip[1];
ip[2] = DHCP_allocated_ip[2];
ip[2] = DHCP_allocated_ip[2];
ip[3] = DHCP_allocated_ip[3];
}
@ -947,23 +978,23 @@ void getGWfromDHCP(uint8_t* ip)
ip[0] =DHCP_allocated_gw[0];
ip[1] =DHCP_allocated_gw[1];
ip[2] =DHCP_allocated_gw[2];
ip[3] =DHCP_allocated_gw[3];
ip[3] =DHCP_allocated_gw[3];
}
void getSNfromDHCP(uint8_t* ip)
{
ip[0] = DHCP_allocated_sn[0];
ip[1] = DHCP_allocated_sn[1];
ip[2] = DHCP_allocated_sn[2];
ip[3] = DHCP_allocated_sn[3];
ip[0] = DHCP_allocated_sn[0];
ip[1] = DHCP_allocated_sn[1];
ip[2] = DHCP_allocated_sn[2];
ip[3] = DHCP_allocated_sn[3];
}
void getDNSfromDHCP(uint8_t* ip)
{
ip[0] = DHCP_allocated_dns[0];
ip[1] = DHCP_allocated_dns[1];
ip[2] = DHCP_allocated_dns[2];
ip[3] = DHCP_allocated_dns[3];
ip[0] = DHCP_allocated_dns[0];
ip[1] = DHCP_allocated_dns[1];
ip[2] = DHCP_allocated_dns[2];
ip[3] = DHCP_allocated_dns[3];
}
uint32_t getDHCPLeasetime(void)

View File

@ -44,7 +44,9 @@
//*****************************************************************************
#ifndef _DHCP_H_
#define _DHCP_H_
#include <stdint.h>
#include "socket.h"
#include "W7500x_wztoe.h"
/*
* @brief
* @details If you want to display debug & procssing message, Define _DHCP_DEBUG_
@ -55,7 +57,7 @@
/* Retry to processing DHCP */
#define MAX_DHCP_RETRY 2 ///< Maxium retry count
#define DHCP_WAIT_TIME 10 ///< Wait Time 10s
#define DHCP_WAIT_TIME 5 ///< Wait Time 10s
/* UDP port numbers for DHCP */

View File

@ -1,3 +1,16 @@
/*******************************************************************************************************************************************************
* Copyright <20><>I 2016 <WIZnet Co.,Ltd.>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the <20><><EFBFBD><EFBFBD>Software<72><65><EFBFBD><EFBFBD>),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED <20><><EFBFBD><EFBFBD>AS IS<49><53><EFBFBD><EFBFBD>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************************************************************************/
//*****************************************************************************
//
//! \file dns.c
@ -339,7 +352,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
uint8_t * cp;
msg = pbuf;
memset(pdhdr, 0, sizeof(pdhdr));
memset(pdhdr, 0, sizeof(*pdhdr));
pdhdr->id = get16(&msg[0]);
tmp = get16(&msg[2]);
@ -366,7 +379,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
for (i = 0; i < pdhdr->qdcount; i++)
{
cp = dns_question(msg, cp);
#ifdef _DNS_DEUBG_
#ifdef _DNS_DEBUG_
printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h"
#endif
if(!cp) return -1;
@ -376,7 +389,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
for (i = 0; i < pdhdr->ancount; i++)
{
cp = dns_answer(msg, cp, ip_from_dns);
#ifdef _DNS_DEUBG_
#ifdef _DNS_DEBUG_
printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h"
#endif
if(!cp) return -1;
@ -523,10 +536,10 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
{
if (len > MAX_DNS_BUF_SIZE) len = MAX_DNS_BUF_SIZE;
len = recvfrom(DNS_SOCKET, pDNSMSG, len, ip, &port);
#ifdef _DNS_DEBUG_
printf("> Receive DNS message from %d.%d.%d.%d(%d). len = %d\r\n", ip[0], ip[1], ip[2], ip[3],port,len);
#endif
ret = parseDNSMSG(&dhp, pDNSMSG, ip_from_dns);
#ifdef _DNS_DEBUG_
printf("> Receive DNS message from %d.%d.%d.%d(%d). len = %d\r\n", ip[0], ip[1], ip[2], ip[3],port,len);
#endif
ret = parseDNSMSG(&dhp, pDNSMSG, ip_from_dns);
break;
}
// Check Timeout

View File

@ -1,3 +1,16 @@
/*******************************************************************************************************************************************************
* Copyright <20><>I 2016 <WIZnet Co.,Ltd.>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the <20><><EFBFBD><EFBFBD>Software<72><65><EFBFBD><EFBFBD>),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED <20><><EFBFBD><EFBFBD>AS IS<49><53><EFBFBD><EFBFBD>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************************************************************************/
//*****************************************************************************
//
//! \file dns.h
@ -52,6 +65,7 @@
#define _DNS_H_
#include <stdint.h>
#include "W7500x_wztoe.h"
/*
* @brief Define it for Debug & Monitor DNS processing.
* @note If defined, it dependens on <stdio.h>
@ -64,7 +78,7 @@
* @todo SHOULD BE defined it equal as or greater than your Domain name lenght + null character(1)
* @note SHOULD BE careful to stack overflow because it is allocated 1.5 times as MAX_DOMAIN_NAME in stack.
*/
#define MAX_DOMAIN_NAME 16 // for example "www.google.com"
#define MAX_DOMAIN_NAME 50 // for example "www.google.com"
#define MAX_DNS_RETRY 2 ///< Requery Count
#define DNS_WAIT_TIME 3 ///< Wait response time. unit 1s.

View File

@ -1,3 +1,16 @@
/*******************************************************************************************************************************************************
* Copyright <20><>I 2016 <WIZnet Co.,Ltd.>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the <20><><EFBFBD><EFBFBD>Software<72><65><EFBFBD><EFBFBD>),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED <20><><EFBFBD><EFBFBD>AS IS<49><53><EFBFBD><EFBFBD>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************************************************************************/
/**
@file httpd.c
@brief functions associated http processing
@ -8,6 +21,7 @@
#include "socket.h"
#include "httpParser.h"
/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/

View File

@ -1,3 +1,16 @@
/*******************************************************************************************************************************************************
* Copyright <20><>I 2016 <WIZnet Co.,Ltd.>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the <20><><EFBFBD><EFBFBD>Software<72><65><EFBFBD><EFBFBD>),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED <20><><EFBFBD><EFBFBD>AS IS<49><53><EFBFBD><EFBFBD>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************************************************************************/
/**
@file httpd.h
@brief Define Constants and fucntions associated with HTTP protocol.
@ -5,6 +18,7 @@
#include <stdint.h>
#ifndef __HTTPPARSER_H__
#define __HTTPPARSER_H__

View File

@ -1,3 +1,16 @@
/*******************************************************************************************************************************************************
* Copyright <20><>I 2016 <WIZnet Co.,Ltd.>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the <20><><EFBFBD><EFBFBD>Software<72><65><EFBFBD><EFBFBD>),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED <20><><EFBFBD><EFBFBD>AS IS<49><53><EFBFBD><EFBFBD>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@ -9,6 +22,7 @@
#include "httpParser.h"
#include "httpUtil.h"
#ifdef _USE_SDCARD_
#include "ff.h" // header file for FatFs library (FAT file system)
#endif
@ -354,13 +368,13 @@ static void send_http_response_body(uint8_t s, uint8_t * uri_name, uint8_t * buf
#endif
}
#ifdef _USE_FLASH_
if(HTTPSock_Status[get_seqnum]->storage_type == DATAFLASH) addr = start_addr;
if(HTTPSock_Status[get_seqnum].storage_type == DATAFLASH) addr = start_addr;
#endif
}
else // remained parts
{
#ifdef _USE_FLASH_
if(HTTPSock_Status[get_seqnum]->storage_type == DATAFLASH)
if(HTTPSock_Status[get_seqnum].storage_type == DATAFLASH)
{
addr = HTTPSock_Status[get_seqnum].file_start + HTTPSock_Status[get_seqnum].file_offset;
}
@ -417,7 +431,7 @@ static void send_http_response_body(uint8_t s, uint8_t * uri_name, uint8_t * buf
#endif
#ifdef _USE_FLASH_
else if(HTTPSock_Status[get_seqnum]->storage_type == DATAFLASH)
else if(HTTPSock_Status[get_seqnum].storage_type == DATAFLASH)
{
// Data read from external data flash memory
read_from_flashbuf(addr, &buf[0], send_len);
@ -544,6 +558,9 @@ static void http_process_handler(uint8_t s, st_http_request * p_http_request)
// Find the User registered index for web content
if(find_userReg_webContent(uri_buf, &content_num, &file_len))
{
content_found = 1; // Web content found in code flash memory
content_addr = (uint32_t)content_num;
HTTPSock_Status[get_seqnum].storage_type = CODEFLASH;
@ -567,6 +584,7 @@ static void http_process_handler(uint8_t s, st_http_request * p_http_request)
content_found = 1;
HTTPSock_Status[get_seqnum]->storage_type = DATAFLASH;
; // To do
printf("file len : %d\r\n", file_len);
}
#endif
else
@ -675,7 +693,11 @@ void reg_httpServer_webContent(uint8_t * content_name, uint8_t * content)
name_len = strlen((char *)content_name);
content_len = strlen((char *)content);
web_content[total_content_cnt].content_name = malloc(name_len+1);
//web_content[total_content_cnt].content_name = malloc(name_len+1);
strcpy((char *)web_content[total_content_cnt].content_name, (const char *)content_name);
web_content[total_content_cnt].content_len = content_len;
web_content[total_content_cnt].content = content;

View File

@ -1,9 +1,23 @@
/*******************************************************************************************************************************************************
* Copyright <20><>I 2016 <WIZnet Co.,Ltd.>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the <20><><EFBFBD><EFBFBD>Software<72><65><EFBFBD><EFBFBD>),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED <20><><EFBFBD><EFBFBD>AS IS<49><53><EFBFBD><EFBFBD>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************************************************************************/
/**
@file httpServer.h
@brief Define constants and functions related HTTP Web server.
*/
#include <stdint.h>
#include "W7500x_wztoe.h"
#ifndef __HTTPSERVER_H__
#define __HTTPSERVER_H__
@ -78,7 +92,7 @@ typedef struct _st_http_socket
typedef struct _httpServer_webContent
{
uint8_t * content_name;
uint8_t content_name[20];
uint32_t content_len;
uint8_t * content;
}httpServer_webContent;

View File

@ -1,3 +1,16 @@
/*******************************************************************************************************************************************************
* Copyright <20><>I 2016 <WIZnet Co.,Ltd.>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the <20><><EFBFBD><EFBFBD>Software<72><65><EFBFBD><EFBFBD>),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED <20><><EFBFBD><EFBFBD>AS IS<49><53><EFBFBD><EFBFBD>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************************************************************************/
/**
* @file httpUtil.c
* @brief HTTP Server Utilities
@ -12,13 +25,17 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "W7500x_gpio.h"
#include "httpServer.h"
#include "httpParser.h"
#include "httpUtil.h"
#include "wizchip_conf.h"
uint8_t http_get_cgi_handler(uint8_t * uri_name, uint8_t * buf, uint32_t * file_len)
{
uint8_t ret = HTTP_OK;
uint16_t len = 0;
if(predefined_get_cgi_processor(uri_name, buf, &len))
{
;
@ -43,7 +60,7 @@ uint8_t http_post_cgi_handler(uint8_t * uri_name, st_http_request * p_http_reque
uint8_t ret = HTTP_OK;
uint16_t len = 0;
uint8_t val = 0;
if(predefined_set_cgi_processor(uri_name, p_http_request->URI, buf, &len))
{
;
@ -63,3 +80,140 @@ uint8_t http_post_cgi_handler(uint8_t * uri_name, st_http_request * p_http_reque
if(ret) *file_len = len;
return ret;
}
uint8_t predefined_get_cgi_processor(uint8_t * uri_name, uint8_t * buf, uint16_t * len)
{
uint8_t ret = 1; // ret = 1 means 'uri_name' matched
uint8_t cgibuf[14] = {0, };
int8_t cgi_dio = -1;
int8_t cgi_ain = -1;
uint8_t i;
if(strcmp((const char *)uri_name, "todo.cgi") == 0)
{
// to do
;//make_json_todo(buf, len);
}
else if(strcmp((const char *)uri_name, "get_netinfo.cgi") == 0)
{
make_json_netinfo(buf, len);
}
else
{
;
}
return ret;
}
uint8_t predefined_set_cgi_processor(uint8_t * uri_name, uint8_t * uri, uint8_t * buf, uint16_t * len)
{
uint8_t ret = 1; // ret = '1' means 'uri_name' matched
uint8_t val = 0;
if(strcmp((const char *)uri_name, "todo.cgi") == 0)
{
// to do
;//val = todo(uri);
//*len = sprintf((char *)buf, "%d", val);
}
// Digital I/O; dio_s, dio_d
else if(strcmp((const char *)uri_name, "set_LED.cgi") == 0)
{
val = set_LED(uri);
*len = sprintf((char *)buf, "%d", val);
}
else
{
ret = 0;
}
return ret;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Pre-defined Get CGI functions
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Example of make_jason function */
//void make_json_dio(uint8_t * buf, uint16_t * len, uint8_t pin)
//{
// uint8_t pin_state = Chip_GPIO_GetPinState(LPC_GPIO, dio_ports[pin], dio_pins[pin]);
// uint8_t pin_dir = Chip_GPIO_GetPinDIR(LPC_GPIO, dio_ports[pin], dio_pins[pin]);
// *len = sprintf((char *)buf, "DioCallback({\"dio_p\":\"%d\",\
// \"dio_s\":\"%d\",\
// \"dio_d\":\"%d\"\
// });",
// pin, // Digital io pin number
// pin_state, // Digital io status
// pin_dir // Digital io directions
// );
//}
void make_json_netinfo(uint8_t * buf, uint16_t * len)
{
wiz_NetInfo netinfo;
ctlnetwork(CN_GET_NETINFO, (void*) &netinfo);
// DHCP: 1 - Static, 2 - DHCP
*len = sprintf((char *)buf, "NetinfoCallback({\"mac\":\"%.2X:%.2X:%.2X:%.2X:%.2X:%.2X\",\
\"ip\":\"%d.%d.%d.%d\",\
\"gw\":\"%d.%d.%d.%d\",\
\"sn\":\"%d.%d.%d.%d\",\
\"dns\":\"%d.%d.%d.%d\",\
\"dhcp\":\"%d\"\
});",
netinfo.mac[0], netinfo.mac[1], netinfo.mac[2], netinfo.mac[3], netinfo.mac[4], netinfo.mac[5],
netinfo.ip[0], netinfo.ip[1], netinfo.ip[2], netinfo.ip[3],
netinfo.gw[0], netinfo.gw[1], netinfo.gw[2], netinfo.gw[3],
netinfo.sn[0], netinfo.sn[1], netinfo.sn[2], netinfo.sn[3],
netinfo.dns[0], netinfo.dns[1], netinfo.dns[2], netinfo.dns[3],
netinfo.dhcp
);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Pre-defined Set CGI functions
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int8_t set_LED(uint8_t * uri)
{
uint8_t * param;
uint8_t pin = 0, val = 0;
if((param = get_http_param_value((char *)uri, "pin"))) // GPIO; D0 ~ D15
{
pin = (uint8_t)ATOI(param, 10);
if(pin > 15) return -1;
if((param = get_http_param_value((char *)uri, "val"))) // State; high(off)/low(on)
{
val = (uint8_t)ATOI(param, 10);
}
if(pin == RED)
{
if(val == 0) GPIO_ResetBits(GPIOC, GPIO_Pin_0); // Low(On)
else GPIO_SetBits(GPIOC, GPIO_Pin_0);// High(off)
}
else if(pin == GREEN)
{
if(val == 0) GPIO_ResetBits(GPIOC, GPIO_Pin_4); // Low(On)
else GPIO_SetBits(GPIOC, GPIO_Pin_4);// High(off)
}
else if(pin == BLUE)
{
if(val == 0) GPIO_ResetBits(GPIOC, GPIO_Pin_5); // Low(On)
else GPIO_SetBits(GPIOC, GPIO_Pin_5);// High(off)
}
}
return pin;
}

View File

@ -1,3 +1,16 @@
/*******************************************************************************************************************************************************
* Copyright <20><>I 2016 <WIZnet Co.,Ltd.>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the <20><><EFBFBD><EFBFBD>Software<72><65><EFBFBD><EFBFBD>),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED <20><><EFBFBD><EFBFBD>AS IS<49><53><EFBFBD><EFBFBD>, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************************************************************************/
/**
* @file httpUtil.h
* @brief Header File for HTTP Server Utilities
@ -12,13 +25,27 @@
#ifndef __HTTPUTIL_H__
#define __HTTPUTIL_H__
#include "httpServer.h"
#include "httpParser.h"
#define RED 0
#define GREEN 4
#define BLUE 5
uint8_t http_get_cgi_handler(uint8_t * uri_name, uint8_t * buf, uint32_t * file_len);
uint8_t http_post_cgi_handler(uint8_t * uri_name, st_http_request * p_http_request, uint8_t * buf, uint32_t * file_len);
uint8_t predefined_get_cgi_processor(uint8_t * uri_name, uint8_t * buf, uint16_t * len);
uint8_t predefined_set_cgi_processor(uint8_t * uri_name, uint8_t * uri, uint8_t * buf, uint16_t * len);
// Pre-defined Get CGI functions
void make_json_netinfo(uint8_t * buf, uint16_t * len);
//void make_json_LEDR(uint8_t * buf, uint16_t * len);
// Pre-defined Set CGI functions
//int8_t set_diodir(uint8_t * uri);
//int8_t set_diostate(uint8_t * uri);
int8_t set_LED(uint8_t * uri);
#endif

File diff suppressed because one or more lines are too long