NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
NetworkInterface.h@43:09ea32f2eb54, 2016-02-24 (annotated)
- Committer:
- Christopher Haster
- Date:
- Wed Feb 24 22:04:19 2016 -0600
- Branch:
- api-changes
- Revision:
- 43:09ea32f2eb54
- Parent:
- 42:49893d13c432
- Child:
- 45:c8aca7c1e93f
Responded to feedback in API decisions
- Removed small .cpp files
- Added null _iface checks
- Matched mbed coding standard
- Removed setTimeout/getTimeout
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; |
sam_grove | 3:167dd63981b6 | 77 | |
Christopher Haster |
21:35ed15069189 | 78 | /** Get the current status of the interface |
geky | 31:7f15b95f2a1d | 79 | * @return true if connected |
bridadan | 1:291a9d61e58a | 80 | */ |
Christopher Haster |
42:49893d13c432 | 81 | virtual bool isConnected(); |
Christopher Haster |
41:3ec1c97e9bbf | 82 | |
geky | 31:7f15b95f2a1d | 83 | /** Looks up the specified host's IP address |
geky | 31:7f15b95f2a1d | 84 | * @param name URL of host |
geky | 31:7f15b95f2a1d | 85 | * @param ip Buffer to hold IP address, must be at least SOCK_IP_SIZE |
geky | 31:7f15b95f2a1d | 86 | * @return 0 on success |
geky | 31:7f15b95f2a1d | 87 | */ |
geky | 31:7f15b95f2a1d | 88 | int32_t getHostByName(const char *name, char *ip); |
Christopher Haster |
21:35ed15069189 | 89 | |
Christopher Haster |
26:9774a2edad71 | 90 | protected: |
Christopher Haster |
26:9774a2edad71 | 91 | NetworkInterface(); |
Christopher Haster |
21:35ed15069189 | 92 | |
Christopher Haster |
25:ed7b2a52e8ac | 93 | friend class Socket; |
Christopher Haster |
21:35ed15069189 | 94 | |
Christopher Haster |
21:35ed15069189 | 95 | /** Internally create a socket |
Christopher Haster |
21:35ed15069189 | 96 | * @param proto The type of socket to open, SOCK_TCP or SOCK_UDP |
Christopher Haster |
21:35ed15069189 | 97 | * @return The allocated socket |
Christopher Haster |
21:35ed15069189 | 98 | */ |
Christopher Haster |
21:35ed15069189 | 99 | virtual SocketInterface *createSocket(socket_protocol_t proto) = 0; |
geky | 30:3cc78f5db99d | 100 | |
Christopher Haster |
21:35ed15069189 | 101 | /** Internally destroy a socket |
Christopher Haster |
21:35ed15069189 | 102 | * @param socket An allocated SocketInterface |
Christopher Haster |
21:35ed15069189 | 103 | * @returns 0 on success |
bridadan | 11:47c32687a44c | 104 | */ |
Christopher Haster |
21:35ed15069189 | 105 | virtual void destroySocket(SocketInterface *socket) = 0; |
Christopher Haster |
21:35ed15069189 | 106 | |
Christopher Haster |
21:35ed15069189 | 107 | private: |
Christopher Haster |
42:49893d13c432 | 108 | char _ip_address[NS_IP_SIZE]; |
Christopher Haster |
42:49893d13c432 | 109 | char _network_mask[NS_IP_SIZE]; |
Christopher Haster |
42:49893d13c432 | 110 | char _gateway[NS_IP_SIZE]; |
bridadan | 1:291a9d61e58a | 111 | }; |
bridadan | 1:291a9d61e58a | 112 | |
bridadan | 1:291a9d61e58a | 113 | #endif |