Hostname Attempt
Dependencies: Socket lwip-eth lwip-sys lwip
Fork of EthernetInterface by
EthernetInterface.h@56:0642ca02cebc, 2018-05-10 (annotated)
- Committer:
- mmdonatti
- Date:
- Thu May 10 18:20:26 2018 +0000
- Revision:
- 56:0642ca02cebc
- Parent:
- 55:ffc295afecc5
Tentative to make hostname work (not yet)
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 | 52:f81b90d9a441 | 23 | #if !defined(TARGET_LPC1768) && !defined(TARGET_LPC4088) && !defined(TARGET_LPC4088_DM) && !defined(TARGET_K64F) && !defined(TARGET_RZ_A1H) && !defined(TARGET_VK_RZ_A1H) && !defined(TARGET_STM32F4) |
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 | |
mmdonatti | 55:ffc295afecc5 | 30 | #define DP8_VALID_LINK (1 << 0) /**< 1=Link active */ |
mmdonatti | 55:ffc295afecc5 | 31 | |
donatien | 4:9a52c802be61 | 32 | /** Interface using Ethernet to connect to an IP-based network |
donatien | 3:f5776537f27f | 33 | * |
donatien | 3:f5776537f27f | 34 | */ |
emilmont | 14:cec293071eed | 35 | class EthernetInterface { |
donatien | 3:f5776537f27f | 36 | public: |
donatien | 4:9a52c802be61 | 37 | /** Initialize the interface with DHCP. |
donatien | 4:9a52c802be61 | 38 | * Initialize the interface and configure it to use DHCP (no connection at this point). |
donatien | 4:9a52c802be61 | 39 | * \return 0 on success, a negative number on failure |
donatien | 4:9a52c802be61 | 40 | */ |
emilmont | 14:cec293071eed | 41 | static int init(); //With DHCP |
donatien | 3:f5776537f27f | 42 | |
donatien | 4:9a52c802be61 | 43 | /** Initialize the interface with a static IP address. |
donatien | 4:9a52c802be61 | 44 | * Initialize the interface and configure it with the following static configuration (no connection at this point). |
donatien | 4:9a52c802be61 | 45 | * \param ip the IP address to use |
donatien | 4:9a52c802be61 | 46 | * \param mask the IP address mask |
donatien | 4:9a52c802be61 | 47 | * \param gateway the gateway to use |
donatien | 4:9a52c802be61 | 48 | * \return 0 on success, a negative number on failure |
donatien | 4:9a52c802be61 | 49 | */ |
emilmont | 14:cec293071eed | 50 | static int init(const char* ip, const char* mask, const char* gateway); |
donatien | 3:f5776537f27f | 51 | |
donatien | 4:9a52c802be61 | 52 | /** Connect |
donatien | 4:9a52c802be61 | 53 | * Bring the interface up, start DHCP if needed. |
emilmont | 30:4d7d7dc8485f | 54 | * \param timeout_ms timeout in ms (default: (15)s). |
donatien | 4:9a52c802be61 | 55 | * \return 0 on success, a negative number on failure |
donatien | 4:9a52c802be61 | 56 | */ |
emilmont | 27:2124eae946f3 | 57 | static int connect(unsigned int timeout_ms=15000); |
donatien | 4:9a52c802be61 | 58 | |
donatien | 4:9a52c802be61 | 59 | /** Disconnect |
donatien | 4:9a52c802be61 | 60 | * Bring the interface down |
donatien | 4:9a52c802be61 | 61 | * \return 0 on success, a negative number on failure |
donatien | 4:9a52c802be61 | 62 | */ |
emilmont | 14:cec293071eed | 63 | static int disconnect(); |
donatien | 3:f5776537f27f | 64 | |
mmdonatti | 55:ffc295afecc5 | 65 | /** is_connected |
mmdonatti | 55:ffc295afecc5 | 66 | * |
mmdonatti | 55:ffc295afecc5 | 67 | * Determine if the interface is up and connected. |
mmdonatti | 55:ffc295afecc5 | 68 | * |
mmdonatti | 55:ffc295afecc5 | 69 | * \example |
mmdonatti | 55:ffc295afecc5 | 70 | * if (eth.is_connected()) |
mmdonatti | 55:ffc295afecc5 | 71 | * ethLED = 1; |
mmdonatti | 55:ffc295afecc5 | 72 | * else |
mmdonatti | 55:ffc295afecc5 | 73 | * ethLED = 0; |
mmdonatti | 55:ffc295afecc5 | 74 | * |
mmdonatti | 55:ffc295afecc5 | 75 | * \return true if connected, false if not connected. |
mmdonatti | 55:ffc295afecc5 | 76 | */ |
mmdonatti | 55:ffc295afecc5 | 77 | static bool is_connected(void); |
mmdonatti | 55:ffc295afecc5 | 78 | |
emilmont | 27:2124eae946f3 | 79 | /** Get the MAC address of your Ethernet interface |
emilmont | 27:2124eae946f3 | 80 | * \return a pointer to a string containing the MAC address |
emilmont | 27:2124eae946f3 | 81 | */ |
emilmont | 27:2124eae946f3 | 82 | static char* getMACAddress(); |
emilmont | 27:2124eae946f3 | 83 | |
emilmont | 27:2124eae946f3 | 84 | /** Get the IP address of your Ethernet interface |
emilmont | 27:2124eae946f3 | 85 | * \return a pointer to a string containing the IP address |
emilmont | 27:2124eae946f3 | 86 | */ |
emilmont | 14:cec293071eed | 87 | static char* getIPAddress(); |
mbed_official | 35:cba86db5ab96 | 88 | |
mbed_official | 35:cba86db5ab96 | 89 | /** Get the Gateway address of your Ethernet interface |
mbed_official | 35:cba86db5ab96 | 90 | * \return a pointer to a string containing the Gateway address |
mbed_official | 35:cba86db5ab96 | 91 | */ |
mbed_official | 35:cba86db5ab96 | 92 | static char* getGateway(); |
mbed_official | 35:cba86db5ab96 | 93 | |
mbed_official | 35:cba86db5ab96 | 94 | /** Get the Network mask of your Ethernet interface |
mbed_official | 35:cba86db5ab96 | 95 | * \return a pointer to a string containing the Network mask |
mbed_official | 35:cba86db5ab96 | 96 | */ |
mbed_official | 35:cba86db5ab96 | 97 | static char* getNetworkMask(); |
mmdonatti | 55:ffc295afecc5 | 98 | |
mmdonatti | 55:ffc295afecc5 | 99 | /** setName |
mmdonatti | 55:ffc295afecc5 | 100 | * |
mmdonatti | 55:ffc295afecc5 | 101 | * Set the network name for this device. Apply this before |
mmdonatti | 55:ffc295afecc5 | 102 | * calling 'connect'. |
mmdonatti | 55:ffc295afecc5 | 103 | * |
mmdonatti | 55:ffc295afecc5 | 104 | * \param myname is the name to assign for this node. |
mmdonatti | 55:ffc295afecc5 | 105 | * Only the first 32 characters will be used if the |
mmdonatti | 55:ffc295afecc5 | 106 | * name is longer. |
mmdonatti | 55:ffc295afecc5 | 107 | * Only '0'-'9', 'A'-'Z', 'a'-'z' are accepted, |
mmdonatti | 55:ffc295afecc5 | 108 | * any others are converted to '-'. |
mmdonatti | 55:ffc295afecc5 | 109 | * \return 0 on success, a negative number on failure. |
mmdonatti | 55:ffc295afecc5 | 110 | */ |
mmdonatti | 55:ffc295afecc5 | 111 | static int setName(const char * myname); |
mmdonatti | 55:ffc295afecc5 | 112 | |
mmdonatti | 55:ffc295afecc5 | 113 | uint32_t mii_read_data(void); |
mmdonatti | 55:ffc295afecc5 | 114 | |
mmdonatti | 55:ffc295afecc5 | 115 | char* getName(); |
mmdonatti | 55:ffc295afecc5 | 116 | |
donatien | 3:f5776537f27f | 117 | }; |
donatien | 3:f5776537f27f | 118 | |
emilmont | 15:fd9597f1b81b | 119 | #include "TCPSocketConnection.h" |
emilmont | 15:fd9597f1b81b | 120 | #include "TCPSocketServer.h" |
emilmont | 17:b7a3766f6253 | 121 | |
emilmont | 20:0d9ae7845bfe | 122 | #include "Endpoint.h" |
donatien | 3:f5776537f27f | 123 | #include "UDPSocket.h" |
donatien | 3:f5776537f27f | 124 | |
donatien | 3:f5776537f27f | 125 | #endif /* ETHERNETINTERFACE_H_ */ |