Fork for fixes

Committer:
ivo_n
Date:
Sat Sep 26 08:31:41 2020 +0000
Revision:
22:a0b1d0e6d237
Parent:
21:4dcda56a9820
Everything seems to work

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 9:a156d3de5647 1 /*
hudakz 9:a156d3de5647 2 UipEthernet.h - Arduino implementation of a UIP wrapper class.
hudakz 9:a156d3de5647 3 Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de>
hudakz 9:a156d3de5647 4 All rights reserved.
hudakz 9:a156d3de5647 5
hudakz 9:a156d3de5647 6 Modified (ported to mbed) by Zoltan Hudak <hudakz@inbox.com>
hudakz 9:a156d3de5647 7
hudakz 9:a156d3de5647 8 This program is free software: you can redistribute it and/or modify
hudakz 9:a156d3de5647 9 it under the terms of the GNU General Public License as published by
hudakz 9:a156d3de5647 10 the Free Software Foundation, either version 3 of the License, or
hudakz 9:a156d3de5647 11 (at your option) any later version.
hudakz 9:a156d3de5647 12
hudakz 9:a156d3de5647 13 This program is distributed in the hope that it will be useful,
hudakz 9:a156d3de5647 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
hudakz 9:a156d3de5647 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
hudakz 9:a156d3de5647 16 GNU General Public License for more details.
hudakz 9:a156d3de5647 17
hudakz 9:a156d3de5647 18 You should have received a copy of the GNU General Public License
hudakz 9:a156d3de5647 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
hudakz 9:a156d3de5647 20 */
hudakz 11:647d53d146f1 21 #ifndef UIPETHERNET_h
hudakz 11:647d53d146f1 22 #define UIPETHERNET_h
hudakz 9:a156d3de5647 23
ivo_n 19:58e840279555 24 #define UIPETHERNET_DEBUG
hudakz 9:a156d3de5647 25 //#define UIPETHERNET_DEBUG_CHKSUM
ivo_n 18:a19f7933d5c7 26 #define UIPETHERNET_DEBUG_UDP
ivo_n 19:58e840279555 27 #define UIPETHERNET_DEBUG_CLIENT
ivo_n 19:58e840279555 28 #define UIP_LOGGING 1
hudakz 9:a156d3de5647 29 #include "mbed.h"
hudakz 9:a156d3de5647 30 #include "DhcpClient.h"
hudakz 9:a156d3de5647 31 #include "IpAddress.h"
hudakz 11:647d53d146f1 32 #include "utility/Enc28j60Eth.h"
hudakz 9:a156d3de5647 33 #include "TcpClient.h"
hudakz 9:a156d3de5647 34 #include "TcpServer.h"
hudakz 9:a156d3de5647 35 #include "UdpSocket.h"
hudakz 9:a156d3de5647 36
hudakz 9:a156d3de5647 37 extern "C"
hudakz 9:a156d3de5647 38 {
hudakz 9:a156d3de5647 39 #include "utility/uip_timer.h"
hudakz 9:a156d3de5647 40 #include "utility/uip.h"
hudakz 14:7648334eb41b 41 #include "utility/util.h"
hudakz 9:a156d3de5647 42 }
hudakz 9:a156d3de5647 43
hudakz 9:a156d3de5647 44 class UipEthernet
hudakz 9:a156d3de5647 45 {
hudakz 9:a156d3de5647 46 public:
hudakz 9:a156d3de5647 47 static UipEthernet* ethernet;
hudakz 9:a156d3de5647 48 static IpAddress dnsServerAddress;
hudakz 11:647d53d146f1 49 Enc28j60Eth enc28j60Eth;
hudakz 9:a156d3de5647 50
hudakz 9:a156d3de5647 51 UipEthernet (const uint8_t mac[6], PinName mosi, PinName miso, PinName sck, PinName cs);
hudakz 9:a156d3de5647 52
hudakz 15:53715cc81c63 53 int connect(unsigned long timeout = 60);
hudakz 13:95c00132cd98 54 void disconnect();
hudakz 9:a156d3de5647 55 void set_network(uint8_t octet1, uint8_t octet2, uint8_t octet3, uint8_t octet4);
hudakz 9:a156d3de5647 56 void set_network(IpAddress ip);
hudakz 9:a156d3de5647 57 void set_network(IpAddress ip, IpAddress dns);
hudakz 9:a156d3de5647 58 void set_network(IpAddress ip, IpAddress dns, IpAddress gateway);
hudakz 9:a156d3de5647 59 void set_network(IpAddress ip, IpAddress dns, IpAddress gateway, IpAddress subnet);
hudakz 11:647d53d146f1 60 void set_network(const char *ip_address, const char *netmask, const char *gateway);
hudakz 9:a156d3de5647 61 void tick();
hudakz 9:a156d3de5647 62 IpAddress localIP();
hudakz 9:a156d3de5647 63 IpAddress subnetMask();
hudakz 9:a156d3de5647 64 IpAddress gatewayIP();
hudakz 9:a156d3de5647 65 IpAddress dnsServerIP();
hudakz 9:a156d3de5647 66 const char* get_ip_address();
hudakz 16:269f652b4d0b 67 void get_ip_address(SocketAddress* addr);
hudakz 9:a156d3de5647 68 const char* get_netmask();
hudakz 16:269f652b4d0b 69 void get_netmask(SocketAddress* addr);
hudakz 9:a156d3de5647 70 const char* get_gateway();
hudakz 16:269f652b4d0b 71 void get_gateway(SocketAddress* addr);
ivo_n 21:4dcda56a9820 72 const char* get_mqttFromDhcp();
hudakz 9:a156d3de5647 73 static uint16_t chksum(uint16_t sum, const uint8_t* data, uint16_t len);
hudakz 9:a156d3de5647 74 static uint16_t ipchksum();
hudakz 11:647d53d146f1 75 bool stoip4(const char *ip4addr, size_t len, void *dest);
hudakz 9:a156d3de5647 76 private:
hudakz 9:a156d3de5647 77 uint8_t *const _mac;
hudakz 9:a156d3de5647 78 IpAddress _ip;
hudakz 9:a156d3de5647 79 IpAddress _dns;
hudakz 9:a156d3de5647 80 IpAddress _gateway;
hudakz 9:a156d3de5647 81 IpAddress _subnet;
hudakz 9:a156d3de5647 82 static memhandle inPacket;
hudakz 9:a156d3de5647 83 static memhandle uipPacket;
hudakz 9:a156d3de5647 84 static uint8_t uipHeaderLen;
hudakz 9:a156d3de5647 85 static uint8_t packetState;
hudakz 9:a156d3de5647 86 DhcpClient dhcpClient;
hudakz 9:a156d3de5647 87 Timer periodicTimer;
hudakz 9:a156d3de5647 88 void init(const uint8_t* mac);
hudakz 9:a156d3de5647 89 bool network_send();
hudakz 9:a156d3de5647 90 friend class TcpServer;
hudakz 9:a156d3de5647 91 friend class TcpClient;
hudakz 9:a156d3de5647 92 friend class UdpSocket;
hudakz 9:a156d3de5647 93 #if UIP_UDP
hudakz 9:a156d3de5647 94 uint16_t upper_layer_chksum(uint8_t proto);
hudakz 9:a156d3de5647 95 #endif
hudakz 9:a156d3de5647 96 friend uint16_t uip_ipchksum();
hudakz 9:a156d3de5647 97 friend uint16_t uip_tcpchksum();
hudakz 9:a156d3de5647 98 friend uint16_t uip_udpchksum();
hudakz 9:a156d3de5647 99 friend void uipclient_appcall();
hudakz 9:a156d3de5647 100 friend void uipudp_appcall();
hudakz 9:a156d3de5647 101
hudakz 9:a156d3de5647 102 #if UIP_CONF_IPV6
hudakz 9:a156d3de5647 103 uint16_t uip_icmp6chksum();
hudakz 9:a156d3de5647 104 #endif
hudakz 9:a156d3de5647 105 };
hudakz 11:647d53d146f1 106
hudakz 9:a156d3de5647 107 #endif