NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
NetworkInterface.h@41:3ec1c97e9bbf, 2016-02-23 (annotated)
- Committer:
- Christopher Haster
- Date:
- Tue Feb 23 04:01:38 2016 -0600
- Branch:
- api-changes
- Revision:
- 41:3ec1c97e9bbf
- Parent:
- 40:11d4a94df3f7
- Child:
- 42:49893d13c432
Moved timeout handling to setTimeout/getTimeout functions
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 | |
sam_grove | 7:b147c08301be | 20 | #include "stdint.h" |
bridadan | 11:47c32687a44c | 21 | #include "SocketInterface.h" |
Christopher Haster |
21:35ed15069189 | 22 | |
Christopher Haster |
28:163fbe3263f4 | 23 | #define SOCK_IP_SIZE 16 |
Christopher Haster |
28:163fbe3263f4 | 24 | |
bridadan | 11:47c32687a44c | 25 | |
Christopher Haster |
21:35ed15069189 | 26 | /** NetworkInterface class |
Christopher Haster |
21:35ed15069189 | 27 | * Common interface that is shared between all hardware that |
Christopher Haster |
21:35ed15069189 | 28 | * can connect to a network over IP. |
bridadan | 1:291a9d61e58a | 29 | */ |
sam_grove | 3:167dd63981b6 | 30 | class NetworkInterface |
sam_grove | 3:167dd63981b6 | 31 | { |
bridadan | 1:291a9d61e58a | 32 | public: |
Christopher Haster |
21:35ed15069189 | 33 | /** Enables DHCP and clears any static address |
Christopher Haster |
40:11d4a94df3f7 | 34 | * DHCP resolution does not occur until connect call |
Christopher Haster |
21:35ed15069189 | 35 | * DHCP is enabled by default |
Christopher Haster |
21:35ed15069189 | 36 | */ |
Christopher Haster |
40:11d4a94df3f7 | 37 | virtual void useDHCP(); |
Christopher Haster |
21:35ed15069189 | 38 | |
Christopher Haster |
21:35ed15069189 | 39 | /** Set the static IP address of the network interface |
Christopher Haster |
21:35ed15069189 | 40 | * @param ip Static IP address, copied internally |
bridadan | 1:291a9d61e58a | 41 | */ |
Christopher Haster |
21:35ed15069189 | 42 | virtual void setIPAddress(const char *ip); |
Christopher Haster |
21:35ed15069189 | 43 | |
Christopher Haster |
21:35ed15069189 | 44 | /** Set the static network mask of the network interface |
Christopher Haster |
21:35ed15069189 | 45 | * @param mask Static network mask, copied internally |
Christopher Haster |
21:35ed15069189 | 46 | */ |
Christopher Haster |
21:35ed15069189 | 47 | virtual void setNetworkMask(const char *mask); |
Christopher Haster |
21:35ed15069189 | 48 | |
Christopher Haster |
21:35ed15069189 | 49 | /** Set the static gateway of the network interface |
Christopher Haster |
21:35ed15069189 | 50 | * @param gateway Gateway address, copied internally |
Christopher Haster |
21:35ed15069189 | 51 | */ |
Christopher Haster |
21:35ed15069189 | 52 | virtual void setGateway(const char *gateway); |
Christopher Haster |
21:35ed15069189 | 53 | |
Christopher Haster |
21:35ed15069189 | 54 | /** Get the IP address |
Christopher Haster |
21:35ed15069189 | 55 | * @return IP address of the interface |
Christopher Haster |
21:35ed15069189 | 56 | */ |
Christopher Haster |
21:35ed15069189 | 57 | virtual const char *getIPAddress(); |
sam_grove | 3:167dd63981b6 | 58 | |
Christopher Haster |
21:35ed15069189 | 59 | /** Get the network mask |
Christopher Haster |
21:35ed15069189 | 60 | * @return Network mask of the interface |
sam_grove | 3:167dd63981b6 | 61 | */ |
Christopher Haster |
21:35ed15069189 | 62 | virtual const char *getNetworkMask(); |
Christopher Haster |
21:35ed15069189 | 63 | |
Christopher Haster |
21:35ed15069189 | 64 | /** Get the gateway |
Christopher Haster |
21:35ed15069189 | 65 | * @return Gateway address of the interface |
Christopher Haster |
21:35ed15069189 | 66 | */ |
Christopher Haster |
21:35ed15069189 | 67 | virtual const char *getGateway(); |
Christopher Haster |
21:35ed15069189 | 68 | |
Christopher Haster |
21:35ed15069189 | 69 | /** Get the current MAC address |
Christopher Haster |
21:35ed15069189 | 70 | * @return String MAC address of the interface |
Christopher Haster |
21:35ed15069189 | 71 | */ |
Christopher Haster |
21:35ed15069189 | 72 | virtual const char *getMACAddress() = 0; |
Christopher Haster |
41:3ec1c97e9bbf | 73 | |
Christopher Haster |
41:3ec1c97e9bbf | 74 | /** Set a timeout on network operations |
Christopher Haster |
41:3ec1c97e9bbf | 75 | * @param timeout Maximum time in milliseconds for socket operations |
Christopher Haster |
41:3ec1c97e9bbf | 76 | */ |
Christopher Haster |
41:3ec1c97e9bbf | 77 | virtual void setTimeout(uint32_t timeout); |
Christopher Haster |
41:3ec1c97e9bbf | 78 | |
Christopher Haster |
41:3ec1c97e9bbf | 79 | /** Get the current timeout on network operations |
Christopher Haster |
41:3ec1c97e9bbf | 80 | * @return Maximum time in milliseconds for socket operations |
Christopher Haster |
41:3ec1c97e9bbf | 81 | */ |
Christopher Haster |
41:3ec1c97e9bbf | 82 | virtual uint32_t getTimeout(); |
Christopher Haster |
41:3ec1c97e9bbf | 83 | |
sam_grove | 3:167dd63981b6 | 84 | |
Christopher Haster |
21:35ed15069189 | 85 | /** Get the current status of the interface |
geky | 31:7f15b95f2a1d | 86 | * @return true if connected |
bridadan | 1:291a9d61e58a | 87 | */ |
Christopher Haster |
23:1e86d9fb3d86 | 88 | virtual bool isConnected(void); |
Christopher Haster |
41:3ec1c97e9bbf | 89 | |
geky | 31:7f15b95f2a1d | 90 | /** Looks up the specified host's IP address |
geky | 31:7f15b95f2a1d | 91 | * @param name URL of host |
geky | 31:7f15b95f2a1d | 92 | * @param ip Buffer to hold IP address, must be at least SOCK_IP_SIZE |
geky | 31:7f15b95f2a1d | 93 | * @return 0 on success |
geky | 31:7f15b95f2a1d | 94 | */ |
geky | 31:7f15b95f2a1d | 95 | int32_t getHostByName(const char *name, char *ip); |
Christopher Haster |
21:35ed15069189 | 96 | |
Christopher Haster |
26:9774a2edad71 | 97 | protected: |
Christopher Haster |
26:9774a2edad71 | 98 | NetworkInterface(); |
Christopher Haster |
21:35ed15069189 | 99 | |
Christopher Haster |
25:ed7b2a52e8ac | 100 | friend class Socket; |
Christopher Haster |
21:35ed15069189 | 101 | |
Christopher Haster |
21:35ed15069189 | 102 | /** Internally create a socket |
Christopher Haster |
21:35ed15069189 | 103 | * @param proto The type of socket to open, SOCK_TCP or SOCK_UDP |
Christopher Haster |
21:35ed15069189 | 104 | * @return The allocated socket |
Christopher Haster |
21:35ed15069189 | 105 | */ |
Christopher Haster |
21:35ed15069189 | 106 | virtual SocketInterface *createSocket(socket_protocol_t proto) = 0; |
geky | 30:3cc78f5db99d | 107 | |
Christopher Haster |
21:35ed15069189 | 108 | /** Internally destroy a socket |
Christopher Haster |
21:35ed15069189 | 109 | * @param socket An allocated SocketInterface |
Christopher Haster |
21:35ed15069189 | 110 | * @returns 0 on success |
bridadan | 11:47c32687a44c | 111 | */ |
Christopher Haster |
21:35ed15069189 | 112 | virtual void destroySocket(SocketInterface *socket) = 0; |
Christopher Haster |
21:35ed15069189 | 113 | |
Christopher Haster |
21:35ed15069189 | 114 | private: |
Christopher Haster |
28:163fbe3263f4 | 115 | char _ip_address[SOCK_IP_SIZE]; |
Christopher Haster |
28:163fbe3263f4 | 116 | char _network_mask[SOCK_IP_SIZE]; |
Christopher Haster |
28:163fbe3263f4 | 117 | char _gateway[SOCK_IP_SIZE]; |
Christopher Haster |
41:3ec1c97e9bbf | 118 | uint32_t _timeout; |
bridadan | 1:291a9d61e58a | 119 | }; |
bridadan | 1:291a9d61e58a | 120 | |
bridadan | 1:291a9d61e58a | 121 | #endif |