Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8ebd860
Merge pull request #51 from javakys/master
javakys Jul 25, 2018
b8e3c63
Revert "MDIO added"
javakys Jul 25, 2018
15b79ef
Merge pull request #52 from Wiznet/revert-51-master
javakys Jul 25, 2018
3939dc4
fixed unused variables warning
newAM Aug 13, 2018
72d9df5
Merge pull request #53 from newAM/unused-fix
khj098765 Sep 9, 2018
a832944
Missing braces #55
Sep 9, 2018
28e8a16
#36 structure alignment.
Sep 9, 2018
c69d27b
#49 Adding support for C++
Sep 10, 2018
183daf1
@c69d27b modify a typing error
irinakim12 Sep 27, 2018
2163c8b
modify wizchip_conf.c
irinakim12 Sep 27, 2018
bac969f
#36 structure alignment.
irinakim12 Sep 27, 2018
6676770
setSn_RXMEM_SIZE
irinakim12 Sep 27, 2018
8dde2af
fixed -Wsizeof-pointer-memaccess warning
newAM Oct 6, 2018
d1f87bd
fixed several warnings in mqtt_interface
newAM Oct 7, 2018
cafc29e
fixed typing errors
newAM Oct 7, 2018
c2940b0
cleaned up unused variable warning for _WIZCHIP_ >= W5200
newAM Oct 7, 2018
21f6528
cleaned up maybe-unitialized warning
newAM Oct 7, 2018
b70a532
removed unused variable strindex from MQTTFormat_toServerString and M…
newAM Oct 7, 2018
db469a1
fixed incompatible pointer type warning
newAM Oct 7, 2018
b135a73
fixed typos in DHCP files
newAM Oct 7, 2018
dc10163
Merge pull request #58 from newAM/sizeof_pointer_memaccess_fix
khj098765 Oct 17, 2018
4de4aa0
Merge pull request #60 from newAM/mqtt_interface_fix
khj098765 Oct 17, 2018
f3a575c
Merge pull request #63 from newAM/wizchip_init_unused_variable_warnin…
khj098765 Oct 17, 2018
435cedc
Merge pull request #61 from newAM/extern_c_cleanup
khj098765 Oct 17, 2018
4b2cd30
Merge pull request #65 from newAM/maybeuinitialized_fix
khj098765 Oct 17, 2018
ca53487
Merge pull request #67 from newAM/remove_strindex
khj098765 Oct 17, 2018
c5be3a8
Merge pull request #68 from newAM/dhcp_typo_fix
khj098765 Oct 17, 2018
c2356c8
1.For W5100S,The array size is one byte smaller
yaozhiman Dec 1, 2018
dac948e
Fixed issue 69
midnightcow Jan 28, 2019
798d505
Merge pull request #75 from Wiznet/issue69
midnightcow Jan 29, 2019
dd05361
Merge pull request #71 from yaozhiman/master
midnightcow Feb 7, 2019
81e94dc
#77 fix by request.
Feb 22, 2019
c166849
fix w5100s bug
HubertXie Apr 9, 2019
16657be
Update w5100s.h
HubertXie Apr 10, 2019
40dc8d1
Merge pull request #78 from HubertXie/master
irinakim12 Apr 11, 2019
fe116b3
Update dns.c
zhouchuanfu Apr 14, 2019
7dd9ef0
typing error
May 29, 2019
890a73f
Merge pull request #83 from Wiznet/W5300
irinakim12 May 29, 2019
3016459
Fix MQTTClient unaligned access on ARM when using -Os
hubmartin Aug 7, 2019
dacf22c
Fix regression KEEPALIVEAUTO Not supported in W5100, W5200
KoynovStas Sep 3, 2019
b58bfbd
modify comparing DHCP server ip addres
WIZbecky Oct 8, 2019
863973b
Merge pull request #89 from Wiznet/modifyDHCP
WIZbecky Oct 8, 2019
af704a0
Merge pull request #85 from hubmartin/master
midnightcow Nov 6, 2019
47dec41
Merge pull request #79 from zhouchuanfu/master
midnightcow Nov 6, 2019
587d26e
Merge pull request #86 from KoynovStas/Fix_KEEPALIVEAUTO_for_w5100_w5200
midnightcow Nov 6, 2019
84f4b6d
add multicast example
WIZbecky Dec 27, 2019
96857e8
Merge pull request #93 from Wiznet/addApplicationmulticast
WIZbecky Dec 27, 2019
18aeb30
Added a break to remove compiler warning.
MrDiba Jan 27, 2020
1fadc59
Merge pull request #95 from MrDiba/patch-1
Feb 3, 2020
de18368
Modify getSn_TXBUF_SIZE(s)*1024 - > getSn_TxMAX(s)
WIZbecky Feb 17, 2020
0bad15a
Added each of the devices have to has a different XID.
Feb 18, 2020
a9141a7
Modify wizchip_clrinterrupt() to set Sn_IR for clearing SIR.
WIZbecky Feb 27, 2020
cbf5b6e
Merge pull request #96 from Wiznet/FIxedwiz_clrinterrupt()
Mar 2, 2020
66c27e9
changed base address
javakys Apr 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 56 additions & 120 deletions Application/loopback/loopback.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
/*******************************************************************************************************************************************************
* Copyright ��I 2016 <WIZnet Co.,Ltd.>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ����Software����),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

* THE SOFTWARE IS PROVIDED ����AS IS����, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************************************************************************/
#include <stdio.h>
#include "loopback.h"
#include "socket.h"
#include "wizchip_conf.h"

