Compare commits
65 Commits
W5500_PHY_
...
addApplica
Author | SHA1 | Date | |
---|---|---|---|
84f4b6d030 | |||
587d26e341 | |||
47dec417fa | |||
af704a0d23 | |||
863973b22e | |||
b58bfbdbc8 | |||
dacf22ca48 | |||
3016459cc9 | |||
890a73fb8b | |||
7dd9ef0c2a | |||
fe116b361b | |||
40dc8d1f1e | |||
16657be394 | |||
c166849712 | |||
81e94dcc22 | |||
dd053614b5 | |||
798d505bff | |||
dac948e885 | |||
c2356c8777 | |||
c5be3a85b9 | |||
ca5348784f | |||
4b2cd30cb8 | |||
435cedca91 | |||
f3a575c8b4 | |||
4de4aa0816 | |||
dc10163277 | |||
b135a73a94 | |||
db469a1dc7 | |||
b70a532f8d | |||
21f6528af2 | |||
c2940b08bf | |||
cafc29ecee | |||
d1f87bd19f | |||
8dde2af871 | |||
6676770d63 | |||
bac969f04e | |||
2163c8b29c | |||
183daf143d | |||
c69d27b875 | |||
28e8a16b54 | |||
a832944757 | |||
72d9df579b | |||
3939dc4925 | |||
15b79ef7c0 | |||
b8e3c63cff | |||
8ebd860b08 | |||
aaaf41eff1 | |||
433f4bb409 | |||
18c878db9c | |||
e20beebfc2 | |||
7bac9a1f99 | |||
74bf44ddc0 | |||
879b8a1828 | |||
01d6b321bc | |||
1c6b068fa0 | |||
2166370f1d | |||
556bee8d4a | |||
a8b1f0a05c | |||
640eb5a863 | |||
e3855b86e8 | |||
81d0d9d981 | |||
d96daf13f0 | |||
47b6ea8bf7 | |||
4ddea28229 | |||
fdeac309b6 |
@ -1,6 +1,10 @@
|
||||
#ifndef _LOOPBACK_H_
|
||||
#define _LOOPBACK_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Loopback test debug message printout enable */
|
||||
@ -27,4 +31,8 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
|
||||
/* UDP Loopback test example */
|
||||
int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
113
Application/multicast/multicast.c
Normal file
113
Application/multicast/multicast.c
Normal file
@ -0,0 +1,113 @@
|
||||
#include "multicast.h"
|
||||
#include <stdio.h>
|
||||
#include "socket.h"
|
||||
#include "wizchip_conf.h"
|
||||
|
||||
|
||||
int32_t multicast_loopback(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port)
|
||||
{
|
||||
int32_t ret;
|
||||
uint16_t size, sentsize;
|
||||
uint8_t destip[4];
|
||||
uint16_t destport, port=3000;
|
||||
|
||||
switch(getSn_SR(sn))
|
||||
{
|
||||
case SOCK_UDP :
|
||||
if((size = getSn_RX_RSR(sn)) > 0)
|
||||
{
|
||||
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
|
||||
ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport);
|
||||
if(ret <= 0)
|
||||
{
|
||||
#ifdef _MULTICAST_DEBUG_
|
||||
printf("%d: recvfrom error. %ld\r\n",sn,ret);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
size = (uint16_t) ret;
|
||||
sentsize = 0;
|
||||
while(sentsize != size)
|
||||
{
|
||||
ret = sendto(sn, buf+sentsize, size-sentsize, destip, destport);
|
||||
if(ret < 0)
|
||||
{
|
||||
#ifdef _MULTICAST_DEBUG_
|
||||
printf("%d: sendto error. %ld\r\n",sn,ret);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case SOCK_CLOSED:
|
||||
#ifdef _MULTICAST_DEBUG_
|
||||
printf("%d:Multicast Loopback start\r\n",sn);
|
||||
#endif
|
||||
setSn_DIPR(0, multicast_ip);
|
||||
setSn_DPORT(0, multicast_port);
|
||||
if((ret = socket(sn, Sn_MR_UDP, port, Sn_MR_MULTI)) != sn)
|
||||
return ret;
|
||||
#ifdef _MULTICAST_DEBUG_
|
||||
printf("%d:Opened, UDP Multicast Socket\r\n", sn);
|
||||
printf("%d:Multicast Group IP - %d.%d.%d.%d\r\n", sn, multicast_ip[0], multicast_ip[1], multicast_ip[2], multicast_ip[3]);
|
||||
printf("%d:Multicast Group Port - %d\r\n", sn, multicast_port);
|
||||
#endif
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t multicast_recv(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port)
|
||||
{
|
||||
int32_t ret;
|
||||
uint16_t size, port=3000;
|
||||
uint8_t destip[4];
|
||||
uint16_t destport;
|
||||
|
||||
switch(getSn_SR(sn))
|
||||
{
|
||||
case SOCK_UDP :
|
||||
if((size = getSn_RX_RSR(sn)) > 0)
|
||||
{
|
||||
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
|
||||
ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport);
|
||||
if(ret <= 0)
|
||||
{
|
||||
#ifdef _MULTICAST_DEBUG_
|
||||
printf("%d: recvfrom error. %ld\r\n",sn,ret);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
size = (uint16_t) ret;
|
||||
#ifdef _MULTICAST_DEBUG_
|
||||
printf("\r\nrecv size : %d\r\n", size);
|
||||
for(int i=0; i<size; i++)
|
||||
printf("%c", buf[i]);
|
||||
printf("\r\n");
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case SOCK_CLOSED:
|
||||
#ifdef _MULTICAST_DEBUG_
|
||||
printf("%d:Multicast Recv start\r\n",sn);
|
||||
#endif
|
||||
setSn_DIPR(sn, multicast_ip);
|
||||
setSn_DPORT(sn, multicast_port);
|
||||
if((ret = socket(sn, Sn_MR_UDP, port, Sn_MR_MULTI)) != sn)
|
||||
return ret;
|
||||
#ifdef _MULTICAST_DEBUG_
|
||||
printf("%d:Opened, UDP Multicast Socket\r\n", sn);
|
||||
printf("%d:Multicast Group IP - %d.%d.%d.%d\r\n", sn, multicast_ip[0], multicast_ip[1], multicast_ip[2], multicast_ip[3]);
|
||||
printf("%d:Multicast Group Port - %d\r\n", sn, multicast_port);
|
||||
#endif
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
28
Application/multicast/multicast.h
Normal file
28
Application/multicast/multicast.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef _MULTICAST_H_
|
||||
#define _MULTICAST_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Multicast test debug message printout enable */
|
||||
#define _MULTICAST_DEBUG_
|
||||
|
||||
#ifndef DATA_BUF_SIZE
|
||||
#define DATA_BUF_SIZE 2048
|
||||
#endif
|
||||
|
||||
/* UDP Multicast Loopback test example */
|
||||
int32_t multicast_loopback(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port);
|
||||
|
||||
/* UDP Multicast Recv test example */
|
||||
int32_t multicast_recv(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -40,6 +40,11 @@
|
||||
|
||||
#ifndef _W5100_H_
|
||||
#define _W5100_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "wizchip_conf.h"
|
||||
|
||||
@ -1850,6 +1855,10 @@ void wiz_recv_ignore(uint8_t sn, uint16_t len);
|
||||
#endif
|
||||
/// @endcond
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_W5100_H_
|
||||
|
||||
|
||||
|
@ -42,6 +42,10 @@
|
||||
#ifndef _W5100S_H_
|
||||
#define _W5100S_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "wizchip_conf.h"
|
||||
|
||||
@ -975,7 +979,7 @@
|
||||
* @brief Address Auto-Increment in Indirect Bus Interface
|
||||
* @details 0 : Disable auto-increment \n
|
||||
* 1 : Enable auto-incremente \n
|
||||
* At the Indirect Bus Interface mode, if this bit is set as 占쎌쥙猷욑옙占쏙옙醫롫짗占쏙옙 the address will
|
||||
* At the Indirect Bus Interface mode, if this bit is set as the address will
|
||||
* be automatically increased by 1 whenever read and write are performed.
|
||||
*/
|
||||
#define MR_AI 0x02 ///< auto-increment in indirect mode
|
||||
@ -984,7 +988,7 @@
|
||||
* @brief Indirect Bus Interface mode
|
||||
* @details 0 : Disable Indirect bus Interface mode \n
|
||||
* 1 : Enable Indirect bus Interface mode \n
|
||||
* If this bit is set as 占쎌쥙猷욑옙占쏙옙醫롫짗占쏙옙 Indirect Bus Interface mode is set.
|
||||
* If this bit is set as Indirect Bus Interface mode is set.
|
||||
*/
|
||||
#define MR_IND 0x01 ///< enable indirect mode
|
||||
|
||||
@ -2928,9 +2932,8 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
|
||||
* @sa getSn_RXMEM_SIZE()
|
||||
*/
|
||||
#define setSn_RXMEM_SIZE(sn, rxmemsize) \
|
||||
WIZCHIP_WRITE(Sn_RXBUF_SIZE(sn),rxmemsize)
|
||||
#define setSn_RXBUF_SIZE(sn,rxmemsize) setSn_RXMEM_SIZE(sn,rxmemsize)
|
||||
|
||||
WIZCHIP_WRITE(RMSR, (WIZCHIP_READ(RMSR) & ~(0x03 << (2*sn))) | (rxmemsize << (2*sn)))
|
||||
#define setSn_RXBUF_SIZE(sn,rxmemsize) setSn_RXMEM_SIZE(sn,rxmemsize)
|
||||
/**
|
||||
* @ingroup Socket_register_access_function_W5100S
|
||||
* @brief Get @ref Sn_RXMEM_SIZE register
|
||||
@ -2939,7 +2942,7 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
|
||||
* @sa setSn_RXMEM_SIZE()
|
||||
*/
|
||||
#define getSn_RXMEM_SIZE(sn) \
|
||||
WIZCHIP_READ(Sn_RXBUF_SIZE(sn))
|
||||
((WIZCHIP_READ(RMSR) & (0x03 << (2*sn))) >> (2*sn))
|
||||
#define getSn_RXBUF_SIZE(sn) getSn_RXMEM_SIZE(sn)
|
||||
|
||||
/**
|
||||
@ -2950,7 +2953,7 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
|
||||
* @sa getSn_TXMEM_SIZE()
|
||||
*/
|
||||
#define setSn_TXMEM_SIZE(sn, txmemsize) \
|
||||
WIZCHIP_WRITE(Sn_TXBUF_SIZE(sn),txmemsize)
|
||||
WIZCHIP_WRITE(TMSR, (WIZCHIP_READ(TMSR) & ~(0x03 << (2*sn))) | (txmemsize << (2*sn)))
|
||||
#define setSn_TXBUF_SIZE(sn, txmemsize) setSn_TXMEM_SIZE(sn,txmemsize)
|
||||
|
||||
/**
|
||||
@ -2961,7 +2964,7 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len);
|
||||
* @sa setSn_TXMEM_SIZE()
|
||||
*/
|
||||
#define getSn_TXMEM_SIZE(sn) \
|
||||
WIZCHIP_READ(Sn_TXBUF_SIZE(sn))
|
||||
((WIZCHIP_READ(TMSR) & (0x03 << (2*sn))) >> (2*sn))
|
||||
#define getSn_TXBUF_SIZE(sn) getSn_TXMEM_SIZE(sn)
|
||||
|
||||
/**
|
||||
@ -3084,7 +3087,7 @@ uint16_t getSn_RX_RSR(uint8_t sn);
|
||||
* @return uint16_t. Max buffer size
|
||||
*/
|
||||
#define getSn_RxMAX(sn) \
|
||||
((uint16_t)(getSn_RXMEM_SIZE(sn)) << 10)
|
||||
((uint16_t)(0x0001 << getSn_RXMEM_SIZE(sn)) << 10)
|
||||
|
||||
|
||||
/**
|
||||
@ -3094,7 +3097,7 @@ uint16_t getSn_RX_RSR(uint8_t sn);
|
||||
* @return uint16_t. Max buffer size
|
||||
*/
|
||||
#define getSn_TxMAX(sn) \
|
||||
((uint16_t)(getSn_TXMEM_SIZE(sn)) << 10)
|
||||
((uint16_t)(0x0001 << getSn_TXMEM_SIZE(sn)) << 10)
|
||||
|
||||
/**
|
||||
* @ingroup Socket_register_access_function_W5100S
|
||||
@ -3310,6 +3313,10 @@ void wiz_delay_ms(uint32_t ms);
|
||||
#endif
|
||||
/// @endcond
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_W5100S_H_
|
||||
|
||||
|
||||
|
@ -40,6 +40,11 @@
|
||||
|
||||
#ifndef _W5200_H
|
||||
#define _W5200_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "wizchip_conf.h"
|
||||
|
||||
@ -2095,6 +2100,10 @@ void wiz_recv_ignore(uint8_t sn, uint16_t len);
|
||||
#endif
|
||||
/// \endcond
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_W5200_H_
|
||||
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
#ifndef _W5300_H_
|
||||
#define _W5300_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
//! \file w5300.h
|
||||
@ -900,16 +905,16 @@
|
||||
|
||||
|
||||
/************************************/
|
||||
/* The bit of IR regsiter defintion */
|
||||
/* The bit of IR regsiter definition */
|
||||
/************************************/
|
||||
#define IR_IPCF (1 << 15) /**< IP conflict bit of \ref IR. To clear, Write the bit to '1'. */
|
||||
#define IR_DPUR (1 << 14) /**< Destination port unreachable bit of \ref IR. To clear, Write the bit to '1'. */
|
||||
#define IR_PPPT (1 << 13) /**< PPPoE terminate bit of \ref IR. To clear, Write the bit to '1'. */
|
||||
#define IR_FMTU (1 << 12) /**< Fragment MTU bit of IR. To clear, Write the bit to '1'. */
|
||||
#define IR_IPCF (1 << 7) /**< IP conflict bit of \ref IR. To clear, Write the bit to '1'. */
|
||||
#define IR_DPUR (1 << 6) /**< Destination port unreachable bit of \ref IR. To clear, Write the bit to '1'. */
|
||||
#define IR_PPPT (1 << 5) /**< PPPoE terminate bit of \ref IR. To clear, Write the bit to '1'. */
|
||||
#define IR_FMTU (1 << 4) /**< Fragment MTU bit of IR. To clear, Write the bit to '1'. */
|
||||
#define IR_SnINT(n) (0x01 << n) /**< SOCKETn interrupt occurrence bit of \ref IR. To clear, Clear \ref Sn_IR*/
|
||||
|
||||
/*****************************************/
|
||||
/* The bit of Pn_BRDYR regsiter defintion*/
|
||||
/* The bit of Pn_BRDYR regsiter definition*/
|
||||
/*****************************************/
|
||||
#define Pn_PEN (1 << 7) /**< PIN 'BRDYn' enable bit of Pn_BRDYR. */
|
||||
#define Pn_MT (1 << 6) /**< PIN memory type bit of Pn_BRDYR. */
|
||||
@ -918,7 +923,7 @@
|
||||
|
||||
|
||||
/***************************************/
|
||||
/* The bit of Sn_MR regsiter defintion */
|
||||
/* The bit of Sn_MR regsiter definition */
|
||||
/***************************************/
|
||||
/**
|
||||
* @brief Alignment bit of \ref Sn_MR.
|
||||
@ -1015,7 +1020,7 @@
|
||||
|
||||
|
||||
/******************************/
|
||||
/* The values of CR defintion */
|
||||
/* The values of CR definition */
|
||||
/******************************/
|
||||
/**
|
||||
* @brief Initialize or open a socket
|
||||
@ -1115,7 +1120,7 @@
|
||||
|
||||
|
||||
/*********************************/
|
||||
/* The values of Sn_IR defintion */
|
||||
/* The values of Sn_IR definition */
|
||||
/*********************************/
|
||||
#define Sn_IR_PRECV 0x80 /**< It is set in the case that option data which is not supported is received. Refer to \ref Sn_IR */
|
||||
#define Sn_IR_PFAIL 0x40 /**< It is set in the case that PAP authentication is failed. Refer to \ref Sn_IR */
|
||||
@ -1127,7 +1132,7 @@
|
||||
#define Sn_IR_CON 0x01 /**< It is set one time when the connection is successful and then @ref Sn_SR is changed to @ref SOCK_ESTABLISHED. */
|
||||
|
||||
/**********************************/
|
||||
/* The values of Sn_SSR defintion */
|
||||
/* The values of Sn_SSR definition */
|
||||
/**********************************/
|
||||
/**
|
||||
* @brief The state of SOCKET intialized or closed
|
||||
@ -1988,7 +1993,7 @@ uint8_t getRMSR(uint8_t sn);
|
||||
* @return uint16_t. Variable of @ref Sn_PORTR.
|
||||
* @sa setSn_PORTR()
|
||||
*/
|
||||
#define getSn_PORTR(sn, port) \
|
||||
#define getSn_PORTR(sn) \
|
||||
WIZCHIP_READ(Sn_PORTR(sn))
|
||||
#define getSn_PORT(sn) getSn_PORTR(sn) ///< For compatible ioLibrary
|
||||
|
||||
@ -2120,7 +2125,7 @@ uint8_t getRMSR(uint8_t sn);
|
||||
* @sa getSn_PROTOR()
|
||||
*/
|
||||
#define setSn_PROTOR(sn, proto) \
|
||||
WIZCHIP_WRITE(Sn_PROTOR(sn),(WIZCHIP_READ(Sn_PROTOR(sn) & 0xFF00) | (((uint16_t)proto) & 0x00FF))
|
||||
WIZCHIP_WRITE(Sn_PROTOR(sn),(WIZCHIP_READ(Sn_PROTOR(sn)) & 0xFF00) | (((uint16_t)proto) & 0x00FF))
|
||||
#define setSn_PROTO(sn,proto) setSn_PROTOR(sn,proto) ///< For compatible ioLibrary
|
||||
|
||||
/**
|
||||
@ -2242,7 +2247,7 @@ uint32_t getSn_RX_RSR(uint8_t sn);
|
||||
* @sa getSn_FRAGR()
|
||||
*/
|
||||
#define setSn_FRAGR(sn, frag) \
|
||||
WIZCHIP_WRITE(Sn_FRAGR(sn), (uint16_t)(frag >>8))
|
||||
WIZCHIP_WRITE(Sn_FRAGR(sn), ((uint16_t)frag) & 0x00FF)
|
||||
#define setSn_FRAG(sn,frag) setSn_FRAGR(sn,flag)
|
||||
|
||||
/**
|
||||
@ -2253,7 +2258,7 @@ uint32_t getSn_RX_RSR(uint8_t sn);
|
||||
* @sa setSn_FRAGR()
|
||||
*/
|
||||
#define getSn_FRAGR(sn) \
|
||||
(WIZCHIP_READ(Sn_FRAG(sn)) << 8)
|
||||
(WIZCHIP_READ(Sn_FRAG(sn)))
|
||||
#define getSn_FRAG(sn) getSn_FRAGR(sn)
|
||||
|
||||
|
||||
@ -2324,4 +2329,8 @@ void wiz_recv_ignore(uint8_t sn, uint32_t len);
|
||||
#endif
|
||||
/// \endcond
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _W5300_H_
|
||||
|
@ -48,6 +48,10 @@
|
||||
#ifndef _W5500_H_
|
||||
#define _W5500_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "wizchip_conf.h"
|
||||
|
||||
@ -2152,4 +2156,8 @@ void wiz_recv_ignore(uint8_t sn, uint16_t len);
|
||||
#endif
|
||||
/// @endcond
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _W5500_H_
|
||||
|
@ -517,11 +517,11 @@ int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t
|
||||
//}
|
||||
//
|
||||
//if(*((uint32_t*)addr) == 0) return SOCKERR_IPINVALID;
|
||||
if((taddr == 0) && (getSn_MR(sn)&Sn_MR_MACRAW != Sn_MR_MACRAW)) return SOCKERR_IPINVALID;
|
||||
if((port == 0) && (getSn_MR(sn)&Sn_MR_MACRAW != Sn_MR_MACRAW)) return SOCKERR_PORTZERO;
|
||||
if((taddr == 0) && ((getSn_MR(sn)&Sn_MR_MACRAW) != Sn_MR_MACRAW)) return SOCKERR_IPINVALID;
|
||||
if((port == 0) && ((getSn_MR(sn)&Sn_MR_MACRAW) != Sn_MR_MACRAW)) return SOCKERR_PORTZERO;
|
||||
tmp = getSn_SR(sn);
|
||||
//#if ( _WIZCHIP_ < 5200 )
|
||||
if(tmp != SOCK_MACRAW && tmp != SOCK_UDP && tmp != SOCK_IPRAW) return SOCKERR_SOCKSTATUS;
|
||||
if((tmp != SOCK_MACRAW) && (tmp != SOCK_UDP) && (tmp != SOCK_IPRAW)) return SOCKERR_SOCKSTATUS;
|
||||
//#else
|
||||
// if(tmp != SOCK_MACRAW && tmp != SOCK_UDP) return SOCKERR_SOCKSTATUS;
|
||||
//#endif
|
||||
@ -858,7 +858,7 @@ int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg)
|
||||
}
|
||||
}
|
||||
break;
|
||||
#if _WIZCHIP_ > 5200
|
||||
#if !( (_WIZCHIP_ == 5100) || (_WIZCHIP_ == 5200) )
|
||||
case SO_KEEPALIVEAUTO:
|
||||
CHECK_SOCKMODE(Sn_MR_TCP);
|
||||
setSn_KPALVTR(sn,*(uint8_t*)arg);
|
||||
@ -910,7 +910,7 @@ int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg)
|
||||
*(uint8_t*) arg = getSn_SR(sn);
|
||||
break;
|
||||
case SO_REMAINSIZE:
|
||||
if(getSn_MR(sn) == Sn_MR_TCP)
|
||||
if(getSn_MR(sn) & Sn_MR_TCP)
|
||||
*(uint16_t*)arg = getSn_RX_RSR(sn);
|
||||
else
|
||||
*(uint16_t*)arg = sock_remained_size[sn];
|
||||
|
@ -84,6 +84,9 @@
|
||||
*/
|
||||
#ifndef _SOCKET_H_
|
||||
#define _SOCKET_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "wizchip_conf.h"
|
||||
|
||||
@ -387,7 +390,7 @@ typedef enum
|
||||
SO_DESTPORT, ///< Set the destination Port number. @ref Sn_DPORT ( @ref setSn_DPORT(), @ref getSn_DPORT() )
|
||||
#if _WIZCHIP_ != 5100
|
||||
SO_KEEPALIVESEND, ///< Valid only in setsockopt. Manually send keep-alive packet in TCP mode, Not supported in W5100
|
||||
#if _WIZCHIP_ > 5200
|
||||
#if !( (_WIZCHIP_ == 5100) || (_WIZCHIP_ == 5200) )
|
||||
SO_KEEPALIVEAUTO, ///< Set/Get keep-alive auto transmission timer in TCP mode, Not supported in W5100, W5200
|
||||
#endif
|
||||
#endif
|
||||
@ -479,4 +482,8 @@ int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg);
|
||||
*/
|
||||
int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _SOCKET_H_
|
||||
|
@ -163,21 +163,28 @@ _WIZCHIP WIZCHIP =
|
||||
};
|
||||
*/
|
||||
_WIZCHIP WIZCHIP =
|
||||
{
|
||||
_WIZCHIP_IO_MODE_,
|
||||
_WIZCHIP_ID_ ,
|
||||
wizchip_cris_enter,
|
||||
wizchip_cris_exit,
|
||||
wizchip_cs_select,
|
||||
wizchip_cs_deselect,
|
||||
//M20150601 : Rename the function
|
||||
//wizchip_bus_readbyte,
|
||||
//wizchip_bus_writebyte
|
||||
wizchip_bus_readdata,
|
||||
wizchip_bus_writedata,
|
||||
// wizchip_spi_readbyte,
|
||||
// wizchip_spi_writebyte
|
||||
};
|
||||
{
|
||||
_WIZCHIP_IO_MODE_,
|
||||
_WIZCHIP_ID_ ,
|
||||
{
|
||||
wizchip_cris_enter,
|
||||
wizchip_cris_exit
|
||||
},
|
||||
{
|
||||
wizchip_cs_select,
|
||||
wizchip_cs_deselect
|
||||
},
|
||||
{
|
||||
{
|
||||
//M20150601 : Rename the function
|
||||
//wizchip_bus_readbyte,
|
||||
//wizchip_bus_writebyte
|
||||
wizchip_bus_readdata,
|
||||
wizchip_bus_writedata
|
||||
},
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static uint8_t _DNS_[4]; // DNS server ip address
|
||||
@ -411,7 +418,10 @@ void wizchip_sw_reset(void)
|
||||
|
||||
int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
|
||||
{
|
||||
int8_t i,j;
|
||||
int8_t i;
|
||||
#if _WIZCHIP_ < W5200
|
||||
int8_t j;
|
||||
#endif
|
||||
int8_t tmp = 0;
|
||||
wizchip_sw_reset();
|
||||
if(txsize)
|
||||
@ -430,25 +440,27 @@ int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
|
||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||
{
|
||||
tmp += txsize[i];
|
||||
|
||||
#if _WIZCHIP_ < W5200 //2016.10.28 peter add condition for w5100 and w5100s
|
||||
if(tmp > 8) return -1;
|
||||
#else
|
||||
if(tmp > 16) return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||
{
|
||||
#if __WIZCHIP_ < W5200 //2016.10.28 peter add condition for w5100 and w5100s
|
||||
#if _WIZCHIP_ < W5200 //2016.10.28 peter add condition for w5100
|
||||
j = 0;
|
||||
while(txsize[i] >> j != 1){j++;}
|
||||
while((txsize[i] >> j != 1)&&(txsize[i] !=0)){j++;}
|
||||
setSn_TXBUF_SIZE(i, j);
|
||||
#else
|
||||
setSn_TXBUF_SIZE(i, txsize[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
if(rxsize)
|
||||
{
|
||||
tmp = 0;
|
||||
@ -473,12 +485,12 @@ int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
|
||||
|
||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||
{
|
||||
#if __WIZCHIP_ < W5200 //2016.10.28 peter add condition for w5100 and w5100s
|
||||
#if _WIZCHIP_ < W5200 // add condition for w5100
|
||||
j = 0;
|
||||
while(rxsize[i] >> j != 1){j++;}
|
||||
while((rxsize[i] >> j != 1)&&(txsize[i] !=0)){j++;}
|
||||
setSn_RXBUF_SIZE(i, j);
|
||||
#else
|
||||
setSn_RXBUF_SIZE(i, txsize[i]);
|
||||
setSn_RXBUF_SIZE(i, rxsize[i]);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -609,6 +621,7 @@ int8_t wizphy_getphylink(void)
|
||||
#elif _WIZCHIP_ == W5500
|
||||
if(getPHYCFGR() & PHYCFGR_LNK_ON)
|
||||
tmp = PHY_LINK_ON;
|
||||
|
||||
#else
|
||||
tmp = -1;
|
||||
#endif
|
||||
@ -834,7 +847,6 @@ int8_t wizphy_setphypmode(uint8_t pmode)
|
||||
|
||||
void wizchip_setnetinfo(wiz_NetInfo* pnetinfo)
|
||||
{
|
||||
int i,j,k;
|
||||
setSHAR(pnetinfo->mac);
|
||||
setGAR(pnetinfo->gw);
|
||||
setSUBR(pnetinfo->sn);
|
||||
|
@ -54,6 +54,10 @@
|
||||
#ifndef _WIZCHIP_CONF_H_
|
||||
#define _WIZCHIP_CONF_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
/**
|
||||
* @brief Select WIZCHIP.
|
||||
@ -68,7 +72,7 @@
|
||||
#define W5500 5500
|
||||
|
||||
#ifndef _WIZCHIP_
|
||||
#define _WIZCHIP_ W5500 // W5100, W5100S, W5200, W5300, W5500
|
||||
#define _WIZCHIP_ W5100S // W5100, W5100S, W5200, W5300, W5500
|
||||
#endif
|
||||
|
||||
#define _WIZCHIP_IO_MODE_NONE_ 0x0000
|
||||
@ -107,7 +111,7 @@
|
||||
* @brief Define interface mode.
|
||||
* @todo you should select interface mode as chip. Select one of @ref \_WIZCHIP_IO_MODE_SPI_ , @ref \_WIZCHIP_IO_MODE_BUS_DIR_ or @ref \_WIZCHIP_IO_MODE_BUS_INDIR_
|
||||
*/
|
||||
//#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_
|
||||
// #define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_BUS_INDIR_
|
||||
//#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_5500_
|
||||
#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_
|
||||
|
||||
@ -193,8 +197,11 @@
|
||||
* @ref \_WIZCHIP_IO_MODE_BUS_DIR_, @ref \_WIZCHIP_IO_MODE_BUS_INDIR_). \n\n
|
||||
* ex> <code> #define \_WIZCHIP_IO_BASE_ 0x00008000 </code>
|
||||
*/
|
||||
#define _WIZCHIP_IO_BASE_ 0x60000000 // for 5100S IND
|
||||
//#define _WIZCHIP_IO_BASE_ 0x00000000 // for 5100S SPI
|
||||
#if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_
|
||||
#define _WIZCHIP_IO_BASE_ 0x60000000 // for 5100S IND
|
||||
#elif _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SPI_
|
||||
#define _WIZCHIP_IO_BASE_ 0x00000000 // for 5100S SPI
|
||||
#endif
|
||||
|
||||
#ifndef _WIZCHIP_IO_BASE_
|
||||
#define _WIZCHIP_IO_BASE_ 0x00000000 // 0x8000
|
||||
@ -225,7 +232,7 @@
|
||||
typedef struct __WIZCHIP
|
||||
{
|
||||
uint16_t if_mode; ///< host interface mode
|
||||
uint8_t id[6]; ///< @b WIZCHIP ID such as @b 5100, @b 5200, @b 5500, and so on.
|
||||
uint8_t id[7]; ///< @b WIZCHIP ID such as @b 5100, @b 5200, @b 5500, and so on.
|
||||
/**
|
||||
* The set of critical section callback func.
|
||||
*/
|
||||
@ -646,5 +653,8 @@ void wizchip_settimeout(wiz_NetTimeout* nettime);
|
||||
* @param nettime @ref _RTR_ value and @ref _RCR_ value. Refer to @ref wiz_NetTimeout.
|
||||
*/
|
||||
void wizchip_gettimeout(wiz_NetTimeout* nettime);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _WIZCHIP_CONF_H_
|
||||
|
@ -2,10 +2,11 @@
|
||||
//
|
||||
//! \file dhcp.c
|
||||
//! \brief DHCP APIs implement file.
|
||||
//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
|
||||
//! \version 1.1.0
|
||||
//! \date 2013/11/18
|
||||
//! \details Processing DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
|
||||
//! \version 1.1.1
|
||||
//! \date 2019/10/08
|
||||
//! \par Revision history
|
||||
//! <2019/10/08> compare DHCP server ip address
|
||||
//! <2013/11/18> 1st Release
|
||||
//! <2012/12/20> V1.1.0
|
||||
//! 1. Optimize code
|
||||
@ -52,7 +53,7 @@
|
||||
#include "socket.h"
|
||||
#include "dhcp.h"
|
||||
|
||||
/* If you want to display debug & procssing message, Define _DHCP_DEBUG_ in dhcp.h */
|
||||
/* If you want to display debug & processing message, Define _DHCP_DEBUG_ in dhcp.h */
|
||||
|
||||
#ifdef _DHCP_DEBUG_
|
||||
#include <stdio.h>
|
||||
@ -65,7 +66,7 @@
|
||||
#define STATE_DHCP_LEASED 3 ///< ReceiveD ACK and IP leased
|
||||
#define STATE_DHCP_REREQUEST 4 ///< send REQUEST for maintaining leased IP
|
||||
#define STATE_DHCP_RELEASE 5 ///< No use
|
||||
#define STATE_DHCP_STOP 6 ///< Stop procssing DHCP
|
||||
#define STATE_DHCP_STOP 6 ///< Stop processing DHCP
|
||||
|
||||
#define DHCP_FLAGSBROADCAST 0x8000 ///< The broadcast value of flags in @ref RIP_MSG
|
||||
#define DHCP_FLAGSUNICAST 0x0000 ///< The unicast value of flags in @ref RIP_MSG
|
||||
@ -192,6 +193,7 @@ typedef struct {
|
||||
uint8_t DHCP_SOCKET; // Socket number for DHCP
|
||||
|
||||
uint8_t DHCP_SIP[4]; // DHCP Server IP address
|
||||
uint8_t DHCP_REAL_SIP[4]; // For extract my DHCP server in a few DHCP server
|
||||
|
||||
// Network information from DHCP Server
|
||||
uint8_t OLD_allocated_ip[4] = {0, }; // Previous IP address
|
||||
@ -228,6 +230,7 @@ void (*dhcp_ip_conflict)(void) = default_ip_conflict; /* handler to be called
|
||||
|
||||
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
|
||||
|
||||
char NibbleToHex(uint8_t nibble);
|
||||
|
||||
/* send DISCOVER message to DHCP server */
|
||||
void send_DHCP_DISCOVER(void);
|
||||
@ -244,7 +247,7 @@ int8_t check_DHCP_leasedIP(void);
|
||||
/* check the timeout in DHCP process */
|
||||
uint8_t check_DHCP_timeout(void);
|
||||
|
||||
/* Intialize to timeout process. */
|
||||
/* Initialize to timeout process. */
|
||||
void reset_DHCP_timeout(void);
|
||||
|
||||
/* Parse message as OFFER and ACK and NACK from DHCP server.*/
|
||||
@ -258,7 +261,7 @@ void default_ip_assign(void)
|
||||
setGAR (DHCP_allocated_gw);
|
||||
}
|
||||
|
||||
/* The default handler of ip chaged */
|
||||
/* The default handler of ip changed */
|
||||
void default_ip_update(void)
|
||||
{
|
||||
/* WIZchip Software Reset */
|
||||
@ -268,7 +271,7 @@ void default_ip_update(void)
|
||||
setSHAR(DHCP_CHADDR);
|
||||
}
|
||||
|
||||
/* The default handler of ip chaged */
|
||||
/* The default handler of ip changed */
|
||||
void default_ip_conflict(void)
|
||||
{
|
||||
// WIZchip Software Reset
|
||||
@ -355,8 +358,16 @@ void send_DHCP_DISCOVER(void)
|
||||
uint16_t k = 0;
|
||||
|
||||
makeDHCPMSG();
|
||||
DHCP_SIP[0]=0;
|
||||
DHCP_SIP[1]=0;
|
||||
DHCP_SIP[2]=0;
|
||||
DHCP_SIP[3]=0;
|
||||
DHCP_REAL_SIP[0]=0;
|
||||
DHCP_REAL_SIP[1]=0;
|
||||
DHCP_REAL_SIP[2]=0;
|
||||
DHCP_REAL_SIP[3]=0;
|
||||
|
||||
k = 4; // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
|
||||
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
|
||||
|
||||
// Option Request Param
|
||||
pDHCPMSG->OPT[k++] = dhcpMessageType;
|
||||
@ -379,10 +390,13 @@ void send_DHCP_DISCOVER(void)
|
||||
pDHCPMSG->OPT[k++] = 0; // fill zero length of hostname
|
||||
for(i = 0 ; HOST_NAME[i] != 0; i++)
|
||||
pDHCPMSG->OPT[k++] = HOST_NAME[i];
|
||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
|
||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
|
||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
|
||||
pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3] >> 4);
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3]);
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4] >> 4);
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4]);
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5] >> 4);
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5]);
|
||||
pDHCPMSG->OPT[k - (i+6+1)] = i+6; // length of hostname
|
||||
|
||||
pDHCPMSG->OPT[k++] = dhcpParamRequest;
|
||||
pDHCPMSG->OPT[k++] = 0x06; // length of request
|
||||
@ -439,7 +453,7 @@ void send_DHCP_REQUEST(void)
|
||||
ip[3] = 255;
|
||||
}
|
||||
|
||||
k = 4; // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
|
||||
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
|
||||
|
||||
// Option Request Param.
|
||||
pDHCPMSG->OPT[k++] = dhcpMessageType;
|
||||
@ -478,10 +492,13 @@ void send_DHCP_REQUEST(void)
|
||||
pDHCPMSG->OPT[k++] = 0; // length of hostname
|
||||
for(i = 0 ; HOST_NAME[i] != 0; i++)
|
||||
pDHCPMSG->OPT[k++] = HOST_NAME[i];
|
||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
|
||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
|
||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
|
||||
pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3] >> 4);
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3]);
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4] >> 4);
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4]);
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5] >> 4);
|
||||
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[5]);
|
||||
pDHCPMSG->OPT[k - (i+6+1)] = i+6; // length of hostname
|
||||
|
||||
pDHCPMSG->OPT[k++] = dhcpParamRequest;
|
||||
pDHCPMSG->OPT[k++] = 0x08;
|
||||
@ -514,7 +531,7 @@ void send_DHCP_DECLINE(void)
|
||||
|
||||
makeDHCPMSG();
|
||||
|
||||
k = 4; // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
|
||||
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
|
||||
|
||||
*((uint8_t*)(&pDHCPMSG->flags)) = ((DHCP_FLAGSUNICAST & 0xFF00)>> 8);
|
||||
*((uint8_t*)(&pDHCPMSG->flags)+1) = (DHCP_FLAGSUNICAST & 0x00FF);
|
||||
@ -574,7 +591,7 @@ int8_t parseDHCPMSG(void)
|
||||
|
||||
uint8_t * p;
|
||||
uint8_t * e;
|
||||
uint8_t type;
|
||||
uint8_t type = 0;
|
||||
uint8_t opt_len;
|
||||
|
||||
if((len = getSn_RX_RSR(DHCP_SOCKET)) > 0)
|
||||
@ -590,8 +607,23 @@ int8_t parseDHCPMSG(void)
|
||||
if ( (pDHCPMSG->chaddr[0] != DHCP_CHADDR[0]) || (pDHCPMSG->chaddr[1] != DHCP_CHADDR[1]) ||
|
||||
(pDHCPMSG->chaddr[2] != DHCP_CHADDR[2]) || (pDHCPMSG->chaddr[3] != DHCP_CHADDR[3]) ||
|
||||
(pDHCPMSG->chaddr[4] != DHCP_CHADDR[4]) || (pDHCPMSG->chaddr[5] != DHCP_CHADDR[5]) )
|
||||
{
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("No My DHCP Message. This message is ignored.\r\n");
|
||||
#endif
|
||||
return 0;
|
||||
type = 0;
|
||||
}
|
||||
//compare DHCP server ip address
|
||||
if((DHCP_SIP[0]!=0) || (DHCP_SIP[1]!=0) || (DHCP_SIP[2]!=0) || (DHCP_SIP[3]!=0)){
|
||||
if( ((svr_addr[0]!=DHCP_SIP[0])|| (svr_addr[1]!=DHCP_SIP[1])|| (svr_addr[2]!=DHCP_SIP[2])|| (svr_addr[3]!=DHCP_SIP[3])) &&
|
||||
((svr_addr[0]!=DHCP_REAL_SIP[0])|| (svr_addr[1]!=DHCP_REAL_SIP[1])|| (svr_addr[2]!=DHCP_REAL_SIP[2])|| (svr_addr[3]!=DHCP_REAL_SIP[3])) )
|
||||
{
|
||||
#ifdef _DHCP_DEBUG_
|
||||
printf("Another DHCP sever send a response message. This is ignored.\r\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
p = (uint8_t *)(&pDHCPMSG->op);
|
||||
p = p + 240; // 240 = sizeof(RIP_MSG) + MAGIC_COOKIE size in RIP_MSG.opt - sizeof(RIP_MSG.opt)
|
||||
e = p + (len - 240);
|
||||
@ -655,6 +687,10 @@ int8_t parseDHCPMSG(void)
|
||||
DHCP_SIP[1] = *p++;
|
||||
DHCP_SIP[2] = *p++;
|
||||
DHCP_SIP[3] = *p++;
|
||||
DHCP_REAL_SIP[0]=svr_addr[0];
|
||||
DHCP_REAL_SIP[1]=svr_addr[1];
|
||||
DHCP_REAL_SIP[2]=svr_addr[2];
|
||||
DHCP_REAL_SIP[3]=svr_addr[3];
|
||||
break;
|
||||
default :
|
||||
p++;
|
||||
@ -897,7 +933,7 @@ void DHCP_init(uint8_t s, uint8_t * buf)
|
||||
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.
|
||||
// assigning temporary mac address, you should be set SHAR before call this function.
|
||||
DHCP_CHADDR[0] = 0x00;
|
||||
DHCP_CHADDR[1] = 0x08;
|
||||
DHCP_CHADDR[2] = 0xdc;
|
||||
@ -913,7 +949,6 @@ void DHCP_init(uint8_t s, uint8_t * buf)
|
||||
|
||||
// WIZchip Netinfo Clear
|
||||
setSIPR(zeroip);
|
||||
setSIPR(zeroip);
|
||||
setGAR(zeroip);
|
||||
|
||||
reset_DHCP_timeout();
|
||||
@ -921,7 +956,7 @@ void DHCP_init(uint8_t s, uint8_t * buf)
|
||||
}
|
||||
|
||||
|
||||
/* Rset the DHCP timeout count and retry count. */
|
||||
/* Reset the DHCP timeout count and retry count. */
|
||||
void reset_DHCP_timeout(void)
|
||||
{
|
||||
dhcp_tick_1s = 0;
|
||||
@ -971,6 +1006,13 @@ uint32_t getDHCPLeasetime(void)
|
||||
return dhcp_lease_time;
|
||||
}
|
||||
|
||||
|
||||
char NibbleToHex(uint8_t nibble)
|
||||
{
|
||||
nibble &= 0x0F;
|
||||
if (nibble <= 9)
|
||||
return nibble + '0';
|
||||
else
|
||||
return nibble + ('A'-0x0A);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,9 +3,10 @@
|
||||
//! \file dhcp.h
|
||||
//! \brief DHCP APIs Header file.
|
||||
//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
|
||||
//! \version 1.1.0
|
||||
//! \date 2013/11/18
|
||||
//! \version 1.1.1
|
||||
//! \date 2019/10/08
|
||||
//! \par Revision history
|
||||
//! <2019/10/08> compare DHCP server ip address
|
||||
//! <2013/11/18> 1st Release
|
||||
//! <2012/12/20> V1.1.0
|
||||
//! 1. Move unreferenced DEFINE to dhcp.c
|
||||
@ -45,16 +46,20 @@
|
||||
#ifndef _DHCP_H_
|
||||
#define _DHCP_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* @brief
|
||||
* @details If you want to display debug & procssing message, Define _DHCP_DEBUG_
|
||||
* @note If defined, it dependens on <stdio.h>
|
||||
* @details If you want to display debug & processing message, Define _DHCP_DEBUG_
|
||||
* @note If defined, it depends on <stdio.h>
|
||||
*/
|
||||
//#define _DHCP_DEBUG_
|
||||
|
||||
|
||||
/* Retry to processing DHCP */
|
||||
#define MAX_DHCP_RETRY 2 ///< Maxium retry count
|
||||
#define MAX_DHCP_RETRY 2 ///< Maximum retry count
|
||||
#define DHCP_WAIT_TIME 10 ///< Wait Time 10s
|
||||
|
||||
|
||||
@ -63,7 +68,7 @@
|
||||
#define DHCP_CLIENT_PORT 68 ///< DHCP client port number
|
||||
|
||||
|
||||
#define MAGIC_COOKIE 0x63825363 ///< Any number. You can be modifyed it any number
|
||||
#define MAGIC_COOKIE 0x63825363 ///< You should not modify it number.
|
||||
|
||||
#define DCHP_HOST_NAME "WIZnet\0"
|
||||
|
||||
@ -72,18 +77,18 @@
|
||||
*/
|
||||
enum
|
||||
{
|
||||
DHCP_FAILED = 0, ///< Procssing Fail
|
||||
DHCP_RUNNING, ///< Procssing DHCP proctocol
|
||||
DHCP_FAILED = 0, ///< Processing Fail
|
||||
DHCP_RUNNING, ///< Processing DHCP protocol
|
||||
DHCP_IP_ASSIGN, ///< First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign)
|
||||
DHCP_IP_CHANGED, ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
|
||||
DHCP_IP_LEASED, ///< Stand by
|
||||
DHCP_STOPPED ///< Stop procssing DHCP protocol
|
||||
DHCP_STOPPED ///< Stop processing DHCP protocol
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief DHCP client initialization (outside of the main loop)
|
||||
* @param s - socket number
|
||||
* @param buf - buffer for procssing DHCP message
|
||||
* @param buf - buffer for processing DHCP message
|
||||
*/
|
||||
void DHCP_init(uint8_t s, uint8_t * buf);
|
||||
|
||||
@ -97,7 +102,7 @@ void DHCP_time_handler(void);
|
||||
* @brief Register call back function
|
||||
* @param ip_assign - callback func when IP is assigned from DHCP server first
|
||||
* @param ip_update - callback func when IP is changed
|
||||
* @prarm ip_conflict - callback func when the assigned IP is conflict with others.
|
||||
* @param ip_conflict - callback func when the assigned IP is conflict with others.
|
||||
*/
|
||||
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
|
||||
|
||||
@ -116,7 +121,7 @@ void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_co
|
||||
uint8_t DHCP_run(void);
|
||||
|
||||
/*
|
||||
* @brief Stop DHCP procssing
|
||||
* @brief Stop DHCP processing
|
||||
* @note If you want to restart. call DHCP_init() and DHCP_run()
|
||||
*/
|
||||
void DHCP_stop(void);
|
||||
@ -145,8 +150,12 @@ void getDNSfromDHCP(uint8_t* ip);
|
||||
|
||||
/*
|
||||
* @brief Get the leased time by DHCP sever
|
||||
* @retrun unit 1s
|
||||
* @return unit 1s
|
||||
*/
|
||||
uint32_t getDHCPLeasetime(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _DHCP_H_ */
|
||||
|
@ -120,6 +120,7 @@ uint8_t DNS_SOCKET; // SOCKET number for DNS
|
||||
uint16_t DNS_MSGID; // DNS message ID
|
||||
|
||||
uint32_t dns_1s_tick; // for timout of DNS processing
|
||||
static uint8_t retry_count;
|
||||
|
||||
/* converts uint16_t from network buffer to a host byte order integer. */
|
||||
uint16_t get16(uint8_t * s)
|
||||
@ -339,7 +340,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]);
|
||||
@ -367,7 +368,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
|
||||
{
|
||||
cp = dns_question(msg, cp);
|
||||
#ifdef _DNS_DEUBG_
|
||||
printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h"
|
||||
printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h");
|
||||
#endif
|
||||
if(!cp) return -1;
|
||||
}
|
||||
@ -377,7 +378,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
|
||||
{
|
||||
cp = dns_answer(msg, cp, ip_from_dns);
|
||||
#ifdef _DNS_DEUBG_
|
||||
printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h"
|
||||
printf("MAX_DOMAIN_NAME is too small, it should be redfine in dns.h");
|
||||
#endif
|
||||
if(!cp) return -1;
|
||||
}
|
||||
@ -472,7 +473,6 @@ int16_t dns_makequery(uint16_t op, char * name, uint8_t * buf, uint16_t len)
|
||||
|
||||
int8_t check_DNS_timeout(void)
|
||||
{
|
||||
static uint8_t retry_count;
|
||||
|
||||
if(dns_1s_tick >= DNS_WAIT_TIME)
|
||||
{
|
||||
@ -507,6 +507,9 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
|
||||
uint16_t len, port;
|
||||
int8_t ret_check_timeout;
|
||||
|
||||
retry_count = 0;
|
||||
dns_1s_tick = 0;
|
||||
|
||||
// Socket open
|
||||
socket(DNS_SOCKET, Sn_MR_UDP, 0, 0);
|
||||
|
||||
@ -536,6 +539,7 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
|
||||
#ifdef _DNS_DEBUG_
|
||||
printf("> DNS Server is not responding : %d.%d.%d.%d\r\n", dns_ip[0], dns_ip[1], dns_ip[2], dns_ip[3]);
|
||||
#endif
|
||||
wizchip_close(DNS_SOCKET);
|
||||
return 0; // timeout occurred
|
||||
}
|
||||
else if (ret_check_timeout == 0) {
|
||||
@ -558,6 +562,3 @@ void DNS_time_handler(void)
|
||||
{
|
||||
dns_1s_tick++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -51,6 +51,10 @@
|
||||
#ifndef _DNS_H_
|
||||
#define _DNS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
/*
|
||||
* @brief Define it for Debug & Monitor DNS processing.
|
||||
@ -98,4 +102,8 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns);
|
||||
*/
|
||||
void DNS_time_handler(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _DNS_H_ */
|
||||
|
@ -1,6 +1,10 @@
|
||||
#ifndef _FTPC_H_
|
||||
#define _FTPC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
@ -116,4 +120,8 @@ char proc_ftpc(char * buf);
|
||||
int pportc(char * arg);
|
||||
uint8_t* User_Keyboard_MSG();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _FTPC_H_
|
||||
|
@ -29,6 +29,10 @@
|
||||
|
||||
/* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -65,3 +69,7 @@ struct __file {
|
||||
#define SCANF_MIN 1
|
||||
#define SCANF_STD 2
|
||||
#define SCANF_FLT 3
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1,6 +1,10 @@
|
||||
#ifndef _FTPD_H_
|
||||
#define _FTPD_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Wiznet.
|
||||
* (c) Copyright 2002, Wiznet.
|
||||
@ -142,4 +146,9 @@ long recvfile(uint8_t s);
|
||||
#if defined(F_FILESYSTEM)
|
||||
void print_filedsc(FIL *fil);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _FTPD_H_
|
||||
|
@ -28,6 +28,9 @@
|
||||
*/
|
||||
|
||||
/* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@ -65,3 +68,7 @@ struct __file {
|
||||
#define SCANF_MIN 1
|
||||
#define SCANF_STD 2
|
||||
#define SCANF_FLT 3
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -295,14 +295,10 @@ int MQTTYield(MQTTClient* c, int timeout_ms)
|
||||
TimerInit(&timer);
|
||||
TimerCountdownMS(&timer, timeout_ms);
|
||||
|
||||
do
|
||||
if (cycle(c, &timer) == FAILURE)
|
||||
{
|
||||
if (cycle(c, &timer) == FAILURE)
|
||||
{
|
||||
rc = FAILURE;
|
||||
break;
|
||||
}
|
||||
} while (!TimerIsExpired(&timer));
|
||||
rc = FAILURE;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
@ -410,6 +406,9 @@ int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, messageH
|
||||
int len = 0;
|
||||
MQTTString topic = MQTTString_initializer;
|
||||
topic.cstring = (char *)topicFilter;
|
||||
// This was added because enum QoS was previously typed to *int which resulted in HardFault and unaligned integer read.
|
||||
// This coping below makes sure the parameter for MQTTSerialize_subscribe is always char no matter what compiler is using for enums
|
||||
char charQos = (char)qos;
|
||||
|
||||
#if defined(MQTT_TASK)
|
||||
MutexLock(&c->mutex);
|
||||
@ -420,7 +419,7 @@ int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, messageH
|
||||
TimerInit(&timer);
|
||||
TimerCountdownMS(&timer, c->command_timeout_ms);
|
||||
|
||||
len = MQTTSerialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, (int*)&qos);
|
||||
len = MQTTSerialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, &charQos);
|
||||
if (len <= 0)
|
||||
goto exit;
|
||||
if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) // send the subscribe packet
|
||||
|
@ -119,8 +119,6 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
||||
int index = 0;
|
||||
int rem_length = 0;
|
||||
MQTTHeader header = {0};
|
||||
int strindex = 0;
|
||||
|
||||
header.byte = buf[index++];
|
||||
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
||||
|
||||
@ -130,7 +128,7 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
||||
{
|
||||
unsigned char sessionPresent, connack_rc;
|
||||
if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1)
|
||||
strindex = MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent);
|
||||
MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent);
|
||||
}
|
||||
break;
|
||||
case PUBLISH:
|
||||
@ -141,7 +139,7 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
||||
MQTTString topicName = MQTTString_initializer;
|
||||
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
||||
&payload, &payloadlen, buf, buflen) == 1)
|
||||
strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,
|
||||
MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,
|
||||
topicName, payload, payloadlen);
|
||||
}
|
||||
break;
|
||||
@ -153,7 +151,7 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
||||
unsigned char packettype, dup;
|
||||
unsigned short packetid;
|
||||
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
||||
strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
||||
MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
||||
}
|
||||
break;
|
||||
case SUBACK:
|
||||
@ -162,20 +160,20 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
||||
int maxcount = 1, count = 0;
|
||||
int grantedQoSs[1];
|
||||
if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 1)
|
||||
strindex = MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs);
|
||||
MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs);
|
||||
}
|
||||
break;
|
||||
case UNSUBACK:
|
||||
{
|
||||
unsigned short packetid;
|
||||
if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1)
|
||||
strindex = MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);
|
||||
MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);
|
||||
}
|
||||
break;
|
||||
case PINGREQ:
|
||||
case PINGRESP:
|
||||
case DISCONNECT:
|
||||
strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
||||
snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
||||
break;
|
||||
}
|
||||
return strbuf;
|
||||
@ -187,7 +185,6 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
||||
int index = 0;
|
||||
int rem_length = 0;
|
||||
MQTTHeader header = {0};
|
||||
int strindex = 0;
|
||||
|
||||
header.byte = buf[index++];
|
||||
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
||||
@ -199,7 +196,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
||||
MQTTPacket_connectData data;
|
||||
int rc;
|
||||
if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1)
|
||||
strindex = MQTTStringFormat_connect(strbuf, strbuflen, &data);
|
||||
MQTTStringFormat_connect(strbuf, strbuflen, &data);
|
||||
}
|
||||
break;
|
||||
case PUBLISH:
|
||||
@ -210,7 +207,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
||||
MQTTString topicName = MQTTString_initializer;
|
||||
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
||||
&payload, &payloadlen, buf, buflen) == 1)
|
||||
strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,
|
||||
MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,
|
||||
topicName, payload, payloadlen);
|
||||
}
|
||||
break;
|
||||
@ -222,7 +219,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
||||
unsigned char packettype, dup;
|
||||
unsigned short packetid;
|
||||
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
||||
strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
||||
MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);
|
||||
}
|
||||
break;
|
||||
case SUBSCRIBE:
|
||||
@ -234,7 +231,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
||||
int requestedQoSs[1];
|
||||
if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count,
|
||||
topicFilters, requestedQoSs, buf, buflen) == 1)
|
||||
strindex = MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);;
|
||||
MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);;
|
||||
}
|
||||
break;
|
||||
case UNSUBSCRIBE:
|
||||
@ -244,13 +241,13 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
||||
int maxcount = 1, count = 0;
|
||||
MQTTString topicFilters[1];
|
||||
if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 1)
|
||||
strindex = MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters);
|
||||
MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters);
|
||||
}
|
||||
break;
|
||||
case PINGREQ:
|
||||
case PINGRESP:
|
||||
case DISCONNECT:
|
||||
strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
||||
snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
||||
break;
|
||||
}
|
||||
strbuf[strbuflen] = '\0';
|
||||
|
@ -26,7 +26,7 @@
|
||||
#endif
|
||||
|
||||
DLLExport int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid,
|
||||
int count, MQTTString topicFilters[], int requestedQoSs[]);
|
||||
int count, MQTTString topicFilters[], char requestedQoSs[]);
|
||||
|
||||
DLLExport int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid,
|
||||
int maxcount, int* count, MQTTString topicFilters[], int requestedQoSs[], unsigned char* buf, int len);
|
||||
|
@ -48,7 +48,7 @@ int MQTTSerialize_subscribeLength(int count, MQTTString topicFilters[])
|
||||
* @return the length of the serialized data. <= 0 indicates error
|
||||
*/
|
||||
int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, int count,
|
||||
MQTTString topicFilters[], int requestedQoSs[])
|
||||
MQTTString topicFilters[], char requestedQoSs[])
|
||||
{
|
||||
unsigned char *ptr = buf;
|
||||
MQTTHeader header = {0};
|
||||
|
@ -42,6 +42,7 @@
|
||||
|
||||
#include "mqtt_interface.h"
|
||||
#include "wizchip_conf.h"
|
||||
#include "socket.h"
|
||||
|
||||
unsigned long MilliTimer;
|
||||
|
||||
@ -122,12 +123,15 @@ void NewNetwork(Network* n, int sn) {
|
||||
* that contains the configuration information for the Network.
|
||||
* buffer : pointer to a read buffer.
|
||||
* len : buffer length.
|
||||
* @retval received data length or SOCKERR code
|
||||
*/
|
||||
int w5x00_read(Network* n, unsigned char* buffer, int len)
|
||||
int w5x00_read(Network* n, unsigned char* buffer, int len, long time)
|
||||
{
|
||||
|
||||
if((getSn_SR(n->my_socket) == SOCK_ESTABLISHED) && (getSn_RX_RSR(n->my_socket)>0))
|
||||
return recv(n->my_socket, buffer, len);
|
||||
|
||||
return SOCK_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -136,11 +140,14 @@ int w5x00_read(Network* n, unsigned char* buffer, int len)
|
||||
* that contains the configuration information for the Network.
|
||||
* buffer : pointer to a read buffer.
|
||||
* len : buffer length.
|
||||
* @retval length of data sent or SOCKERR code
|
||||
*/
|
||||
int w5x00_write(Network* n, unsigned char* buffer, int len)
|
||||
int w5x00_write(Network* n, unsigned char* buffer, int len, long time)
|
||||
{
|
||||
if(getSn_SR(n->my_socket) == SOCK_ESTABLISHED)
|
||||
return send(n->my_socket, buffer, len);
|
||||
|
||||
return SOCK_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -160,9 +167,9 @@ void w5x00_disconnect(Network* n)
|
||||
* ip : server iP.
|
||||
* port : server port.
|
||||
*/
|
||||
int ConnectNetwork(Network* n, char* ip, int port)
|
||||
void ConnectNetwork(Network* n, uint8_t* ip, uint16_t port)
|
||||
{
|
||||
uint8_t myport = 12345;
|
||||
uint16_t myport = 12345;
|
||||
|
||||
socket(n->my_socket,Sn_MR_TCP,myport,0);
|
||||
connect(n->my_socket,ip,port);
|
||||
|
@ -212,6 +212,13 @@ int main(void)
|
||||
#ifndef __MQTT_INTERFACE_H_
|
||||
#define __MQTT_INTERFACE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* @brief MQTT MilliTimer handler
|
||||
* @note MUST BE register to your system 1m Tick timer handler
|
||||
@ -234,8 +241,8 @@ typedef struct Network Network;
|
||||
struct Network
|
||||
{
|
||||
int my_socket;
|
||||
int (*mqttread) (Network*, unsigned char*, int, int);
|
||||
int (*mqttwrite) (Network*, unsigned char*, int, int);
|
||||
int (*mqttread) (Network*, unsigned char*, int, long);
|
||||
int (*mqttwrite) (Network*, unsigned char*, int, long);
|
||||
void (*disconnect) (Network*);
|
||||
};
|
||||
|
||||
@ -251,10 +258,14 @@ int TimerLeftMS(Timer*);
|
||||
/*
|
||||
* @brief Network interface porting
|
||||
*/
|
||||
int w5x00_read(Network*, unsigned char*, int);
|
||||
int w5x00_write(Network*, unsigned char*, int);
|
||||
int w5x00_read(Network*, unsigned char*, int, long);
|
||||
int w5x00_write(Network*, unsigned char*, int, long);
|
||||
void w5x00_disconnect(Network*);
|
||||
void NewNetwork(Network* n, int sn);
|
||||
int ConnectNetwork(Network*, char*, int);
|
||||
void ConnectNetwork(Network* n, uint8_t* ip, uint16_t port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //__MQTT_INTERFACE_H_
|
||||
|
@ -1,6 +1,10 @@
|
||||
#ifndef _SNMP_H_
|
||||
#define _SNMP_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// SNMP Debug Message (dump) Enable
|
||||
#define _SNMP_DEBUG_
|
||||
|
||||
@ -111,4 +115,8 @@ void SNMP_time_handler(void);
|
||||
uint32_t getSNMPTimeTick(void);
|
||||
void currentUptime(void *ptr, uint8_t *len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,10 @@
|
||||
#ifndef _SNMP_CUSTOM_H_
|
||||
#define _SNMP_CUSTOM_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
@ -30,4 +34,8 @@ void initTable();
|
||||
/* SNMP Trap: warmStart(1) */
|
||||
void initial_Trap(uint8_t * managerIP, uint8_t * agentIP);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -8,6 +8,10 @@
|
||||
#ifndef SNTP_H_
|
||||
#define SNTP_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
@ -65,4 +69,8 @@ int8_t SNTP_run(datetime *time);
|
||||
tstamp changedatetime_to_seconds(void);
|
||||
void calcdatetime(tstamp seconds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SNTP_H_ */
|
||||
|
@ -2,6 +2,10 @@
|
||||
#ifndef __NETUTIL_H__
|
||||
#define __NETUTIL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SYSTEM_LITTLE_ENDIAN
|
||||
@ -16,4 +20,8 @@ uint32_t htonl(uint32_t hostlong);
|
||||
uint32_t ntohs(uint16_t netshort);
|
||||
uint32_t ntohl(uint32_t netlong);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,10 @@
|
||||
#ifndef __TFTP_H__
|
||||
#define __TFTP_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define F_APP_TFTP
|
||||
@ -90,4 +94,8 @@ int TFTP_run(void);
|
||||
void TFTP_read_request(uint32_t server_ip, uint8_t *filename);
|
||||
void tftp_timeout_handler(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__TFTP_H__ */
|
||||
|
@ -8,6 +8,10 @@
|
||||
#ifndef __HTTPPARSER_H__
|
||||
#define __HTTPPARSER_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//#define _HTTPPARSER_DEBUG_
|
||||
|
||||
#define HTTP_SERVER_PORT 80 /**< HTTP server well-known port number */
|
||||
@ -147,4 +151,8 @@ uint16_t ATOI(uint8_t * str, uint8_t base);
|
||||
void mid(char* src, char* s1, char* s2, char* sub);
|
||||
void inet_addr_(uint8_t * addr, uint8_t * ip);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of __HTTPPARSER_H__ */
|
||||
|
@ -8,6 +8,10 @@
|
||||
#ifndef __HTTPSERVER_H__
|
||||
#define __HTTPSERVER_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// HTTP Server debug message enable
|
||||
#define _HTTPSERVER_DEBUG_
|
||||
|
||||
@ -100,4 +104,8 @@ uint8_t display_reg_webContent_list(void);
|
||||
void httpServer_time_handler(void);
|
||||
uint32_t get_httpServer_timecount(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -12,6 +12,10 @@
|
||||
#ifndef __HTTPUTIL_H__
|
||||
#define __HTTPUTIL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "httpServer.h"
|
||||
#include "httpParser.h"
|
||||
|
||||
@ -21,4 +25,8 @@ uint8_t http_post_cgi_handler(uint8_t * uri_name, st_http_request * p_http_reque
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user