mbed IP library over Ethernet with setName and setNewAddress
Dependencies: Socket lwip-eth lwip-sys lwip
Dependents: JRO_CR2 JRO_DDSv2 JRO_DDSv2_rev2019
Fork of EthernetInterface by
EthernetInterface.h@48:303f4d8389a1, 2015-02-23 (annotated)
- Committer:
- miguelcordero191
- Date:
- Mon Feb 23 20:36:52 2015 +0000
- Revision:
- 48:303f4d8389a1
- Parent:
- 47:3b0a475eb1ad
Any change was done;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 3:f5776537f27f | 1 | /* EthernetInterface.h */ |
donatien | 3:f5776537f27f | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
donatien | 3:f5776537f27f | 3 | * |
donatien | 3:f5776537f27f | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
donatien | 3:f5776537f27f | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
donatien | 3:f5776537f27f | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
donatien | 3:f5776537f27f | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
donatien | 3:f5776537f27f | 8 | * furnished to do so, subject to the following conditions: |
donatien | 3:f5776537f27f | 9 | * |
donatien | 3:f5776537f27f | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
donatien | 3:f5776537f27f | 11 | * substantial portions of the Software. |
donatien | 3:f5776537f27f | 12 | * |
donatien | 3:f5776537f27f | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
donatien | 3:f5776537f27f | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
donatien | 3:f5776537f27f | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
donatien | 3:f5776537f27f | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 3:f5776537f27f | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
donatien | 3:f5776537f27f | 18 | */ |
donatien | 3:f5776537f27f | 19 | |
donatien | 3:f5776537f27f | 20 | #ifndef ETHERNETINTERFACE_H_ |
donatien | 3:f5776537f27f | 21 | #define ETHERNETINTERFACE_H_ |
donatien | 3:f5776537f27f | 22 | |
mbed_official | 44:de796e2a5e98 | 23 | #if !defined(TARGET_LPC1768) && !defined(TARGET_LPC4088) && !defined(TARGET_K64F) && !defined(TARGET_RZ_A1H) |
mbed_official | 37:926eb6517318 | 24 | #error The Ethernet Interface library is not supported on this target |
emilmont | 23:5d5b40c4378b | 25 | #endif |
emilmont | 23:5d5b40c4378b | 26 | |
donatien | 3:f5776537f27f | 27 | #include "rtos.h" |
donatien | 3:f5776537f27f | 28 | #include "lwip/netif.h" |
donatien | 3:f5776537f27f | 29 | |
donatien | 4:9a52c802be61 | 30 | /** Interface using Ethernet to connect to an IP-based network |
donatien | 3:f5776537f27f | 31 | * |
donatien | 3:f5776537f27f | 32 | */ |
emilmont | 14:cec293071eed | 33 | class EthernetInterface { |
donatien | 3:f5776537f27f | 34 | public: |
donatien | 4:9a52c802be61 | 35 | /** Initialize the interface with DHCP. |
donatien | 4:9a52c802be61 | 36 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
donatien | 4:9a52c802be61 | 37 | * \return 0 on success, a negative number on failure |
donatien | 4:9a52c802be61 | 38 | */ |
emilmont | 14:cec293071eed | 39 | static int init(); //With DHCP |
donatien | 3:f5776537f27f | 40 | |
donatien | 4:9a52c802be61 | 41 | /** Initialize the interface with a static IP address. |
donatien | 4:9a52c802be61 | 42 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
donatien | 4:9a52c802be61 | 43 | * \param ip the IP address to use |
donatien | 4:9a52c802be61 | 44 | * \param mask the IP address mask |
donatien | 4:9a52c802be61 | 45 | * \param gateway the gateway to use |
donatien | 4:9a52c802be61 | 46 | * \return 0 on success, a negative number on failure |
donatien | 4:9a52c802be61 | 47 | */ |
emilmont | 14:cec293071eed | 48 | static int init(const char* ip, const char* mask, const char* gateway); |
donatien | 3:f5776537f27f | 49 | |
miguelcordero191 | 46:4cb91998b200 | 50 | /** Change the interface with a new static IP address. |
miguelcordero191 | 46:4cb91998b200 | 51 | * Change the interface and configure it with the following static configuration (no connection at this point). |
miguelcordero191 | 46:4cb91998b200 | 52 | * \param ip the IP address to use |
miguelcordero191 | 46:4cb91998b200 | 53 | * \param mask the IP address mask |
miguelcordero191 | 46:4cb91998b200 | 54 | * \param gateway the gateway to use |
miguelcordero191 | 46:4cb91998b200 | 55 | * \return 0 on success, a negative number on failure |
miguelcordero191 | 46:4cb91998b200 | 56 | */ |
miguelcordero191 | 46:4cb91998b200 | 57 | static int setNewAddr(const char* ip, const char* mask, const char* gateway); |
miguelcordero191 | 47:3b0a475eb1ad | 58 | |
miguelcordero191 | 48:303f4d8389a1 | 59 | /** Set the network name for this device. Apply this before calling 'connect'. |
miguelcordero191 | 47:3b0a475eb1ad | 60 | * |
miguelcordero191 | 47:3b0a475eb1ad | 61 | * \param myname is the name to assign for this node. |
miguelcordero191 | 47:3b0a475eb1ad | 62 | * Only the first 32 characters will be used if the |
miguelcordero191 | 47:3b0a475eb1ad | 63 | * name is longer. |
miguelcordero191 | 47:3b0a475eb1ad | 64 | * Only '0'-'9', 'A'-'Z', 'a'-'z' are accepted, |
miguelcordero191 | 47:3b0a475eb1ad | 65 | * any others are converted to '-'. |
miguelcordero191 | 47:3b0a475eb1ad | 66 | * \return 0 on success, a negative number on failure. |
miguelcordero191 | 47:3b0a475eb1ad | 67 | */ |
miguelcordero191 | 47:3b0a475eb1ad | 68 | static int setName(const char * myname); |
miguelcordero191 | 46:4cb91998b200 | 69 | |
donatien | 4:9a52c802be61 | 70 | /** Connect |
donatien | 4:9a52c802be61 | 71 | * Bring the interface up, start DHCP if needed. |
emilmont | 30:4d7d7dc8485f | 72 | * \param timeout_ms timeout in ms (default: (15)s). |
donatien | 4:9a52c802be61 | 73 | * \return 0 on success, a negative number on failure |
donatien | 4:9a52c802be61 | 74 | */ |
miguelcordero191 | 47:3b0a475eb1ad | 75 | |
emilmont | 27:2124eae946f3 | 76 | static int connect(unsigned int timeout_ms=15000); |
donatien | 4:9a52c802be61 | 77 | |
donatien | 4:9a52c802be61 | 78 | /** Disconnect |
donatien | 4:9a52c802be61 | 79 | * Bring the interface down |
donatien | 4:9a52c802be61 | 80 | * \return 0 on success, a negative number on failure |
donatien | 4:9a52c802be61 | 81 | */ |
emilmont | 14:cec293071eed | 82 | static int disconnect(); |
donatien | 3:f5776537f27f | 83 | |
emilmont | 27:2124eae946f3 | 84 | /** Get the MAC address of your Ethernet interface |
emilmont | 27:2124eae946f3 | 85 | * \return a pointer to a string containing the MAC address |
emilmont | 27:2124eae946f3 | 86 | */ |
emilmont | 27:2124eae946f3 | 87 | static char* getMACAddress(); |
emilmont | 27:2124eae946f3 | 88 | |
emilmont | 27:2124eae946f3 | 89 | /** Get the IP address of your Ethernet interface |
emilmont | 27:2124eae946f3 | 90 | * \return a pointer to a string containing the IP address |
emilmont | 27:2124eae946f3 | 91 | */ |
emilmont | 14:cec293071eed | 92 | static char* getIPAddress(); |
mbed_official | 35:cba86db5ab96 | 93 | |
mbed_official | 35:cba86db5ab96 | 94 | /** Get the Gateway address of your Ethernet interface |
mbed_official | 35:cba86db5ab96 | 95 | * \return a pointer to a string containing the Gateway address |
mbed_official | 35:cba86db5ab96 | 96 | */ |
mbed_official | 35:cba86db5ab96 | 97 | static char* getGateway(); |
mbed_official | 35:cba86db5ab96 | 98 | |
mbed_official | 35:cba86db5ab96 | 99 | /** Get the Network mask of your Ethernet interface |
mbed_official | 35:cba86db5ab96 | 100 | * \return a pointer to a string containing the Network mask |
mbed_official | 35:cba86db5ab96 | 101 | */ |
mbed_official | 35:cba86db5ab96 | 102 | static char* getNetworkMask(); |
donatien | 3:f5776537f27f | 103 | }; |
donatien | 3:f5776537f27f | 104 | |
emilmont | 15:fd9597f1b81b | 105 | #include "TCPSocketConnection.h" |
emilmont | 15:fd9597f1b81b | 106 | #include "TCPSocketServer.h" |
emilmont | 17:b7a3766f6253 | 107 | |
emilmont | 20:0d9ae7845bfe | 108 | #include "Endpoint.h" |
donatien | 3:f5776537f27f | 109 | #include "UDPSocket.h" |
donatien | 3:f5776537f27f | 110 | |
donatien | 3:f5776537f27f | 111 | #endif /* ETHERNETINTERFACE_H_ */ |