#if LOOPBACK_MODE == LOOPBACK_MAIN_NOBLCOK
Expand All @@ -33,30 +21,32 @@ int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port)
if(getSn_IR(sn) & Sn_IR_CON)
{
#ifdef _LOOPBACK_DEBUG_
getSn_DIPR(sn, destip);
destport = getSn_DPORT(sn);
printf("%d:Connected - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
getSn_DIPR(sn, destip);
destport = getSn_DPORT(sn);

printf("%d:Connected - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
#endif
setSn_IR(sn,Sn_IR_CON);
setSn_IR(sn,Sn_IR_CON);
}
if((size = getSn_RX_RSR(sn)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur.
if((size = getSn_RX_RSR(sn)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur.
{
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
ret = recv(sn, buf, size);

if(ret <= 0) return ret; // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY.
sentsize = 0;

while(size != sentsize)
{
ret = send(sn, buf+sentsize, size-sentsize);
if(ret < 0)
{
close(sn);
return ret;
}
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
}
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
ret = recv(sn, buf, size);

if(ret <= 0) return ret; // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY.
size = (uint16_t) ret;
sentsize = 0;

while(size != sentsize)
{
ret = send(sn, buf+sentsize, size-sentsize);
if(ret < 0)
{
close(sn);
return ret;
}
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
}
}
break;
case SOCK_CLOSE_WAIT :
Expand All @@ -70,7 +60,7 @@ int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port)
break;
case SOCK_INIT :
#ifdef _LOOPBACK_DEBUG_
printf("%d:Listen, TCP server loopback, port [%d]\r\n", sn, port);
printf("%d:Listen, TCP server loopback, port [%d]\r\n", sn, port);
#endif
if( (ret = listen(sn)) != SOCK_OK) return ret;
break;
Expand Down Expand Up @@ -102,7 +92,7 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
// uint16_t destport = 5000;

// Port number for TCP client (will be increased)
uint16_t any_port = 50000;
static uint16_t any_port = 50000;

// Socket Status Transitions
// Check the W5500 Socket n status register (Sn_SR, The 'Sn_SR' controlled by Sn_CR command or Packet send/recv status)
Expand All @@ -112,35 +102,36 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
if(getSn_IR(sn) & Sn_IR_CON) // Socket n interrupt register mask; TCP CON interrupt = connection with peer is successful
{
#ifdef _LOOPBACK_DEBUG_
printf("%d:Connected to - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
printf("%d:Connected to - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
#endif
setSn_IR(sn, Sn_IR_CON); // this interrupt should be write the bit cleared to '1'
setSn_IR(sn, Sn_IR_CON); // this interrupt should be write the bit cleared to '1'
}

//////////////////////////////////////////////////////////////////////////////////////////////
// Data Transaction Parts; Handle the [data receive and send] process
//////////////////////////////////////////////////////////////////////////////////////////////
if((size = getSn_RX_RSR(sn)) > 0) // Sn_RX_RSR: Socket n Received Size Register, Receiving data length
if((size = getSn_RX_RSR(sn)) > 0) // Sn_RX_RSR: Socket n Received Size Register, Receiving data length
{
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE; // DATA_BUF_SIZE means user defined buffer size (array)
ret = recv(sn, buf, size); // Data Receive process (H/W Rx socket buffer -> User's buffer)

if(ret <= 0) return ret; // If the received data length <= 0, receive failed and process end
sentsize = 0;

// Data sentsize control
while(size != sentsize)
{
ret = send(sn, buf+sentsize, size-sentsize); // Data send process (User's buffer -> Destination through H/W Tx socket buffer)
if(ret < 0) // Send Error occurred (sent data length < 0)
{
close(sn); // socket close
return ret;
}
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
}
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE; // DATA_BUF_SIZE means user defined buffer size (array)
ret = recv(sn, buf, size); // Data Receive process (H/W Rx socket buffer -> User's buffer)

if(ret <= 0) return ret; // If the received data length <= 0, receive failed and process end
size = (uint16_t) ret;
sentsize = 0;

// Data sentsize control
while(size != sentsize)
{
ret = send(sn, buf+sentsize, size-sentsize); // Data send process (User's buffer -> Destination through H/W Tx socket buffer)
if(ret < 0) // Send Error occurred (sent data length < 0)
{
close(sn); // socket close
return ret;
}
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
break;

case SOCK_CLOSE_WAIT :
Expand All @@ -155,16 +146,19 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo

case SOCK_INIT :
#ifdef _LOOPBACK_DEBUG_
printf("%d:Try to connect to the %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport);
printf("%d:Try to connect to the %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport);
#endif
if( (ret = connect(sn, destip, destport)) != SOCK_OK) return ret; // Try to TCP connect to the TCP server (destination)
if( (ret = connect(sn, destip, destport)) != SOCK_OK) return ret; // Try to TCP connect to the TCP server (destination)
break;

case SOCK_CLOSED:
close(sn);
if((ret=socket(sn, Sn_MR_TCP, any_port++, 0x00)) != sn) return ret; // TCP socket open with 'any_port' port number
close(sn);
if((ret=socket(sn, Sn_MR_TCP, any_port++, 0x00)) != sn){
if(any_port == 0xffff) any_port = 50000;
return ret; // TCP socket open with 'any_port' port number
}
#ifdef _LOOPBACK_DEBUG_
//printf("%d:TCP client loopback start\r\n",sn);
//printf("%d:TCP client loopback start\r\n",sn);
//printf("%d:Socket opened\r\n",sn);
#endif
break;
Expand Down Expand Up @@ -228,62 +222,4 @@ int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port)
return 1;
}

int32_t loopback_iperf(uint8_t sn, uint8_t* buf, uint16_t port)
{
int32_t ret;
uint16_t size = 0;

#ifdef _LOOPBACK_DEBUG_
uint8_t destip[4];
uint16_t destport;
#endif

switch(getSn_SR(sn))
{
case SOCK_ESTABLISHED :
if(getSn_IR(sn) & Sn_IR_CON)
{
#ifdef _LOOPBACK_DEBUG_
getSn_DIPR(sn, destip);
destport = getSn_DPORT(sn);
printf("%d:Connected - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
#endif
setSn_IR(sn,Sn_IR_CON);
}
if((size = getSn_RX_RSR(sn)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur.
{
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
ret = recv(sn, buf, size);
}
break;
case SOCK_CLOSE_WAIT :
#ifdef _LOOPBACK_DEBUG_
//printf("%d:CloseWait\r\n",sn);
#endif
if((ret = disconnect(sn)) != SOCK_OK) return ret;
#ifdef _LOOPBACK_DEBUG_
printf("%d:Socket Closed\r\n", sn);
#endif
break;
case SOCK_INIT :
#ifdef _LOOPBACK_DEBUG_
printf("%d:Listen, TCP server loopback, port [%d]\r\n", sn, port);
#endif
if( (ret = listen(sn)) != SOCK_OK) return ret;
break;
case SOCK_CLOSED:
#ifdef _LOOPBACK_DEBUG_
//printf("%d:TCP server loopback start\r\n",sn);
#endif
if((ret = socket(sn, Sn_MR_TCP, port, 0x00)) != sn) return ret;
#ifdef _LOOPBACK_DEBUG_
//printf("%d:Socket opened\r\n",sn);
#endif
break;
default:
break;
}
return 1;
}

#endif
25 changes: 7 additions & 18 deletions Application/loopback/loopback.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
/*******************************************************************************************************************************************************
* Copyright ��I 2016 <WIZnet Co.,Ltd.>
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ����Software����),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

* THE SOFTWARE IS PROVIDED ����AS IS����, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************************************************************************************************************************************************/
#ifndef _LOOPBACK_H_
#define _LOOPBACK_H_

#include <stdint.h>
#include "socket.h"
#include "W7500x_wztoe.h"
#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

/* Loopback test debug message printout enable */
#define _LOOPBACK_DEBUG_
Expand All @@ -43,7 +31,8 @@ int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destpo
/* UDP Loopback test example */
int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port);

/* TCP Server loopback test example for performance test (iperf, receive only) */
int32_t loopback_iperf(uint8_t sn, uint8_t* buf, uint16_t port);
#ifdef __cplusplus
}
#endif

#endif
113 changes: 113 additions & 0 deletions Application/multicast/multicast.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include "multicast.h"
#include <stdio.h>
#include "socket.h"
#include "wizchip_conf.h"


int32_t multicast_loopback(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port)
{
int32_t ret;
uint16_t size, sentsize;
uint8_t destip[4];
uint16_t destport, port=3000;

switch(getSn_SR(sn))
{
case SOCK_UDP :
if((size = getSn_RX_RSR(sn)) > 0)
{
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport);
if(ret <= 0)
{
#ifdef _MULTICAST_DEBUG_
printf("%d: recvfrom error. %ld\r\n",sn,ret);
#endif
return ret;
}
size = (uint16_t) ret;
sentsize = 0;
while(sentsize != size)
{
ret = sendto(sn, buf+sentsize, size-sentsize, destip, destport);
if(ret < 0)
{
#ifdef _MULTICAST_DEBUG_
printf("%d: sendto error. %ld\r\n",sn,ret);
#endif
return ret;
}
sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
}
}

break;
case SOCK_CLOSED:
#ifdef _MULTICAST_DEBUG_
printf("%d:Multicast Loopback start\r\n",sn);
#endif
setSn_DIPR(0, multicast_ip);
setSn_DPORT(0, multicast_port);
if((ret = socket(sn, Sn_MR_UDP, port, Sn_MR_MULTI)) != sn)
return ret;
#ifdef _MULTICAST_DEBUG_
printf("%d:Opened, UDP Multicast Socket\r\n", sn);
printf("%d:Multicast Group IP - %d.%d.%d.%d\r\n", sn, multicast_ip[0], multicast_ip[1], multicast_ip[2], multicast_ip[3]);
printf("%d:Multicast Group Port - %d\r\n", sn, multicast_port);
#endif
break;
default :
break;
}
return 1;
}

int32_t multicast_recv(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port)
{
int32_t ret;
uint16_t size, port=3000;
uint8_t destip[4];
uint16_t destport;

switch(getSn_SR(sn))
{
case SOCK_UDP :
if((size = getSn_RX_RSR(sn)) > 0)
{
if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport);
if(ret <= 0)
{
#ifdef _MULTICAST_DEBUG_
printf("%d: recvfrom error. %ld\r\n",sn,ret);
#endif
return ret;
}
size = (uint16_t) ret;
#ifdef _MULTICAST_DEBUG_
printf("\r\nrecv size : %d\r\n", size);
for(int i=0; i<size; i++)
printf("%c", buf[i]);
printf("\r\n");
#endif
}
break;
case SOCK_CLOSED:
#ifdef _MULTICAST_DEBUG_
printf("%d:Multicast Recv start\r\n",sn);
#endif
setSn_DIPR(sn, multicast_ip);
setSn_DPORT(sn, multicast_port);
if((ret = socket(sn, Sn_MR_UDP, port, Sn_MR_MULTI)) != sn)
return ret;
#ifdef _MULTICAST_DEBUG_
printf("%d:Opened, UDP Multicast Socket\r\n", sn);
printf("%d:Multicast Group IP - %d.%d.%d.%d\r\n", sn, multicast_ip[0], multicast_ip[1], multicast_ip[2], multicast_ip[3]);
printf("%d:Multicast Group Port - %d\r\n", sn, multicast_port);
#endif
break;
default :
break;
}
return 1;
}
Loading