Compare commits
65 Commits
W5500_PHY_
...
modifyFTPS
Author | SHA1 | Date | |
---|---|---|---|
7286d4aa36 | |||
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_
|
#ifndef _LOOPBACK_H_
|
||||||
#define _LOOPBACK_H_
|
#define _LOOPBACK_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* Loopback test debug message printout enable */
|
/* 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 */
|
/* UDP Loopback test example */
|
||||||
int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port);
|
int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -40,6 +40,11 @@
|
|||||||
|
|
||||||
#ifndef _W5100_H_
|
#ifndef _W5100_H_
|
||||||
#define _W5100_H_
|
#define _W5100_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "wizchip_conf.h"
|
#include "wizchip_conf.h"
|
||||||
|
|
||||||
@ -1850,6 +1855,10 @@ void wiz_recv_ignore(uint8_t sn, uint16_t len);
|
|||||||
#endif
|
#endif
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif //_W5100_H_
|
#endif //_W5100_H_
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,6 +42,10 @@
|
|||||||
#ifndef _W5100S_H_
|
#ifndef _W5100S_H_
|
||||||
#define _W5100S_H_
|
#define _W5100S_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "wizchip_conf.h"
|
#include "wizchip_conf.h"
|
||||||
|
|
||||||
@ -975,7 +979,7 @@
|
|||||||
* @brief Address Auto-Increment in Indirect Bus Interface
|
* @brief Address Auto-Increment in Indirect Bus Interface
|
||||||
* @details 0 : Disable auto-increment \n
|
* @details 0 : Disable auto-increment \n
|
||||||
* 1 : Enable auto-incremente \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.
|
* be automatically increased by 1 whenever read and write are performed.
|
||||||
*/
|
*/
|
||||||
#define MR_AI 0x02 ///< auto-increment in indirect mode
|
#define MR_AI 0x02 ///< auto-increment in indirect mode
|
||||||
@ -984,7 +988,7 @@
|
|||||||
* @brief Indirect Bus Interface mode
|
* @brief Indirect Bus Interface mode
|
||||||
* @details 0 : Disable Indirect bus Interface mode \n
|
* @details 0 : Disable Indirect bus Interface mode \n
|
||||||
* 1 : Enable 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
|
#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()
|
* @sa getSn_RXMEM_SIZE()
|
||||||
*/
|
*/
|
||||||
#define setSn_RXMEM_SIZE(sn, rxmemsize) \
|
#define setSn_RXMEM_SIZE(sn, rxmemsize) \
|
||||||
WIZCHIP_WRITE(Sn_RXBUF_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)
|
#define setSn_RXBUF_SIZE(sn,rxmemsize) setSn_RXMEM_SIZE(sn,rxmemsize)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup Socket_register_access_function_W5100S
|
* @ingroup Socket_register_access_function_W5100S
|
||||||
* @brief Get @ref Sn_RXMEM_SIZE register
|
* @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()
|
* @sa setSn_RXMEM_SIZE()
|
||||||
*/
|
*/
|
||||||
#define getSn_RXMEM_SIZE(sn) \
|
#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)
|
#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()
|
* @sa getSn_TXMEM_SIZE()
|
||||||
*/
|
*/
|
||||||
#define setSn_TXMEM_SIZE(sn, txmemsize) \
|
#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)
|
#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()
|
* @sa setSn_TXMEM_SIZE()
|
||||||
*/
|
*/
|
||||||
#define getSn_TXMEM_SIZE(sn) \
|
#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)
|
#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
|
* @return uint16_t. Max buffer size
|
||||||
*/
|
*/
|
||||||
#define getSn_RxMAX(sn) \
|
#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
|
* @return uint16_t. Max buffer size
|
||||||
*/
|
*/
|
||||||
#define getSn_TxMAX(sn) \
|
#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
|
* @ingroup Socket_register_access_function_W5100S
|
||||||
@ -3310,6 +3313,10 @@ void wiz_delay_ms(uint32_t ms);
|
|||||||
#endif
|
#endif
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif //_W5100S_H_
|
#endif //_W5100S_H_
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +40,11 @@
|
|||||||
|
|
||||||
#ifndef _W5200_H
|
#ifndef _W5200_H
|
||||||
#define _W5200_H
|
#define _W5200_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "wizchip_conf.h"
|
#include "wizchip_conf.h"
|
||||||
|
|
||||||
@ -2095,6 +2100,10 @@ void wiz_recv_ignore(uint8_t sn, uint16_t len);
|
|||||||
#endif
|
#endif
|
||||||
/// \endcond
|
/// \endcond
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif //_W5200_H_
|
#endif //_W5200_H_
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
#ifndef _W5300_H_
|
#ifndef _W5300_H_
|
||||||
#define _W5300_H_
|
#define _W5300_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
//
|
//
|
||||||
//! \file w5300.h
|
//! \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_IPCF (1 << 7) /**< 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_DPUR (1 << 6) /**< 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_PPPT (1 << 5) /**< 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_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*/
|
#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_PEN (1 << 7) /**< PIN 'BRDYn' enable bit of Pn_BRDYR. */
|
||||||
#define Pn_MT (1 << 6) /**< PIN memory type 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.
|
* @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
|
* @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_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 */
|
#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. */
|
#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
|
* @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.
|
* @return uint16_t. Variable of @ref Sn_PORTR.
|
||||||
* @sa setSn_PORTR()
|
* @sa setSn_PORTR()
|
||||||
*/
|
*/
|
||||||
#define getSn_PORTR(sn, port) \
|
#define getSn_PORTR(sn) \
|
||||||
WIZCHIP_READ(Sn_PORTR(sn))
|
WIZCHIP_READ(Sn_PORTR(sn))
|
||||||
#define getSn_PORT(sn) getSn_PORTR(sn) ///< For compatible ioLibrary
|
#define getSn_PORT(sn) getSn_PORTR(sn) ///< For compatible ioLibrary
|
||||||
|
|
||||||
@ -2120,7 +2125,7 @@ uint8_t getRMSR(uint8_t sn);
|
|||||||
* @sa getSn_PROTOR()
|
* @sa getSn_PROTOR()
|
||||||
*/
|
*/
|
||||||
#define setSn_PROTOR(sn, proto) \
|
#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
|
#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()
|
* @sa getSn_FRAGR()
|
||||||
*/
|
*/
|
||||||
#define setSn_FRAGR(sn, frag) \
|
#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)
|
#define setSn_FRAG(sn,frag) setSn_FRAGR(sn,flag)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2253,7 +2258,7 @@ uint32_t getSn_RX_RSR(uint8_t sn);
|
|||||||
* @sa setSn_FRAGR()
|
* @sa setSn_FRAGR()
|
||||||
*/
|
*/
|
||||||
#define getSn_FRAGR(sn) \
|
#define getSn_FRAGR(sn) \
|
||||||
(WIZCHIP_READ(Sn_FRAG(sn)) << 8)
|
(WIZCHIP_READ(Sn_FRAG(sn)))
|
||||||
#define getSn_FRAG(sn) getSn_FRAGR(sn)
|
#define getSn_FRAG(sn) getSn_FRAGR(sn)
|
||||||
|
|
||||||
|
|
||||||
@ -2324,4 +2329,8 @@ void wiz_recv_ignore(uint8_t sn, uint32_t len);
|
|||||||
#endif
|
#endif
|
||||||
/// \endcond
|
/// \endcond
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _W5300_H_
|
#endif // _W5300_H_
|
||||||
|
@ -48,6 +48,10 @@
|
|||||||
#ifndef _W5500_H_
|
#ifndef _W5500_H_
|
||||||
#define _W5500_H_
|
#define _W5500_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "wizchip_conf.h"
|
#include "wizchip_conf.h"
|
||||||
|
|
||||||
@ -2152,4 +2156,8 @@ void wiz_recv_ignore(uint8_t sn, uint16_t len);
|
|||||||
#endif
|
#endif
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _W5500_H_
|
#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(*((uint32_t*)addr) == 0) return SOCKERR_IPINVALID;
|
||||||
if((taddr == 0) && (getSn_MR(sn)&Sn_MR_MACRAW != Sn_MR_MACRAW)) 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((port == 0) && ((getSn_MR(sn)&Sn_MR_MACRAW) != Sn_MR_MACRAW)) return SOCKERR_PORTZERO;
|
||||||
tmp = getSn_SR(sn);
|
tmp = getSn_SR(sn);
|
||||||
//#if ( _WIZCHIP_ < 5200 )
|
//#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
|
//#else
|
||||||
// if(tmp != SOCK_MACRAW && tmp != SOCK_UDP) return SOCKERR_SOCKSTATUS;
|
// if(tmp != SOCK_MACRAW && tmp != SOCK_UDP) return SOCKERR_SOCKSTATUS;
|
||||||
//#endif
|
//#endif
|
||||||
@ -858,7 +858,7 @@ int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#if _WIZCHIP_ > 5200
|
#if !( (_WIZCHIP_ == 5100) || (_WIZCHIP_ == 5200) )
|
||||||
case SO_KEEPALIVEAUTO:
|
case SO_KEEPALIVEAUTO:
|
||||||
CHECK_SOCKMODE(Sn_MR_TCP);
|
CHECK_SOCKMODE(Sn_MR_TCP);
|
||||||
setSn_KPALVTR(sn,*(uint8_t*)arg);
|
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);
|
*(uint8_t*) arg = getSn_SR(sn);
|
||||||
break;
|
break;
|
||||||
case SO_REMAINSIZE:
|
case SO_REMAINSIZE:
|
||||||
if(getSn_MR(sn) == Sn_MR_TCP)
|
if(getSn_MR(sn) & Sn_MR_TCP)
|
||||||
*(uint16_t*)arg = getSn_RX_RSR(sn);
|
*(uint16_t*)arg = getSn_RX_RSR(sn);
|
||||||
else
|
else
|
||||||
*(uint16_t*)arg = sock_remained_size[sn];
|
*(uint16_t*)arg = sock_remained_size[sn];
|
||||||
|
@ -84,6 +84,9 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef _SOCKET_H_
|
#ifndef _SOCKET_H_
|
||||||
#define _SOCKET_H_
|
#define _SOCKET_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "wizchip_conf.h"
|
#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() )
|
SO_DESTPORT, ///< Set the destination Port number. @ref Sn_DPORT ( @ref setSn_DPORT(), @ref getSn_DPORT() )
|
||||||
#if _WIZCHIP_ != 5100
|
#if _WIZCHIP_ != 5100
|
||||||
SO_KEEPALIVESEND, ///< Valid only in setsockopt. Manually send keep-alive packet in TCP mode, Not supported in W5100
|
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
|
SO_KEEPALIVEAUTO, ///< Set/Get keep-alive auto transmission timer in TCP mode, Not supported in W5100, W5200
|
||||||
#endif
|
#endif
|
||||||
#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);
|
int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _SOCKET_H_
|
#endif // _SOCKET_H_
|
||||||
|
@ -163,21 +163,28 @@ _WIZCHIP WIZCHIP =
|
|||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
_WIZCHIP WIZCHIP =
|
_WIZCHIP WIZCHIP =
|
||||||
{
|
{
|
||||||
_WIZCHIP_IO_MODE_,
|
_WIZCHIP_IO_MODE_,
|
||||||
_WIZCHIP_ID_ ,
|
_WIZCHIP_ID_ ,
|
||||||
wizchip_cris_enter,
|
{
|
||||||
wizchip_cris_exit,
|
wizchip_cris_enter,
|
||||||
wizchip_cs_select,
|
wizchip_cris_exit
|
||||||
wizchip_cs_deselect,
|
},
|
||||||
//M20150601 : Rename the function
|
{
|
||||||
//wizchip_bus_readbyte,
|
wizchip_cs_select,
|
||||||
//wizchip_bus_writebyte
|
wizchip_cs_deselect
|
||||||
wizchip_bus_readdata,
|
},
|
||||||
wizchip_bus_writedata,
|
{
|
||||||
// wizchip_spi_readbyte,
|
{
|
||||||
// wizchip_spi_writebyte
|
//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
|
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 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;
|
int8_t tmp = 0;
|
||||||
wizchip_sw_reset();
|
wizchip_sw_reset();
|
||||||
if(txsize)
|
if(txsize)
|
||||||
@ -430,25 +440,27 @@ int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
|
|||||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
||||||
{
|
{
|
||||||
tmp += txsize[i];
|
tmp += txsize[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 and w5100s
|
||||||
if(tmp > 8) return -1;
|
if(tmp > 8) return -1;
|
||||||
#else
|
#else
|
||||||
if(tmp > 16) return -1;
|
if(tmp > 16) return -1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
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;
|
j = 0;
|
||||||
while(txsize[i] >> j != 1){j++;}
|
while((txsize[i] >> j != 1)&&(txsize[i] !=0)){j++;}
|
||||||
setSn_TXBUF_SIZE(i, j);
|
setSn_TXBUF_SIZE(i, j);
|
||||||
#else
|
#else
|
||||||
setSn_TXBUF_SIZE(i, txsize[i]);
|
setSn_TXBUF_SIZE(i, txsize[i]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rxsize)
|
if(rxsize)
|
||||||
{
|
{
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
@ -473,12 +485,12 @@ int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
|
|||||||
|
|
||||||
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
|
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;
|
j = 0;
|
||||||
while(rxsize[i] >> j != 1){j++;}
|
while((rxsize[i] >> j != 1)&&(txsize[i] !=0)){j++;}
|
||||||
setSn_RXBUF_SIZE(i, j);
|
setSn_RXBUF_SIZE(i, j);
|
||||||
#else
|
#else
|
||||||
setSn_RXBUF_SIZE(i, txsize[i]);
|
setSn_RXBUF_SIZE(i, rxsize[i]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -609,6 +621,7 @@ int8_t wizphy_getphylink(void)
|
|||||||
#elif _WIZCHIP_ == W5500
|
#elif _WIZCHIP_ == W5500
|
||||||
if(getPHYCFGR() & PHYCFGR_LNK_ON)
|
if(getPHYCFGR() & PHYCFGR_LNK_ON)
|
||||||
tmp = PHY_LINK_ON;
|
tmp = PHY_LINK_ON;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
tmp = -1;
|
tmp = -1;
|
||||||
#endif
|
#endif
|
||||||
@ -834,7 +847,6 @@ int8_t wizphy_setphypmode(uint8_t pmode)
|
|||||||
|
|
||||||
void wizchip_setnetinfo(wiz_NetInfo* pnetinfo)
|
void wizchip_setnetinfo(wiz_NetInfo* pnetinfo)
|
||||||
{
|
{
|
||||||
int i,j,k;
|
|
||||||
setSHAR(pnetinfo->mac);
|
setSHAR(pnetinfo->mac);
|
||||||
setGAR(pnetinfo->gw);
|
setGAR(pnetinfo->gw);
|
||||||
setSUBR(pnetinfo->sn);
|
setSUBR(pnetinfo->sn);
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||||
//! THE POSSIBILITY OF SUCH DAMAGE.
|
//! THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
@ -54,6 +54,10 @@
|
|||||||
#ifndef _WIZCHIP_CONF_H_
|
#ifndef _WIZCHIP_CONF_H_
|
||||||
#define _WIZCHIP_CONF_H_
|
#define _WIZCHIP_CONF_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
/**
|
/**
|
||||||
* @brief Select WIZCHIP.
|
* @brief Select WIZCHIP.
|
||||||
@ -68,7 +72,7 @@
|
|||||||
#define W5500 5500
|
#define W5500 5500
|
||||||
|
|
||||||
#ifndef _WIZCHIP_
|
#ifndef _WIZCHIP_
|
||||||
#define _WIZCHIP_ W5500 // W5100, W5100S, W5200, W5300, W5500
|
#define _WIZCHIP_ W5100S // W5100, W5100S, W5200, W5300, W5500
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _WIZCHIP_IO_MODE_NONE_ 0x0000
|
#define _WIZCHIP_IO_MODE_NONE_ 0x0000
|
||||||
@ -107,7 +111,7 @@
|
|||||||
* @brief Define interface mode.
|
* @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_
|
* @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_5500_
|
||||||
#define _WIZCHIP_IO_MODE_ _WIZCHIP_IO_MODE_SPI_
|
#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
|
* @ref \_WIZCHIP_IO_MODE_BUS_DIR_, @ref \_WIZCHIP_IO_MODE_BUS_INDIR_). \n\n
|
||||||
* ex> <code> #define \_WIZCHIP_IO_BASE_ 0x00008000 </code>
|
* ex> <code> #define \_WIZCHIP_IO_BASE_ 0x00008000 </code>
|
||||||
*/
|
*/
|
||||||
#define _WIZCHIP_IO_BASE_ 0x60000000 // for 5100S IND
|
#if _WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_BUS_
|
||||||
//#define _WIZCHIP_IO_BASE_ 0x00000000 // for 5100S SPI
|
#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_
|
#ifndef _WIZCHIP_IO_BASE_
|
||||||
#define _WIZCHIP_IO_BASE_ 0x00000000 // 0x8000
|
#define _WIZCHIP_IO_BASE_ 0x00000000 // 0x8000
|
||||||
@ -225,7 +232,7 @@
|
|||||||
typedef struct __WIZCHIP
|
typedef struct __WIZCHIP
|
||||||
{
|
{
|
||||||
uint16_t if_mode; ///< host interface mode
|
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.
|
* 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.
|
* @param nettime @ref _RTR_ value and @ref _RCR_ value. Refer to @ref wiz_NetTimeout.
|
||||||
*/
|
*/
|
||||||
void wizchip_gettimeout(wiz_NetTimeout* nettime);
|
void wizchip_gettimeout(wiz_NetTimeout* nettime);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _WIZCHIP_CONF_H_
|
#endif // _WIZCHIP_CONF_H_
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
//
|
//
|
||||||
//! \file dhcp.c
|
//! \file dhcp.c
|
||||||
//! \brief DHCP APIs implement file.
|
//! \brief DHCP APIs implement file.
|
||||||
//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
|
//! \details Processing DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
|
||||||
//! \version 1.1.0
|
//! \version 1.1.1
|
||||||
//! \date 2013/11/18
|
//! \date 2019/10/08
|
||||||
//! \par Revision history
|
//! \par Revision history
|
||||||
|
//! <2019/10/08> compare DHCP server ip address
|
||||||
//! <2013/11/18> 1st Release
|
//! <2013/11/18> 1st Release
|
||||||
//! <2012/12/20> V1.1.0
|
//! <2012/12/20> V1.1.0
|
||||||
//! 1. Optimize code
|
//! 1. Optimize code
|
||||||
@ -52,7 +53,7 @@
|
|||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "dhcp.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_
|
#ifdef _DHCP_DEBUG_
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -65,7 +66,7 @@
|
|||||||
#define STATE_DHCP_LEASED 3 ///< ReceiveD ACK and IP leased
|
#define STATE_DHCP_LEASED 3 ///< ReceiveD ACK and IP leased
|
||||||
#define STATE_DHCP_REREQUEST 4 ///< send REQUEST for maintaining leased IP
|
#define STATE_DHCP_REREQUEST 4 ///< send REQUEST for maintaining leased IP
|
||||||
#define STATE_DHCP_RELEASE 5 ///< No use
|
#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_FLAGSBROADCAST 0x8000 ///< The broadcast value of flags in @ref RIP_MSG
|
||||||
#define DHCP_FLAGSUNICAST 0x0000 ///< The unicast 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_SOCKET; // Socket number for DHCP
|
||||||
|
|
||||||
uint8_t DHCP_SIP[4]; // DHCP Server IP address
|
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
|
// Network information from DHCP Server
|
||||||
uint8_t OLD_allocated_ip[4] = {0, }; // Previous IP address
|
uint8_t OLD_allocated_ip[4] = {0, }; // Previous IP address
|
||||||
@ -228,7 +230,8 @@ 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));
|
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 */
|
/* send DISCOVER message to DHCP server */
|
||||||
void send_DHCP_DISCOVER(void);
|
void send_DHCP_DISCOVER(void);
|
||||||
|
|
||||||
@ -244,7 +247,7 @@ int8_t check_DHCP_leasedIP(void);
|
|||||||
/* check the timeout in DHCP process */
|
/* check the timeout in DHCP process */
|
||||||
uint8_t check_DHCP_timeout(void);
|
uint8_t check_DHCP_timeout(void);
|
||||||
|
|
||||||
/* Intialize to timeout process. */
|
/* Initialize to timeout process. */
|
||||||
void reset_DHCP_timeout(void);
|
void reset_DHCP_timeout(void);
|
||||||
|
|
||||||
/* Parse message as OFFER and ACK and NACK from DHCP server.*/
|
/* Parse message as OFFER and ACK and NACK from DHCP server.*/
|
||||||
@ -258,7 +261,7 @@ void default_ip_assign(void)
|
|||||||
setGAR (DHCP_allocated_gw);
|
setGAR (DHCP_allocated_gw);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The default handler of ip chaged */
|
/* The default handler of ip changed */
|
||||||
void default_ip_update(void)
|
void default_ip_update(void)
|
||||||
{
|
{
|
||||||
/* WIZchip Software Reset */
|
/* WIZchip Software Reset */
|
||||||
@ -268,7 +271,7 @@ void default_ip_update(void)
|
|||||||
setSHAR(DHCP_CHADDR);
|
setSHAR(DHCP_CHADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The default handler of ip chaged */
|
/* The default handler of ip changed */
|
||||||
void default_ip_conflict(void)
|
void default_ip_conflict(void)
|
||||||
{
|
{
|
||||||
// WIZchip Software Reset
|
// WIZchip Software Reset
|
||||||
@ -355,8 +358,16 @@ void send_DHCP_DISCOVER(void)
|
|||||||
uint16_t k = 0;
|
uint16_t k = 0;
|
||||||
|
|
||||||
makeDHCPMSG();
|
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
|
// Option Request Param
|
||||||
pDHCPMSG->OPT[k++] = dhcpMessageType;
|
pDHCPMSG->OPT[k++] = dhcpMessageType;
|
||||||
@ -379,10 +390,13 @@ void send_DHCP_DISCOVER(void)
|
|||||||
pDHCPMSG->OPT[k++] = 0; // fill zero length of hostname
|
pDHCPMSG->OPT[k++] = 0; // fill zero length of hostname
|
||||||
for(i = 0 ; HOST_NAME[i] != 0; i++)
|
for(i = 0 ; HOST_NAME[i] != 0; i++)
|
||||||
pDHCPMSG->OPT[k++] = HOST_NAME[i];
|
pDHCPMSG->OPT[k++] = HOST_NAME[i];
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3] >> 4);
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3]);
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4] >> 4);
|
||||||
pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname
|
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++] = dhcpParamRequest;
|
||||||
pDHCPMSG->OPT[k++] = 0x06; // length of request
|
pDHCPMSG->OPT[k++] = 0x06; // length of request
|
||||||
@ -439,7 +453,7 @@ void send_DHCP_REQUEST(void)
|
|||||||
ip[3] = 255;
|
ip[3] = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
k = 4; // beacaue MAGIC_COOKIE already made by makeDHCPMSG()
|
k = 4; // because MAGIC_COOKIE already made by makeDHCPMSG()
|
||||||
|
|
||||||
// Option Request Param.
|
// Option Request Param.
|
||||||
pDHCPMSG->OPT[k++] = dhcpMessageType;
|
pDHCPMSG->OPT[k++] = dhcpMessageType;
|
||||||
@ -478,10 +492,13 @@ void send_DHCP_REQUEST(void)
|
|||||||
pDHCPMSG->OPT[k++] = 0; // length of hostname
|
pDHCPMSG->OPT[k++] = 0; // length of hostname
|
||||||
for(i = 0 ; HOST_NAME[i] != 0; i++)
|
for(i = 0 ; HOST_NAME[i] != 0; i++)
|
||||||
pDHCPMSG->OPT[k++] = HOST_NAME[i];
|
pDHCPMSG->OPT[k++] = HOST_NAME[i];
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[3];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3] >> 4);
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[4];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[3]);
|
||||||
pDHCPMSG->OPT[k++] = DHCP_CHADDR[5];
|
pDHCPMSG->OPT[k++] = NibbleToHex(DHCP_CHADDR[4] >> 4);
|
||||||
pDHCPMSG->OPT[k - (i+3+1)] = i+3; // length of hostname
|
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++] = dhcpParamRequest;
|
||||||
pDHCPMSG->OPT[k++] = 0x08;
|
pDHCPMSG->OPT[k++] = 0x08;
|
||||||
@ -514,7 +531,7 @@ void send_DHCP_DECLINE(void)
|
|||||||
|
|
||||||
makeDHCPMSG();
|
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)) = ((DHCP_FLAGSUNICAST & 0xFF00)>> 8);
|
||||||
*((uint8_t*)(&pDHCPMSG->flags)+1) = (DHCP_FLAGSUNICAST & 0x00FF);
|
*((uint8_t*)(&pDHCPMSG->flags)+1) = (DHCP_FLAGSUNICAST & 0x00FF);
|
||||||
@ -574,7 +591,7 @@ int8_t parseDHCPMSG(void)
|
|||||||
|
|
||||||
uint8_t * p;
|
uint8_t * p;
|
||||||
uint8_t * e;
|
uint8_t * e;
|
||||||
uint8_t type;
|
uint8_t type = 0;
|
||||||
uint8_t opt_len;
|
uint8_t opt_len;
|
||||||
|
|
||||||
if((len = getSn_RX_RSR(DHCP_SOCKET)) > 0)
|
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]) ||
|
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[2] != DHCP_CHADDR[2]) || (pDHCPMSG->chaddr[3] != DHCP_CHADDR[3]) ||
|
||||||
(pDHCPMSG->chaddr[4] != DHCP_CHADDR[4]) || (pDHCPMSG->chaddr[5] != DHCP_CHADDR[5]) )
|
(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;
|
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 = (uint8_t *)(&pDHCPMSG->op);
|
||||||
p = p + 240; // 240 = sizeof(RIP_MSG) + MAGIC_COOKIE size in RIP_MSG.opt - sizeof(RIP_MSG.opt)
|
p = p + 240; // 240 = sizeof(RIP_MSG) + MAGIC_COOKIE size in RIP_MSG.opt - sizeof(RIP_MSG.opt)
|
||||||
e = p + (len - 240);
|
e = p + (len - 240);
|
||||||
@ -655,6 +687,10 @@ int8_t parseDHCPMSG(void)
|
|||||||
DHCP_SIP[1] = *p++;
|
DHCP_SIP[1] = *p++;
|
||||||
DHCP_SIP[2] = *p++;
|
DHCP_SIP[2] = *p++;
|
||||||
DHCP_SIP[3] = *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;
|
break;
|
||||||
default :
|
default :
|
||||||
p++;
|
p++;
|
||||||
@ -897,7 +933,7 @@ void DHCP_init(uint8_t s, uint8_t * buf)
|
|||||||
getSHAR(DHCP_CHADDR);
|
getSHAR(DHCP_CHADDR);
|
||||||
if((DHCP_CHADDR[0] | DHCP_CHADDR[1] | DHCP_CHADDR[2] | DHCP_CHADDR[3] | DHCP_CHADDR[4] | DHCP_CHADDR[5]) == 0x00)
|
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[0] = 0x00;
|
||||||
DHCP_CHADDR[1] = 0x08;
|
DHCP_CHADDR[1] = 0x08;
|
||||||
DHCP_CHADDR[2] = 0xdc;
|
DHCP_CHADDR[2] = 0xdc;
|
||||||
@ -913,7 +949,6 @@ void DHCP_init(uint8_t s, uint8_t * buf)
|
|||||||
|
|
||||||
// WIZchip Netinfo Clear
|
// WIZchip Netinfo Clear
|
||||||
setSIPR(zeroip);
|
setSIPR(zeroip);
|
||||||
setSIPR(zeroip);
|
|
||||||
setGAR(zeroip);
|
setGAR(zeroip);
|
||||||
|
|
||||||
reset_DHCP_timeout();
|
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)
|
void reset_DHCP_timeout(void)
|
||||||
{
|
{
|
||||||
dhcp_tick_1s = 0;
|
dhcp_tick_1s = 0;
|
||||||
@ -971,6 +1006,13 @@ uint32_t getDHCPLeasetime(void)
|
|||||||
return dhcp_lease_time;
|
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
|
//! \file dhcp.h
|
||||||
//! \brief DHCP APIs Header file.
|
//! \brief DHCP APIs Header file.
|
||||||
//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
|
//! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
|
||||||
//! \version 1.1.0
|
//! \version 1.1.1
|
||||||
//! \date 2013/11/18
|
//! \date 2019/10/08
|
||||||
//! \par Revision history
|
//! \par Revision history
|
||||||
|
//! <2019/10/08> compare DHCP server ip address
|
||||||
//! <2013/11/18> 1st Release
|
//! <2013/11/18> 1st Release
|
||||||
//! <2012/12/20> V1.1.0
|
//! <2012/12/20> V1.1.0
|
||||||
//! 1. Move unreferenced DEFINE to dhcp.c
|
//! 1. Move unreferenced DEFINE to dhcp.c
|
||||||
@ -45,16 +46,20 @@
|
|||||||
#ifndef _DHCP_H_
|
#ifndef _DHCP_H_
|
||||||
#define _DHCP_H_
|
#define _DHCP_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief
|
* @brief
|
||||||
* @details If you want to display debug & procssing message, Define _DHCP_DEBUG_
|
* @details If you want to display debug & processing message, Define _DHCP_DEBUG_
|
||||||
* @note If defined, it dependens on <stdio.h>
|
* @note If defined, it depends on <stdio.h>
|
||||||
*/
|
*/
|
||||||
//#define _DHCP_DEBUG_
|
//#define _DHCP_DEBUG_
|
||||||
|
|
||||||
|
|
||||||
/* Retry to processing DHCP */
|
/* 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
|
#define DHCP_WAIT_TIME 10 ///< Wait Time 10s
|
||||||
|
|
||||||
|
|
||||||
@ -63,7 +68,7 @@
|
|||||||
#define DHCP_CLIENT_PORT 68 ///< DHCP client port number
|
#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"
|
#define DCHP_HOST_NAME "WIZnet\0"
|
||||||
|
|
||||||
@ -72,18 +77,18 @@
|
|||||||
*/
|
*/
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
DHCP_FAILED = 0, ///< Procssing Fail
|
DHCP_FAILED = 0, ///< Processing Fail
|
||||||
DHCP_RUNNING, ///< Procssing DHCP proctocol
|
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_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_CHANGED, ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
|
||||||
DHCP_IP_LEASED, ///< Stand by
|
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)
|
* @brief DHCP client initialization (outside of the main loop)
|
||||||
* @param s - socket number
|
* @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);
|
void DHCP_init(uint8_t s, uint8_t * buf);
|
||||||
|
|
||||||
@ -97,7 +102,7 @@ void DHCP_time_handler(void);
|
|||||||
* @brief Register call back function
|
* @brief Register call back function
|
||||||
* @param ip_assign - callback func when IP is assigned from DHCP server first
|
* @param ip_assign - callback func when IP is assigned from DHCP server first
|
||||||
* @param ip_update - callback func when IP is changed
|
* @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));
|
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);
|
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()
|
* @note If you want to restart. call DHCP_init() and DHCP_run()
|
||||||
*/
|
*/
|
||||||
void DHCP_stop(void);
|
void DHCP_stop(void);
|
||||||
@ -145,8 +150,12 @@ void getDNSfromDHCP(uint8_t* ip);
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief Get the leased time by DHCP sever
|
* @brief Get the leased time by DHCP sever
|
||||||
* @retrun unit 1s
|
* @return unit 1s
|
||||||
*/
|
*/
|
||||||
uint32_t getDHCPLeasetime(void);
|
uint32_t getDHCPLeasetime(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _DHCP_H_ */
|
#endif /* _DHCP_H_ */
|
||||||
|
@ -21,30 +21,30 @@
|
|||||||
//!
|
//!
|
||||||
//! Copyright (c) 2013, WIZnet Co., LTD.
|
//! Copyright (c) 2013, WIZnet Co., LTD.
|
||||||
//! All rights reserved.
|
//! All rights reserved.
|
||||||
//!
|
//!
|
||||||
//! Redistribution and use in source and binary forms, with or without
|
//! Redistribution and use in source and binary forms, with or without
|
||||||
//! modification, are permitted provided that the following conditions
|
//! modification, are permitted provided that the following conditions
|
||||||
//! are met:
|
//! are met:
|
||||||
//!
|
//!
|
||||||
//! * Redistributions of source code must retain the above copyright
|
//! * Redistributions of source code must retain the above copyright
|
||||||
//! notice, this list of conditions and the following disclaimer.
|
//! notice, this list of conditions and the following disclaimer.
|
||||||
//! * Redistributions in binary form must reproduce the above copyright
|
//! * Redistributions in binary form must reproduce the above copyright
|
||||||
//! notice, this list of conditions and the following disclaimer in the
|
//! notice, this list of conditions and the following disclaimer in the
|
||||||
//! documentation and/or other materials provided with the distribution.
|
//! documentation and/or other materials provided with the distribution.
|
||||||
//! * Neither the name of the <ORGANIZATION> nor the names of its
|
//! * Neither the name of the <ORGANIZATION> nor the names of its
|
||||||
//! contributors may be used to endorse or promote products derived
|
//! contributors may be used to endorse or promote products derived
|
||||||
//! from this software without specific prior written permission.
|
//! from this software without specific prior written permission.
|
||||||
//!
|
//!
|
||||||
//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
//! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
//! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
//! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
//! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
//! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
//! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
//! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
//! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
//! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
//! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||||
//! THE POSSIBILITY OF SUCH DAMAGE.
|
//! THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
//
|
//
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
@ -120,6 +120,7 @@ uint8_t DNS_SOCKET; // SOCKET number for DNS
|
|||||||
uint16_t DNS_MSGID; // DNS message ID
|
uint16_t DNS_MSGID; // DNS message ID
|
||||||
|
|
||||||
uint32_t dns_1s_tick; // for timout of DNS processing
|
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. */
|
/* converts uint16_t from network buffer to a host byte order integer. */
|
||||||
uint16_t get16(uint8_t * s)
|
uint16_t get16(uint8_t * s)
|
||||||
@ -327,9 +328,9 @@ uint8_t * dns_answer(uint8_t * msg, uint8_t * cp, uint8_t * ip_from_dns)
|
|||||||
* Arguments : dhdr - is a pointer to the header for DNS message
|
* Arguments : dhdr - is a pointer to the header for DNS message
|
||||||
* buf - is a pointer to the reply message.
|
* buf - is a pointer to the reply message.
|
||||||
* len - is the size of reply message.
|
* len - is the size of reply message.
|
||||||
* Returns : -1 - Domain name lenght is too big
|
* Returns : -1 - Domain name lenght is too big
|
||||||
* 0 - Fail (Timout or parse error)
|
* 0 - Fail (Timout or parse error)
|
||||||
* 1 - Success,
|
* 1 - Success,
|
||||||
*/
|
*/
|
||||||
int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
|
int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
|
||||||
{
|
{
|
||||||
@ -339,7 +340,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
|
|||||||
uint8_t * cp;
|
uint8_t * cp;
|
||||||
|
|
||||||
msg = pbuf;
|
msg = pbuf;
|
||||||
memset(pdhdr, 0, sizeof(pdhdr));
|
memset(pdhdr, 0, sizeof(*pdhdr));
|
||||||
|
|
||||||
pdhdr->id = get16(&msg[0]);
|
pdhdr->id = get16(&msg[0]);
|
||||||
tmp = get16(&msg[2]);
|
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);
|
cp = dns_question(msg, cp);
|
||||||
#ifdef _DNS_DEUBG_
|
#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
|
#endif
|
||||||
if(!cp) return -1;
|
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);
|
cp = dns_answer(msg, cp, ip_from_dns);
|
||||||
#ifdef _DNS_DEUBG_
|
#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
|
#endif
|
||||||
if(!cp) return -1;
|
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)
|
int8_t check_DNS_timeout(void)
|
||||||
{
|
{
|
||||||
static uint8_t retry_count;
|
|
||||||
|
|
||||||
if(dns_1s_tick >= DNS_WAIT_TIME)
|
if(dns_1s_tick >= DNS_WAIT_TIME)
|
||||||
{
|
{
|
||||||
@ -506,14 +506,17 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
|
|||||||
uint8_t ip[4];
|
uint8_t ip[4];
|
||||||
uint16_t len, port;
|
uint16_t len, port;
|
||||||
int8_t ret_check_timeout;
|
int8_t ret_check_timeout;
|
||||||
|
|
||||||
|
retry_count = 0;
|
||||||
|
dns_1s_tick = 0;
|
||||||
|
|
||||||
// Socket open
|
// Socket open
|
||||||
socket(DNS_SOCKET, Sn_MR_UDP, 0, 0);
|
socket(DNS_SOCKET, Sn_MR_UDP, 0, 0);
|
||||||
|
|
||||||
#ifdef _DNS_DEBUG_
|
#ifdef _DNS_DEBUG_
|
||||||
printf("> DNS Query to DNS Server : %d.%d.%d.%d\r\n", dns_ip[0], dns_ip[1], dns_ip[2], dns_ip[3]);
|
printf("> DNS Query to DNS Server : %d.%d.%d.%d\r\n", dns_ip[0], dns_ip[1], dns_ip[2], dns_ip[3]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
len = dns_makequery(0, (char *)name, pDNSMSG, MAX_DNS_BUF_SIZE);
|
len = dns_makequery(0, (char *)name, pDNSMSG, MAX_DNS_BUF_SIZE);
|
||||||
sendto(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN);
|
sendto(DNS_SOCKET, pDNSMSG, len, dns_ip, IPPORT_DOMAIN);
|
||||||
|
|
||||||
@ -536,6 +539,7 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
|
|||||||
#ifdef _DNS_DEBUG_
|
#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]);
|
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
|
#endif
|
||||||
|
wizchip_close(DNS_SOCKET);
|
||||||
return 0; // timeout occurred
|
return 0; // timeout occurred
|
||||||
}
|
}
|
||||||
else if (ret_check_timeout == 0) {
|
else if (ret_check_timeout == 0) {
|
||||||
@ -558,6 +562,3 @@ void DNS_time_handler(void)
|
|||||||
{
|
{
|
||||||
dns_1s_tick++;
|
dns_1s_tick++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,6 +51,10 @@
|
|||||||
#ifndef _DNS_H_
|
#ifndef _DNS_H_
|
||||||
#define _DNS_H_
|
#define _DNS_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
/*
|
/*
|
||||||
* @brief Define it for Debug & Monitor DNS processing.
|
* @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);
|
void DNS_time_handler(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _DNS_H_ */
|
#endif /* _DNS_H_ */
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#ifndef _FTPC_H_
|
#ifndef _FTPC_H_
|
||||||
#define _FTPC_H_
|
#define _FTPC_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -116,4 +120,8 @@ char proc_ftpc(char * buf);
|
|||||||
int pportc(char * arg);
|
int pportc(char * arg);
|
||||||
uint8_t* User_Keyboard_MSG();
|
uint8_t* User_Keyboard_MSG();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _FTPC_H_
|
#endif // _FTPC_H_
|
||||||
|
@ -29,6 +29,10 @@
|
|||||||
|
|
||||||
/* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */
|
/* $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 <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -65,3 +69,7 @@ struct __file {
|
|||||||
#define SCANF_MIN 1
|
#define SCANF_MIN 1
|
||||||
#define SCANF_STD 2
|
#define SCANF_STD 2
|
||||||
#define SCANF_FLT 3
|
#define SCANF_FLT 3
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,10 @@
|
|||||||
#ifndef _FTPD_H_
|
#ifndef _FTPD_H_
|
||||||
#define _FTPD_H_
|
#define _FTPD_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wiznet.
|
* Wiznet.
|
||||||
* (c) Copyright 2002, Wiznet.
|
* (c) Copyright 2002, Wiznet.
|
||||||
@ -17,21 +21,19 @@
|
|||||||
//#define F_FILESYSTEM // If your target support a file system, you have to activate this feature and implement.
|
//#define F_FILESYSTEM // If your target support a file system, you have to activate this feature and implement.
|
||||||
|
|
||||||
#if defined(F_FILESYSTEM)
|
#if defined(F_FILESYSTEM)
|
||||||
#include "ff.h"
|
//#include "ff.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define F_APP_FTP
|
#define F_APP_FTP
|
||||||
#define _FTP_DEBUG_
|
#define _FTP_DEBUG_
|
||||||
|
|
||||||
|
|
||||||
#define LINELEN 100
|
#define _FTP_FILENAME_LEN_ 100
|
||||||
//#define DATA_BUF_SIZE 100
|
//#define DATA_BUF_SIZE 100
|
||||||
#if !defined(F_FILESYSTEM)
|
#if !defined(F_FILESYSTEM)
|
||||||
#define _MAX_SS 512
|
#define _MAX_SS 512
|
||||||
#endif
|
#endif
|
||||||
|
#define SOCK_MAX_NUM 4
|
||||||
#define CTRL_SOCK 2
|
|
||||||
#define DATA_SOCK 3
|
|
||||||
|
|
||||||
#define IPPORT_FTPD 20 /* FTP Data port */
|
#define IPPORT_FTPD 20 /* FTP Data port */
|
||||||
#define IPPORT_FTP 21 /* FTP Control port */
|
#define IPPORT_FTP 21 /* FTP Control port */
|
||||||
@ -75,43 +77,18 @@ enum ftp_cmd {
|
|||||||
NO_CMD,
|
NO_CMD,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ftp_type {
|
|
||||||
ASCII_TYPE,
|
|
||||||
IMAGE_TYPE,
|
|
||||||
LOGICAL_TYPE
|
|
||||||
};
|
|
||||||
|
|
||||||
enum ftp_state {
|
|
||||||
FTPS_NOT_LOGIN,
|
|
||||||
FTPS_LOGIN
|
|
||||||
};
|
|
||||||
|
|
||||||
enum datasock_state{
|
|
||||||
DATASOCK_IDLE,
|
|
||||||
DATASOCK_READY,
|
|
||||||
DATASOCK_START
|
|
||||||
};
|
|
||||||
|
|
||||||
enum datasock_mode{
|
|
||||||
PASSIVE_MODE,
|
|
||||||
ACTIVE_MODE
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ftpd {
|
struct ftpd {
|
||||||
uint8_t control; /* Control stream */
|
uint8_t ctrl_sock; /* Control Socket */
|
||||||
uint8_t data; /* Data stream */
|
uint8_t data_sock; /* Data Socket */
|
||||||
|
char user[20]; /* FTP Server user */
|
||||||
enum ftp_type type; /* Transfer type */
|
char pass[20]; /* FTP Server password */
|
||||||
enum ftp_state state;
|
char username[_FTP_FILENAME_LEN_]; /* Arg to USER command */
|
||||||
|
char workingdir[_FTP_FILENAME_LEN_];
|
||||||
enum ftp_cmd current_cmd;
|
char filename[_FTP_FILENAME_LEN_];
|
||||||
|
uint8_t is_login; /* Login 1: login, 0: Not login */
|
||||||
enum datasock_state dsock_state;
|
uint8_t is_ascii; /* Transfer Type 1 : ASCII, 0 : Binary */
|
||||||
enum datasock_mode dsock_mode;
|
uint8_t is_active; /* FTP Mode 1 : Active, 0: Passive */
|
||||||
|
|
||||||
char username[LINELEN]; /* Arg to USER command */
|
|
||||||
char workingdir[LINELEN];
|
|
||||||
char filename[LINELEN];
|
|
||||||
|
|
||||||
#if defined(F_FILESYSTEM)
|
#if defined(F_FILESYSTEM)
|
||||||
FIL fil; // FatFs File objects
|
FIL fil; // FatFs File objects
|
||||||
@ -120,18 +97,8 @@ struct ftpd {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef un_I2cval
|
void ftpd_init(char* user, char*pass);
|
||||||
typedef union _un_l2cval {
|
|
||||||
uint32_t lVal;
|
|
||||||
uint8_t cVal[4];
|
|
||||||
}un_l2cval;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void ftpd_init(uint8_t * src_ip);
|
|
||||||
uint8_t ftpd_run(uint8_t * dbuf);
|
uint8_t ftpd_run(uint8_t * dbuf);
|
||||||
char proc_ftpd(char * buf);
|
|
||||||
char ftplogin(char * pass);
|
|
||||||
int pport(char * arg);
|
|
||||||
|
|
||||||
int sendit(char * command);
|
int sendit(char * command);
|
||||||
int recvit(char * command);
|
int recvit(char * command);
|
||||||
@ -142,4 +109,9 @@ long recvfile(uint8_t s);
|
|||||||
#if defined(F_FILESYSTEM)
|
#if defined(F_FILESYSTEM)
|
||||||
void print_filedsc(FIL *fil);
|
void print_filedsc(FIL *fil);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _FTPD_H_
|
#endif // _FTPD_H_
|
||||||
|
@ -28,6 +28,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */
|
/* $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 <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -65,3 +68,7 @@ struct __file {
|
|||||||
#define SCANF_MIN 1
|
#define SCANF_MIN 1
|
||||||
#define SCANF_STD 2
|
#define SCANF_STD 2
|
||||||
#define SCANF_FLT 3
|
#define SCANF_FLT 3
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -28,9 +28,9 @@ static int getNextPacketId(MQTTClient *c) {
|
|||||||
|
|
||||||
static int sendPacket(MQTTClient* c, int length, Timer* timer)
|
static int sendPacket(MQTTClient* c, int length, Timer* timer)
|
||||||
{
|
{
|
||||||
int rc = FAILURE,
|
int rc = FAILURE,
|
||||||
sent = 0;
|
sent = 0;
|
||||||
|
|
||||||
while (sent < length && !TimerIsExpired(timer))
|
while (sent < length && !TimerIsExpired(timer))
|
||||||
{
|
{
|
||||||
rc = c->ipstack->mqttwrite(c->ipstack, &c->buf[sent], length, TimerLeftMS(timer));
|
rc = c->ipstack->mqttwrite(c->ipstack, &c->buf[sent], length, TimerLeftMS(timer));
|
||||||
@ -54,7 +54,7 @@ void MQTTClientInit(MQTTClient* c, Network* network, unsigned int command_timeou
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
c->ipstack = network;
|
c->ipstack = network;
|
||||||
|
|
||||||
for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i)
|
for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i)
|
||||||
c->messageHandlers[i].topicFilter = 0;
|
c->messageHandlers[i].topicFilter = 0;
|
||||||
c->command_timeout_ms = command_timeout_ms;
|
c->command_timeout_ms = command_timeout_ms;
|
||||||
@ -136,7 +136,7 @@ static char isTopicMatched(char* topicFilter, MQTTString* topicName)
|
|||||||
char* curf = topicFilter;
|
char* curf = topicFilter;
|
||||||
char* curn = topicName->lenstring.data;
|
char* curn = topicName->lenstring.data;
|
||||||
char* curn_end = curn + topicName->lenstring.len;
|
char* curn_end = curn + topicName->lenstring.len;
|
||||||
|
|
||||||
while (*curf && curn < curn_end)
|
while (*curf && curn < curn_end)
|
||||||
{
|
{
|
||||||
if (*curn == '/' && *curf != '/')
|
if (*curn == '/' && *curf != '/')
|
||||||
@ -154,7 +154,7 @@ static char isTopicMatched(char* topicFilter, MQTTString* topicName)
|
|||||||
curf++;
|
curf++;
|
||||||
curn++;
|
curn++;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (curn == curn_end) && (*curf == '\0');
|
return (curn == curn_end) && (*curf == '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,15 +179,15 @@ int deliverMessage(MQTTClient* c, MQTTString* topicName, MQTTMessage* message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc == FAILURE && c->defaultMessageHandler != NULL)
|
if (rc == FAILURE && c->defaultMessageHandler != NULL)
|
||||||
{
|
{
|
||||||
MessageData md;
|
MessageData md;
|
||||||
NewMessageData(&md, topicName, message);
|
NewMessageData(&md, topicName, message);
|
||||||
c->defaultMessageHandler(&md);
|
c->defaultMessageHandler(&md);
|
||||||
rc = SUCCESSS;
|
rc = SUCCESSS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ int cycle(MQTTClient* c, Timer* timer)
|
|||||||
{
|
{
|
||||||
// read the socket, see what work is due
|
// read the socket, see what work is due
|
||||||
unsigned short packet_type = readPacket(c, timer);
|
unsigned short packet_type = readPacket(c, timer);
|
||||||
|
|
||||||
int len = 0,
|
int len = 0,
|
||||||
rc = SUCCESSS;
|
rc = SUCCESSS;
|
||||||
|
|
||||||
@ -295,15 +295,11 @@ int MQTTYield(MQTTClient* c, int timeout_ms)
|
|||||||
TimerInit(&timer);
|
TimerInit(&timer);
|
||||||
TimerCountdownMS(&timer, timeout_ms);
|
TimerCountdownMS(&timer, timeout_ms);
|
||||||
|
|
||||||
do
|
if (cycle(c, &timer) == FAILURE)
|
||||||
{
|
{
|
||||||
if (cycle(c, &timer) == FAILURE)
|
rc = FAILURE;
|
||||||
{
|
}
|
||||||
rc = FAILURE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (!TimerIsExpired(&timer));
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,7 +321,7 @@ void MQTTRun(void* parm)
|
|||||||
#if defined(MQTT_TASK)
|
#if defined(MQTT_TASK)
|
||||||
MutexUnlock(&c->mutex);
|
MutexUnlock(&c->mutex);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -340,14 +336,14 @@ int MQTTStartTask(MQTTClient* client)
|
|||||||
int waitfor(MQTTClient* c, int packet_type, Timer* timer)
|
int waitfor(MQTTClient* c, int packet_type, Timer* timer)
|
||||||
{
|
{
|
||||||
int rc = FAILURE;
|
int rc = FAILURE;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (TimerIsExpired(timer))
|
if (TimerIsExpired(timer))
|
||||||
break; // we timed out
|
break; // we timed out
|
||||||
}
|
}
|
||||||
while ((rc = cycle(c, timer)) != packet_type);
|
while ((rc = cycle(c, timer)) != packet_type);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,20 +360,20 @@ int MQTTConnect(MQTTClient* c, MQTTPacket_connectData* options)
|
|||||||
#endif
|
#endif
|
||||||
if (c->isconnected) /* don't send connect packet again if we are already connected */
|
if (c->isconnected) /* don't send connect packet again if we are already connected */
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
TimerInit(&connect_timer);
|
TimerInit(&connect_timer);
|
||||||
TimerCountdownMS(&connect_timer, c->command_timeout_ms);
|
TimerCountdownMS(&connect_timer, c->command_timeout_ms);
|
||||||
|
|
||||||
if (options == 0)
|
if (options == 0)
|
||||||
options = &default_options; /* set default options if none were supplied */
|
options = &default_options; /* set default options if none were supplied */
|
||||||
|
|
||||||
c->keepAliveInterval = options->keepAliveInterval;
|
c->keepAliveInterval = options->keepAliveInterval;
|
||||||
TimerCountdown(&c->ping_timer, c->keepAliveInterval);
|
TimerCountdown(&c->ping_timer, c->keepAliveInterval);
|
||||||
if ((len = MQTTSerialize_connect(c->buf, c->buf_size, options)) <= 0)
|
if ((len = MQTTSerialize_connect(c->buf, c->buf_size, options)) <= 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
if ((rc = sendPacket(c, len, &connect_timer)) != SUCCESSS) // send the connect packet
|
if ((rc = sendPacket(c, len, &connect_timer)) != SUCCESSS) // send the connect packet
|
||||||
goto exit; // there was a problem
|
goto exit; // there was a problem
|
||||||
|
|
||||||
// this will be a blocking call, wait for the connack
|
// this will be a blocking call, wait for the connack
|
||||||
if (waitfor(c, CONNACK, &connect_timer) == CONNACK)
|
if (waitfor(c, CONNACK, &connect_timer) == CONNACK)
|
||||||
{
|
{
|
||||||
@ -390,7 +386,7 @@ int MQTTConnect(MQTTClient* c, MQTTPacket_connectData* options)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
rc = FAILURE;
|
rc = FAILURE;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (rc == SUCCESSS)
|
if (rc == SUCCESSS)
|
||||||
c->isconnected = 1;
|
c->isconnected = 1;
|
||||||
@ -404,13 +400,16 @@ exit:
|
|||||||
|
|
||||||
|
|
||||||
int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, messageHandler messageHandler)
|
int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, messageHandler messageHandler)
|
||||||
{
|
{
|
||||||
int rc = FAILURE;
|
int rc = FAILURE;
|
||||||
Timer timer;
|
Timer timer;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
MQTTString topic = MQTTString_initializer;
|
MQTTString topic = MQTTString_initializer;
|
||||||
topic.cstring = (char *)topicFilter;
|
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)
|
#if defined(MQTT_TASK)
|
||||||
MutexLock(&c->mutex);
|
MutexLock(&c->mutex);
|
||||||
#endif
|
#endif
|
||||||
@ -419,19 +418,19 @@ int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, messageH
|
|||||||
|
|
||||||
TimerInit(&timer);
|
TimerInit(&timer);
|
||||||
TimerCountdownMS(&timer, c->command_timeout_ms);
|
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)
|
if (len <= 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) // send the subscribe packet
|
if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) // send the subscribe packet
|
||||||
goto exit; // there was a problem
|
goto exit; // there was a problem
|
||||||
|
|
||||||
if (waitfor(c, SUBACK, &timer) == SUBACK) // wait for suback
|
if (waitfor(c, SUBACK, &timer) == SUBACK) // wait for suback
|
||||||
{
|
{
|
||||||
int count = 0, grantedQoS = -1;
|
int count = 0, grantedQoS = -1;
|
||||||
unsigned short mypacketid;
|
unsigned short mypacketid;
|
||||||
if (MQTTDeserialize_suback(&mypacketid, 1, &count, &grantedQoS, c->readbuf, c->readbuf_size) == 1)
|
if (MQTTDeserialize_suback(&mypacketid, 1, &count, &grantedQoS, c->readbuf, c->readbuf_size) == 1)
|
||||||
rc = grantedQoS; // 0, 1, 2 or 0x80
|
rc = grantedQoS; // 0, 1, 2 or 0x80
|
||||||
if (rc != 0x80)
|
if (rc != 0x80)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -447,9 +446,9 @@ int MQTTSubscribe(MQTTClient* c, const char* topicFilter, enum QoS qos, messageH
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rc = FAILURE;
|
rc = FAILURE;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
#if defined(MQTT_TASK)
|
#if defined(MQTT_TASK)
|
||||||
MutexUnlock(&c->mutex);
|
MutexUnlock(&c->mutex);
|
||||||
@ -459,9 +458,9 @@ exit:
|
|||||||
|
|
||||||
|
|
||||||
int MQTTUnsubscribe(MQTTClient* c, const char* topicFilter)
|
int MQTTUnsubscribe(MQTTClient* c, const char* topicFilter)
|
||||||
{
|
{
|
||||||
int rc = FAILURE;
|
int rc = FAILURE;
|
||||||
Timer timer;
|
Timer timer;
|
||||||
MQTTString topic = MQTTString_initializer;
|
MQTTString topic = MQTTString_initializer;
|
||||||
topic.cstring = (char *)topicFilter;
|
topic.cstring = (char *)topicFilter;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
@ -474,21 +473,21 @@ int MQTTUnsubscribe(MQTTClient* c, const char* topicFilter)
|
|||||||
|
|
||||||
TimerInit(&timer);
|
TimerInit(&timer);
|
||||||
TimerCountdownMS(&timer, c->command_timeout_ms);
|
TimerCountdownMS(&timer, c->command_timeout_ms);
|
||||||
|
|
||||||
if ((len = MQTTSerialize_unsubscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic)) <= 0)
|
if ((len = MQTTSerialize_unsubscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic)) <= 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) // send the subscribe packet
|
if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) // send the subscribe packet
|
||||||
goto exit; // there was a problem
|
goto exit; // there was a problem
|
||||||
|
|
||||||
if (waitfor(c, UNSUBACK, &timer) == UNSUBACK)
|
if (waitfor(c, UNSUBACK, &timer) == UNSUBACK)
|
||||||
{
|
{
|
||||||
unsigned short mypacketid; // should be the same as the packetid above
|
unsigned short mypacketid; // should be the same as the packetid above
|
||||||
if (MQTTDeserialize_unsuback(&mypacketid, c->readbuf, c->readbuf_size) == 1)
|
if (MQTTDeserialize_unsuback(&mypacketid, c->readbuf, c->readbuf_size) == 1)
|
||||||
rc = 0;
|
rc = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rc = FAILURE;
|
rc = FAILURE;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
#if defined(MQTT_TASK)
|
#if defined(MQTT_TASK)
|
||||||
MutexUnlock(&c->mutex);
|
MutexUnlock(&c->mutex);
|
||||||
@ -500,7 +499,7 @@ exit:
|
|||||||
int MQTTPublish(MQTTClient* c, const char* topicName, MQTTMessage* message)
|
int MQTTPublish(MQTTClient* c, const char* topicName, MQTTMessage* message)
|
||||||
{
|
{
|
||||||
int rc = FAILURE;
|
int rc = FAILURE;
|
||||||
Timer timer;
|
Timer timer;
|
||||||
MQTTString topic = MQTTString_initializer;
|
MQTTString topic = MQTTString_initializer;
|
||||||
topic.cstring = (char *)topicName;
|
topic.cstring = (char *)topicName;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
@ -516,14 +515,14 @@ int MQTTPublish(MQTTClient* c, const char* topicName, MQTTMessage* message)
|
|||||||
|
|
||||||
if (message->qos == QOS1 || message->qos == QOS2)
|
if (message->qos == QOS1 || message->qos == QOS2)
|
||||||
message->id = getNextPacketId(c);
|
message->id = getNextPacketId(c);
|
||||||
|
|
||||||
len = MQTTSerialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id,
|
len = MQTTSerialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id,
|
||||||
topic, (unsigned char*)message->payload, message->payloadlen);
|
topic, (unsigned char*)message->payload, message->payloadlen);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) // send the subscribe packet
|
if ((rc = sendPacket(c, len, &timer)) != SUCCESSS) // send the subscribe packet
|
||||||
goto exit; // there was a problem
|
goto exit; // there was a problem
|
||||||
|
|
||||||
if (message->qos == QOS1)
|
if (message->qos == QOS1)
|
||||||
{
|
{
|
||||||
if (waitfor(c, PUBACK, &timer) == PUBACK)
|
if (waitfor(c, PUBACK, &timer) == PUBACK)
|
||||||
@ -548,7 +547,7 @@ int MQTTPublish(MQTTClient* c, const char* topicName, MQTTMessage* message)
|
|||||||
else
|
else
|
||||||
rc = FAILURE;
|
rc = FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
#if defined(MQTT_TASK)
|
#if defined(MQTT_TASK)
|
||||||
MutexUnlock(&c->mutex);
|
MutexUnlock(&c->mutex);
|
||||||
@ -558,7 +557,7 @@ exit:
|
|||||||
|
|
||||||
|
|
||||||
int MQTTDisconnect(MQTTClient* c)
|
int MQTTDisconnect(MQTTClient* c)
|
||||||
{
|
{
|
||||||
int rc = FAILURE;
|
int rc = FAILURE;
|
||||||
Timer timer; // we might wait for incomplete incoming publishes to complete
|
Timer timer; // we might wait for incomplete incoming publishes to complete
|
||||||
int len = 0;
|
int len = 0;
|
||||||
@ -572,7 +571,7 @@ int MQTTDisconnect(MQTTClient* c)
|
|||||||
len = MQTTSerialize_disconnect(c->buf, c->buf_size);
|
len = MQTTSerialize_disconnect(c->buf, c->buf_size);
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
rc = sendPacket(c, len, &timer); // send the disconnect packet
|
rc = sendPacket(c, len, &timer); // send the disconnect packet
|
||||||
|
|
||||||
c->isconnected = 0;
|
c->isconnected = 0;
|
||||||
|
|
||||||
#if defined(MQTT_TASK)
|
#if defined(MQTT_TASK)
|
||||||
|
@ -119,8 +119,6 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
int rem_length = 0;
|
int rem_length = 0;
|
||||||
MQTTHeader header = {0};
|
MQTTHeader header = {0};
|
||||||
int strindex = 0;
|
|
||||||
|
|
||||||
header.byte = buf[index++];
|
header.byte = buf[index++];
|
||||||
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
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;
|
unsigned char sessionPresent, connack_rc;
|
||||||
if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1)
|
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;
|
break;
|
||||||
case PUBLISH:
|
case PUBLISH:
|
||||||
@ -141,7 +139,7 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
MQTTString topicName = MQTTString_initializer;
|
MQTTString topicName = MQTTString_initializer;
|
||||||
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
||||||
&payload, &payloadlen, buf, buflen) == 1)
|
&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);
|
topicName, payload, payloadlen);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -153,7 +151,7 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
unsigned char packettype, dup;
|
unsigned char packettype, dup;
|
||||||
unsigned short packetid;
|
unsigned short packetid;
|
||||||
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
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;
|
break;
|
||||||
case SUBACK:
|
case SUBACK:
|
||||||
@ -162,20 +160,20 @@ char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
int maxcount = 1, count = 0;
|
int maxcount = 1, count = 0;
|
||||||
int grantedQoSs[1];
|
int grantedQoSs[1];
|
||||||
if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 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;
|
break;
|
||||||
case UNSUBACK:
|
case UNSUBACK:
|
||||||
{
|
{
|
||||||
unsigned short packetid;
|
unsigned short packetid;
|
||||||
if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1)
|
if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1)
|
||||||
strindex = MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);
|
MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PINGREQ:
|
case PINGREQ:
|
||||||
case PINGRESP:
|
case PINGRESP:
|
||||||
case DISCONNECT:
|
case DISCONNECT:
|
||||||
strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return strbuf;
|
return strbuf;
|
||||||
@ -187,7 +185,6 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
int rem_length = 0;
|
int rem_length = 0;
|
||||||
MQTTHeader header = {0};
|
MQTTHeader header = {0};
|
||||||
int strindex = 0;
|
|
||||||
|
|
||||||
header.byte = buf[index++];
|
header.byte = buf[index++];
|
||||||
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
index += MQTTPacket_decodeBuf(&buf[index], &rem_length);
|
||||||
@ -199,7 +196,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
MQTTPacket_connectData data;
|
MQTTPacket_connectData data;
|
||||||
int rc;
|
int rc;
|
||||||
if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1)
|
if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1)
|
||||||
strindex = MQTTStringFormat_connect(strbuf, strbuflen, &data);
|
MQTTStringFormat_connect(strbuf, strbuflen, &data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PUBLISH:
|
case PUBLISH:
|
||||||
@ -210,7 +207,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
MQTTString topicName = MQTTString_initializer;
|
MQTTString topicName = MQTTString_initializer;
|
||||||
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,
|
||||||
&payload, &payloadlen, buf, buflen) == 1)
|
&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);
|
topicName, payload, payloadlen);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -222,7 +219,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
unsigned char packettype, dup;
|
unsigned char packettype, dup;
|
||||||
unsigned short packetid;
|
unsigned short packetid;
|
||||||
if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)
|
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;
|
break;
|
||||||
case SUBSCRIBE:
|
case SUBSCRIBE:
|
||||||
@ -234,7 +231,7 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
int requestedQoSs[1];
|
int requestedQoSs[1];
|
||||||
if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count,
|
if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count,
|
||||||
topicFilters, requestedQoSs, buf, buflen) == 1)
|
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;
|
break;
|
||||||
case UNSUBSCRIBE:
|
case UNSUBSCRIBE:
|
||||||
@ -244,13 +241,13 @@ char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf,
|
|||||||
int maxcount = 1, count = 0;
|
int maxcount = 1, count = 0;
|
||||||
MQTTString topicFilters[1];
|
MQTTString topicFilters[1];
|
||||||
if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 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;
|
break;
|
||||||
case PINGREQ:
|
case PINGREQ:
|
||||||
case PINGRESP:
|
case PINGRESP:
|
||||||
case DISCONNECT:
|
case DISCONNECT:
|
||||||
strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strbuf[strbuflen] = '\0';
|
strbuf[strbuflen] = '\0';
|
||||||
|
@ -19,14 +19,14 @@
|
|||||||
#define MQTTSUBSCRIBE_H_
|
#define MQTTSUBSCRIBE_H_
|
||||||
|
|
||||||
#if !defined(DLLImport)
|
#if !defined(DLLImport)
|
||||||
#define DLLImport
|
#define DLLImport
|
||||||
#endif
|
#endif
|
||||||
#if !defined(DLLExport)
|
#if !defined(DLLExport)
|
||||||
#define DLLExport
|
#define DLLExport
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DLLExport int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid,
|
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,
|
DLLExport int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid,
|
||||||
int maxcount, int* count, MQTTString topicFilters[], int requestedQoSs[], unsigned char* buf, int len);
|
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
|
* @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,
|
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;
|
unsigned char *ptr = buf;
|
||||||
MQTTHeader header = {0};
|
MQTTHeader header = {0};
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include "mqtt_interface.h"
|
#include "mqtt_interface.h"
|
||||||
#include "wizchip_conf.h"
|
#include "wizchip_conf.h"
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
unsigned long MilliTimer;
|
unsigned long MilliTimer;
|
||||||
|
|
||||||
@ -122,12 +123,15 @@ void NewNetwork(Network* n, int sn) {
|
|||||||
* that contains the configuration information for the Network.
|
* that contains the configuration information for the Network.
|
||||||
* buffer : pointer to a read buffer.
|
* buffer : pointer to a read buffer.
|
||||||
* len : buffer length.
|
* 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))
|
if((getSn_SR(n->my_socket) == SOCK_ESTABLISHED) && (getSn_RX_RSR(n->my_socket)>0))
|
||||||
return recv(n->my_socket, buffer, len);
|
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.
|
* that contains the configuration information for the Network.
|
||||||
* buffer : pointer to a read buffer.
|
* buffer : pointer to a read buffer.
|
||||||
* len : buffer length.
|
* 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)
|
if(getSn_SR(n->my_socket) == SOCK_ESTABLISHED)
|
||||||
return send(n->my_socket, buffer, len);
|
return send(n->my_socket, buffer, len);
|
||||||
|
|
||||||
|
return SOCK_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -160,9 +167,9 @@ void w5x00_disconnect(Network* n)
|
|||||||
* ip : server iP.
|
* ip : server iP.
|
||||||
* port : server port.
|
* 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);
|
socket(n->my_socket,Sn_MR_TCP,myport,0);
|
||||||
connect(n->my_socket,ip,port);
|
connect(n->my_socket,ip,port);
|
||||||
|
@ -212,6 +212,13 @@ int main(void)
|
|||||||
#ifndef __MQTT_INTERFACE_H_
|
#ifndef __MQTT_INTERFACE_H_
|
||||||
#define __MQTT_INTERFACE_H_
|
#define __MQTT_INTERFACE_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief MQTT MilliTimer handler
|
* @brief MQTT MilliTimer handler
|
||||||
* @note MUST BE register to your system 1m Tick timer handler
|
* @note MUST BE register to your system 1m Tick timer handler
|
||||||
@ -234,8 +241,8 @@ typedef struct Network Network;
|
|||||||
struct Network
|
struct Network
|
||||||
{
|
{
|
||||||
int my_socket;
|
int my_socket;
|
||||||
int (*mqttread) (Network*, unsigned char*, int, int);
|
int (*mqttread) (Network*, unsigned char*, int, long);
|
||||||
int (*mqttwrite) (Network*, unsigned char*, int, int);
|
int (*mqttwrite) (Network*, unsigned char*, int, long);
|
||||||
void (*disconnect) (Network*);
|
void (*disconnect) (Network*);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -251,10 +258,14 @@ int TimerLeftMS(Timer*);
|
|||||||
/*
|
/*
|
||||||
* @brief Network interface porting
|
* @brief Network interface porting
|
||||||
*/
|
*/
|
||||||
int w5x00_read(Network*, unsigned char*, int);
|
int w5x00_read(Network*, unsigned char*, int, long);
|
||||||
int w5x00_write(Network*, unsigned char*, int);
|
int w5x00_write(Network*, unsigned char*, int, long);
|
||||||
void w5x00_disconnect(Network*);
|
void w5x00_disconnect(Network*);
|
||||||
void NewNetwork(Network* n, int sn);
|
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_
|
#endif //__MQTT_INTERFACE_H_
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#ifndef _SNMP_H_
|
#ifndef _SNMP_H_
|
||||||
#define _SNMP_H_
|
#define _SNMP_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
// SNMP Debug Message (dump) Enable
|
// SNMP Debug Message (dump) Enable
|
||||||
#define _SNMP_DEBUG_
|
#define _SNMP_DEBUG_
|
||||||
|
|
||||||
@ -111,4 +115,8 @@ void SNMP_time_handler(void);
|
|||||||
uint32_t getSNMPTimeTick(void);
|
uint32_t getSNMPTimeTick(void);
|
||||||
void currentUptime(void *ptr, uint8_t *len);
|
void currentUptime(void *ptr, uint8_t *len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#ifndef _SNMP_CUSTOM_H_
|
#ifndef _SNMP_CUSTOM_H_
|
||||||
#define _SNMP_CUSTOM_H_
|
#define _SNMP_CUSTOM_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@ -30,4 +34,8 @@ void initTable();
|
|||||||
/* SNMP Trap: warmStart(1) */
|
/* SNMP Trap: warmStart(1) */
|
||||||
void initial_Trap(uint8_t * managerIP, uint8_t * agentIP);
|
void initial_Trap(uint8_t * managerIP, uint8_t * agentIP);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
#ifndef SNTP_H_
|
#ifndef SNTP_H_
|
||||||
#define SNTP_H_
|
#define SNTP_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -65,4 +69,8 @@ int8_t SNTP_run(datetime *time);
|
|||||||
tstamp changedatetime_to_seconds(void);
|
tstamp changedatetime_to_seconds(void);
|
||||||
void calcdatetime(tstamp seconds);
|
void calcdatetime(tstamp seconds);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* SNTP_H_ */
|
#endif /* SNTP_H_ */
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
#ifndef __NETUTIL_H__
|
#ifndef __NETUTIL_H__
|
||||||
#define __NETUTIL_H__
|
#define __NETUTIL_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define SYSTEM_LITTLE_ENDIAN
|
#define SYSTEM_LITTLE_ENDIAN
|
||||||
@ -16,4 +20,8 @@ uint32_t htonl(uint32_t hostlong);
|
|||||||
uint32_t ntohs(uint16_t netshort);
|
uint32_t ntohs(uint16_t netshort);
|
||||||
uint32_t ntohl(uint32_t netlong);
|
uint32_t ntohl(uint32_t netlong);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
#ifndef __TFTP_H__
|
#ifndef __TFTP_H__
|
||||||
#define __TFTP_H__
|
#define __TFTP_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define F_APP_TFTP
|
#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_read_request(uint32_t server_ip, uint8_t *filename);
|
||||||
void tftp_timeout_handler(void);
|
void tftp_timeout_handler(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /*__TFTP_H__ */
|
#endif /*__TFTP_H__ */
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
#ifndef __HTTPPARSER_H__
|
#ifndef __HTTPPARSER_H__
|
||||||
#define __HTTPPARSER_H__
|
#define __HTTPPARSER_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
//#define _HTTPPARSER_DEBUG_
|
//#define _HTTPPARSER_DEBUG_
|
||||||
|
|
||||||
#define HTTP_SERVER_PORT 80 /**< HTTP server well-known port number */
|
#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 mid(char* src, char* s1, char* s2, char* sub);
|
||||||
void inet_addr_(uint8_t * addr, uint8_t * ip);
|
void inet_addr_(uint8_t * addr, uint8_t * ip);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* end of __HTTPPARSER_H__ */
|
#endif /* end of __HTTPPARSER_H__ */
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
#ifndef __HTTPSERVER_H__
|
#ifndef __HTTPSERVER_H__
|
||||||
#define __HTTPSERVER_H__
|
#define __HTTPSERVER_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
// HTTP Server debug message enable
|
// HTTP Server debug message enable
|
||||||
#define _HTTPSERVER_DEBUG_
|
#define _HTTPSERVER_DEBUG_
|
||||||
|
|
||||||
@ -100,4 +104,8 @@ uint8_t display_reg_webContent_list(void);
|
|||||||
void httpServer_time_handler(void);
|
void httpServer_time_handler(void);
|
||||||
uint32_t get_httpServer_timecount(void);
|
uint32_t get_httpServer_timecount(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,6 +12,10 @@
|
|||||||
#ifndef __HTTPUTIL_H__
|
#ifndef __HTTPUTIL_H__
|
||||||
#define __HTTPUTIL_H__
|
#define __HTTPUTIL_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "httpServer.h"
|
#include "httpServer.h"
|
||||||
#include "httpParser.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_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);
|
uint8_t predefined_set_cgi_processor(uint8_t * uri_name, uint8_t * uri, uint8_t * buf, uint16_t * len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user