Added RAW sockets.
Fork of WIZnetInterface by
Revision 30:3b0481541a06, committed 2017-12-19
- Comitter:
- Dollyparton
- Date:
- Tue Dec 19 12:49:35 2017 +0000
- Parent:
- 29:c91884bd2713
- Child:
- 31:e49acd942048
- Commit message:
- First version.
Changed in this revision
--- a/Socket/Endpoint.cpp Tue Nov 17 06:35:55 2015 +0000
+++ b/Socket/Endpoint.cpp Tue Dec 19 12:49:35 2017 +0000
@@ -21,7 +21,7 @@
Endpoint::Endpoint()
{
//printf("reset_address\r\n");
- reset_address();
+ reset_address();
}
Endpoint::~Endpoint() {}
--- a/Socket/TCPSocketConnection.cpp Tue Nov 17 06:35:55 2015 +0000
+++ b/Socket/TCPSocketConnection.cpp Tue Dec 19 12:49:35 2017 +0000
@@ -50,6 +50,23 @@
return 0;
}
+
+// Geminate Changes
+
+int TCPSocketConnection::get_DHAR0(void)
+{
+ return( eth->get_DHAR0(_sock_fd));
+}
+
+
+int TCPSocketConnection::get_DHAR1(void)
+{
+ return( eth->get_DHAR1(_sock_fd));
+}
+
+// End Changes
+
+
bool TCPSocketConnection::is_connected(void)
{
// force update recent state.
--- a/Socket/TCPSocketConnection.h Tue Nov 17 06:35:55 2015 +0000
+++ b/Socket/TCPSocketConnection.h Tue Dec 19 12:49:35 2017 +0000
@@ -39,6 +39,12 @@
\return 0 on success, -1 on failure.
*/
int connect(const char* host, const int port);
+
+ // Geminate Changes. Added methods to retrieve the Destination MAC that is
+ // returned from an ARP request.
+ int get_DHAR0(void);
+ int get_DHAR1(void);
+ // End Changes.
/** Check if the socket is connected
\return true if connected, false otherwise.
--- a/arch/int/W7500x_toe.cpp Tue Nov 17 06:35:55 2015 +0000
+++ b/arch/int/W7500x_toe.cpp Tue Dec 19 12:49:35 2017 +0000
@@ -112,6 +112,8 @@
Timer t;
t.reset();
t.start();
+ //timeout_ms=700;
+ //printf("waiting %d\r\n", timeout_ms);
while(!is_connected(socket)) {
if (t.read_ms() > timeout_ms) {
return false;
@@ -141,6 +143,23 @@
return false;
}
+// Geminate Changes.
+int WIZnet_Chip::get_DHAR0(int socket)
+{
+ //sreg<uint32_t>(socket, Sn_RCR, 0x0000000);
+ reg_wr<uint32_t>(Sn_RCR, 0x00000008);
+
+ return( sreg<uint32_t>(socket, Sn_DHAR0));
+}
+
+
+int WIZnet_Chip::get_DHAR1(int socket)
+{
+ return( sreg<uint32_t>(socket, Sn_DHAR1));
+}
+
+// End Changes.
+
bool WIZnet_Chip::is_connected(int socket)
{
@@ -258,7 +277,7 @@
}
int WIZnet_Chip::send(int socket, const char * str, int len)
-{
+{
if (socket < 0) {
return -1;
}
@@ -297,6 +316,47 @@
return len;
}
+
+int WIZnet_Chip::sendRaw(int socket, const char * str, int len)
+{
+ if (socket < 0) {
+ return -1;
+ }
+
+ uint16_t ptr = sreg<uint16_t>(socket, Sn_TX_WR);
+ uint32_t sn_tx_base = W7500x_TXMEM_BASE + (uint32_t)(socket<<18);
+
+ for(int i=0; i<len; i++)
+ *(volatile uint8_t *)(sn_tx_base + ((ptr+i)&0xFFFF)) = str[i];
+
+ sreg<uint16_t>(socket, Sn_TX_WR, ptr + len);
+ scmd(socket, SEND_MAC);
+
+ uint8_t tmp_Sn_IR;
+ while (( (tmp_Sn_IR = sreg<uint8_t>(socket, Sn_IR)) & INT_SEND_OK) != INT_SEND_OK) {
+ // @Jul.10, 2014 fix contant name, and udp sendto function.
+ switch (sreg<uint8_t>(socket, Sn_SR)) {
+ case SOCK_CLOSED :
+ close(socket);
+ return 0;
+ //break;
+ case SOCK_UDP :
+ // ARP timeout is possible.
+ if ((tmp_Sn_IR & INT_TIMEOUT) == INT_TIMEOUT) {
+ sreg<uint8_t>(socket, Sn_ICR, INT_TIMEOUT);
+ return 0;
+ }
+ break;
+ default :
+ break;
+ }
+ }
+
+ sreg<uint8_t>(socket, Sn_ICR, INT_SEND_OK);
+
+ return len;
+}
+
int WIZnet_Chip::recv(int socket, char* buf, int len)
{
if (socket < 0) {
--- a/arch/int/W7500x_toe.h Tue Nov 17 06:35:55 2015 +0000
+++ b/arch/int/W7500x_toe.h Tue Dec 19 12:49:35 2017 +0000
@@ -48,6 +48,12 @@
#define Sn_IR (0x0020) //--Sn_ISR
#define Sn_SR (0x0030)
#define Sn_PORT (0x0114)
+// Geminate Changes
+#define Sn_DHAR0 (0x0118)
+#define Sn_DHAR1 (0x011C)
+#define Sn_RCR (0x6044)
+#define Sn_RTR (0x6040)
+// end
#define Sn_DIPR (0x0124)
#define Sn_DPORT (0x0120)
#define Sn_RXBUF_SIZE (0x0200)
@@ -74,6 +80,7 @@
CLOSED = 0,
TCP = 1,
UDP = 2,
+ RAW = 4
};
enum Command {
@@ -113,6 +120,11 @@
};
WIZnet_Chip();
+
+ // Geminate Changes.
+ int get_DHAR0(int socket);
+ int get_DHAR1(int socket);
+ // End Changes.
/*
* Set MAC Address to W7500x_TOE
@@ -188,6 +200,7 @@
* @param len string length
*/
int send(int socket, const char * str, int len);
+ int sendRaw(int socket, const char * str, int len);
int recv(int socket, char* buf, int len);
