NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
NetworkInterface.h@42:49893d13c432, 2016-02-23 (annotated)
- Committer:
- Christopher Haster
- Date:
- Tue Feb 23 05:07:02 2016 -0600
- Branch:
- api-changes
- Revision:
- 42:49893d13c432
- Parent:
- 41:3ec1c97e9bbf
- Child:
- 43:09ea32f2eb54
Standardized some C++ style things
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:d35446f60233 | 1 | /* NetworkInterface Base Class |
sam_grove | 0:d35446f60233 | 2 | * Copyright (c) 2015 ARM Limited |
sam_grove | 0:d35446f60233 | 3 | * |
sam_grove | 0:d35446f60233 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sam_grove | 0:d35446f60233 | 5 | * you may not use this file except in compliance with the License. |
sam_grove | 0:d35446f60233 | 6 | * You may obtain a copy of the License at |
sam_grove | 0:d35446f60233 | 7 | * |
sam_grove | 0:d35446f60233 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sam_grove | 0:d35446f60233 | 9 | * |
sam_grove | 0:d35446f60233 | 10 | * Unless required by applicable law or agreed to in writing, software |
sam_grove | 0:d35446f60233 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sam_grove | 0:d35446f60233 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sam_grove | 0:d35446f60233 | 13 | * See the License for the specific language governing permissions and |
sam_grove | 0:d35446f60233 | 14 | * limitations under the License. |
sam_grove | 0:d35446f60233 | 15 | */ |
sam_grove | 3:167dd63981b6 | 16 | |
Christopher Haster |
21:35ed15069189 | 17 | #ifndef NETWORK_INTERFACE_H |
Christopher Haster |
21:35ed15069189 | 18 | #define NETWORK_INTERFACE_H |
bridadan | 1:291a9d61e58a | 19 | |
Christopher Haster |
42:49893d13c432 | 20 | #include "SocketInterface.h" |
sam_grove | 7:b147c08301be | 21 | #include "stdint.h" |
Christopher Haster |
42:49893d13c432 | 22 | |
Christopher Haster |
21:35ed15069189 | 23 | |
Christopher Haster |
42:49893d13c432 | 24 | /** Maximum storage needed for IP address and MAC addresses |
Christopher Haster |
42:49893d13c432 | 25 | */ |
Christopher Haster |
42:49893d13c432 | 26 | #define NS_IP_SIZE 16 |
Christopher Haster |
42:49893d13c432 | 27 | #define NS_MAC_SIZE 18 |
Christopher Haster |
28:163fbe3263f4 | 28 | |
bridadan | 11:47c32687a44c | 29 | |
Christopher Haster |
21:35ed15069189 | 30 | /** NetworkInterface class |
Christopher Haster |
21:35ed15069189 | 31 | * Common interface that is shared between all hardware that |
Christopher Haster |
21:35ed15069189 | 32 | * can connect to a network over IP. |
bridadan | 1:291a9d61e58a | 33 | */ |
sam_grove | 3:167dd63981b6 | 34 | class NetworkInterface |
sam_grove | 3:167dd63981b6 | 35 | { |
bridadan | 1:291a9d61e58a | 36 | public: |
Christopher Haster |
21:35ed15069189 | 37 | /** Enables DHCP and clears any static address |
Christopher Haster |
40:11d4a94df3f7 | 38 | * DHCP resolution does not occur until connect call |
Christopher Haster |
21:35ed15069189 | 39 | * DHCP is enabled by default |
Christopher Haster |
21:35ed15069189 | 40 | */ |
Christopher Haster |
40:11d4a94df3f7 | 41 | virtual void useDHCP(); |
Christopher Haster |
21:35ed15069189 | 42 | |
Christopher Haster |
21:35ed15069189 | 43 | /** Set the static IP address of the network interface |
Christopher Haster |
21:35ed15069189 | 44 | * @param ip Static IP address, copied internally |
bridadan | 1:291a9d61e58a | 45 | */ |
Christopher Haster |
21:35ed15069189 | 46 | virtual void setIPAddress(const char *ip); |
Christopher Haster |
21:35ed15069189 | 47 | |
Christopher Haster |
21:35ed15069189 | 48 | /** Set the static network mask of the network interface |
Christopher Haster |
21:35ed15069189 | 49 | * @param mask Static network mask, copied internally |
Christopher Haster |
21:35ed15069189 | 50 | */ |
Christopher Haster |
21:35ed15069189 | 51 | virtual void setNetworkMask(const char *mask); |
Christopher Haster |
21:35ed15069189 | 52 | |
Christopher Haster |
21:35ed15069189 | 53 | /** Set the static gateway of the network interface |
Christopher Haster |
21:35ed15069189 | 54 | * @param gateway Gateway address, copied internally |
Christopher Haster |
21:35ed15069189 | 55 | */ |
Christopher Haster |
21:35ed15069189 | 56 | virtual void setGateway(const char *gateway); |
Christopher Haster |
21:35ed15069189 | 57 | |
Christopher Haster |
21:35ed15069189 | 58 | /** Get the IP address |
Christopher Haster |
21:35ed15069189 | 59 | * @return IP address of the interface |
Christopher Haster |
21:35ed15069189 | 60 | */ |
Christopher Haster |
21:35ed15069189 | 61 | virtual const char *getIPAddress(); |
sam_grove | 3:167dd63981b6 | 62 | |
Christopher Haster |
21:35ed15069189 | 63 | /** Get the network mask |
Christopher Haster |
21:35ed15069189 | 64 | * @return Network mask of the interface |
sam_grove | 3:167dd63981b6 | 65 | */ |
Christopher Haster |
21:35ed15069189 | 66 | virtual const char *getNetworkMask(); |
Christopher Haster |
21:35ed15069189 | 67 | |
Christopher Haster |
21:35ed15069189 | 68 | /** Get the gateway |
Christopher Haster |
21:35ed15069189 | 69 | * @return Gateway address of the interface |
Christopher Haster |
21:35ed15069189 | 70 | */ |
Christopher Haster |
21:35ed15069189 | 71 | virtual const char *getGateway(); |
Christopher Haster |
21:35ed15069189 | 72 | |
Christopher Haster |
21:35ed15069189 | 73 | /** Get the current MAC address |
Christopher Haster |
21:35ed15069189 | 74 | * @return String MAC address of the interface |
Christopher Haster |
21:35ed15069189 | 75 | */ |
Christopher Haster |
21:35ed15069189 | 76 | virtual const char *getMACAddress() = 0; |
Christopher Haster |
41:3ec1c97e9bbf | 77 | |
Christopher Haster |
41:3ec1c97e9bbf | 78 | /** Set a timeout on network operations |
Christopher Haster |
41:3ec1c97e9bbf | 79 | * @param timeout Maximum time in milliseconds for socket operations |
Christopher Haster |
41:3ec1c97e9bbf | 80 | */ |
Christopher Haster |
41:3ec1c97e9bbf | 81 | virtual void setTimeout(uint32_t timeout); |
Christopher Haster |
41:3ec1c97e9bbf | 82 | |
Christopher Haster |
41:3ec1c97e9bbf | 83 | /** Get the current timeout on network operations |
Christopher Haster |
41:3ec1c97e9bbf | 84 | * @return Maximum time in milliseconds for socket operations |
Christopher Haster |
41:3ec1c97e9bbf | 85 | */ |
Christopher Haster |
41:3ec1c97e9bbf | 86 | virtual uint32_t getTimeout(); |
Christopher Haster |
41:3ec1c97e9bbf | 87 | |
sam_grove | 3:167dd63981b6 | 88 | |
Christopher Haster |
21:35ed15069189 | 89 | /** Get the current status of the interface |
geky | 31:7f15b95f2a1d | 90 | * @return true if connected |
bridadan | 1:291a9d61e58a | 91 | */ |
Christopher Haster |
42:49893d13c432 | 92 | virtual bool isConnected(); |
Christopher Haster |
41:3ec1c97e9bbf | 93 | |
geky | 31:7f15b95f2a1d | 94 | /** Looks up the specified host's IP address |
geky | 31:7f15b95f2a1d | 95 | * @param name URL of host |
geky | 31:7f15b95f2a1d | 96 | * @param ip Buffer to hold IP address, must be at least SOCK_IP_SIZE |
geky | 31:7f15b95f2a1d | 97 | * @return 0 on success |
geky | 31:7f15b95f2a1d | 98 | */ |
geky | 31:7f15b95f2a1d | 99 | int32_t getHostByName(const char *name, char *ip); |
Christopher Haster |
21:35ed15069189 | 100 | |
Christopher Haster |
26:9774a2edad71 | 101 | protected: |
Christopher Haster |
26:9774a2edad71 | 102 | NetworkInterface(); |
Christopher Haster |
21:35ed15069189 | 103 | |
Christopher Haster |
25:ed7b2a52e8ac | 104 | friend class Socket; |
Christopher Haster |
21:35ed15069189 | 105 | |
Christopher Haster |
21:35ed15069189 | 106 | /** Internally create a socket |
Christopher Haster |
21:35ed15069189 | 107 | * @param proto The type of socket to open, SOCK_TCP or SOCK_UDP |
Christopher Haster |
21:35ed15069189 | 108 | * @return The allocated socket |
Christopher Haster |
21:35ed15069189 | 109 | */ |
Christopher Haster |
21:35ed15069189 | 110 | virtual SocketInterface *createSocket(socket_protocol_t proto) = 0; |
geky | 30:3cc78f5db99d | 111 | |
Christopher Haster |
21:35ed15069189 | 112 | /** Internally destroy a socket |
Christopher Haster |
21:35ed15069189 | 113 | * @param socket An allocated SocketInterface |
Christopher Haster |
21:35ed15069189 | 114 | * @returns 0 on success |
bridadan | 11:47c32687a44c | 115 | */ |
Christopher Haster |
21:35ed15069189 | 116 | virtual void destroySocket(SocketInterface *socket) = 0; |
Christopher Haster |
21:35ed15069189 | 117 | |
Christopher Haster |
21:35ed15069189 | 118 | private: |
Christopher Haster |
42:49893d13c432 | 119 | char _ip_address[NS_IP_SIZE]; |
Christopher Haster |
42:49893d13c432 | 120 | char _network_mask[NS_IP_SIZE]; |
Christopher Haster |
42:49893d13c432 | 121 | char _gateway[NS_IP_SIZE]; |
Christopher Haster |
41:3ec1c97e9bbf | 122 | uint32_t _timeout; |
bridadan | 1:291a9d61e58a | 123 | }; |
bridadan | 1:291a9d61e58a | 124 | |
bridadan | 1:291a9d61e58a | 125 | #endif |