NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
NetworkInterface.h@26:9774a2edad71, 2016-02-18 (annotated)
- Committer:
- Christopher Haster
- Date:
- Thu Feb 18 06:16:11 2016 -0600
- Branch:
- api-changes
- Revision:
- 26:9774a2edad71
- Parent:
- 25:ed7b2a52e8ac
- Child:
- 28:163fbe3263f4
Moved abstract constructors to protected regions
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 | |
bridadan | 11:47c32687a44c | 23 | |
Christopher Haster |
21:35ed15069189 | 24 | /** NetworkInterface class |
Christopher Haster |
21:35ed15069189 | 25 | * Common interface that is shared between all hardware that |
Christopher Haster |
21:35ed15069189 | 26 | * can connect to a network over IP. |
bridadan | 1:291a9d61e58a | 27 | */ |
sam_grove | 3:167dd63981b6 | 28 | class NetworkInterface |
sam_grove | 3:167dd63981b6 | 29 | { |
bridadan | 1:291a9d61e58a | 30 | public: |
Christopher Haster |
21:35ed15069189 | 31 | /** Enables DHCP and clears any static address |
Christopher Haster |
21:35ed15069189 | 32 | * DHCP is enabled by default |
Christopher Haster |
21:35ed15069189 | 33 | * @return 0 on success |
Christopher Haster |
21:35ed15069189 | 34 | */ |
Christopher Haster |
21:35ed15069189 | 35 | virtual int32_t useDHCP() = 0; |
Christopher Haster |
21:35ed15069189 | 36 | |
Christopher Haster |
21:35ed15069189 | 37 | /** Set the static IP address of the network interface |
Christopher Haster |
21:35ed15069189 | 38 | * @param ip Static IP address, copied internally |
bridadan | 1:291a9d61e58a | 39 | */ |
Christopher Haster |
21:35ed15069189 | 40 | virtual void setIPAddress(const char *ip); |
Christopher Haster |
21:35ed15069189 | 41 | |
Christopher Haster |
21:35ed15069189 | 42 | /** Set the static network mask of the network interface |
Christopher Haster |
21:35ed15069189 | 43 | * @param mask Static network mask, copied internally |
Christopher Haster |
21:35ed15069189 | 44 | */ |
Christopher Haster |
21:35ed15069189 | 45 | virtual void setNetworkMask(const char *mask); |
Christopher Haster |
21:35ed15069189 | 46 | |
Christopher Haster |
21:35ed15069189 | 47 | /** Set the static gateway of the network interface |
Christopher Haster |
21:35ed15069189 | 48 | * @param gateway Gateway address, copied internally |
Christopher Haster |
21:35ed15069189 | 49 | */ |
Christopher Haster |
21:35ed15069189 | 50 | virtual void setGateway(const char *gateway); |
Christopher Haster |
21:35ed15069189 | 51 | |
Christopher Haster |
21:35ed15069189 | 52 | /** Get the IP address |
Christopher Haster |
21:35ed15069189 | 53 | * @return IP address of the interface |
Christopher Haster |
21:35ed15069189 | 54 | */ |
Christopher Haster |
21:35ed15069189 | 55 | virtual const char *getIPAddress(); |
sam_grove | 3:167dd63981b6 | 56 | |
Christopher Haster |
21:35ed15069189 | 57 | /** Get the network mask |
Christopher Haster |
21:35ed15069189 | 58 | * @return Network mask of the interface |
sam_grove | 3:167dd63981b6 | 59 | */ |
Christopher Haster |
21:35ed15069189 | 60 | virtual const char *getNetworkMask(); |
Christopher Haster |
21:35ed15069189 | 61 | |
Christopher Haster |
21:35ed15069189 | 62 | /** Get the gateway |
Christopher Haster |
21:35ed15069189 | 63 | * @return Gateway address of the interface |
Christopher Haster |
21:35ed15069189 | 64 | */ |
Christopher Haster |
21:35ed15069189 | 65 | virtual const char *getGateway(); |
Christopher Haster |
21:35ed15069189 | 66 | |
Christopher Haster |
21:35ed15069189 | 67 | /** Get the current MAC address |
Christopher Haster |
21:35ed15069189 | 68 | * @return String MAC address of the interface |
Christopher Haster |
21:35ed15069189 | 69 | */ |
Christopher Haster |
21:35ed15069189 | 70 | virtual const char *getMACAddress() = 0; |
sam_grove | 3:167dd63981b6 | 71 | |
Christopher Haster |
21:35ed15069189 | 72 | /** Get the current status of the interface |
Christopher Haster |
21:35ed15069189 | 73 | @return true if connected |
bridadan | 1:291a9d61e58a | 74 | */ |
Christopher Haster |
23:1e86d9fb3d86 | 75 | virtual bool isConnected(void); |
Christopher Haster |
21:35ed15069189 | 76 | |
Christopher Haster |
26:9774a2edad71 | 77 | protected: |
Christopher Haster |
26:9774a2edad71 | 78 | NetworkInterface(); |
Christopher Haster |
26:9774a2edad71 | 79 | virtual ~NetworkInterface(); |
Christopher Haster |
21:35ed15069189 | 80 | |
Christopher Haster |
25:ed7b2a52e8ac | 81 | friend class Socket; |
Christopher Haster |
21:35ed15069189 | 82 | |
Christopher Haster |
21:35ed15069189 | 83 | /** Internally create a socket |
Christopher Haster |
21:35ed15069189 | 84 | * @param proto The type of socket to open, SOCK_TCP or SOCK_UDP |
Christopher Haster |
21:35ed15069189 | 85 | * @return The allocated socket |
Christopher Haster |
21:35ed15069189 | 86 | */ |
Christopher Haster |
21:35ed15069189 | 87 | virtual SocketInterface *createSocket(socket_protocol_t proto) = 0; |
bridadan | 11:47c32687a44c | 88 | |
Christopher Haster |
21:35ed15069189 | 89 | /** Internally destroy a socket |
Christopher Haster |
21:35ed15069189 | 90 | * @param socket An allocated SocketInterface |
Christopher Haster |
21:35ed15069189 | 91 | * @returns 0 on success |
bridadan | 11:47c32687a44c | 92 | */ |
Christopher Haster |
21:35ed15069189 | 93 | virtual void destroySocket(SocketInterface *socket) = 0; |
Christopher Haster |
21:35ed15069189 | 94 | |
Christopher Haster |
21:35ed15069189 | 95 | private: |
Christopher Haster |
23:1e86d9fb3d86 | 96 | char *_ip_address; |
Christopher Haster |
23:1e86d9fb3d86 | 97 | char *_network_mask; |
Christopher Haster |
23:1e86d9fb3d86 | 98 | char *_gateway; |
bridadan | 1:291a9d61e58a | 99 | }; |
bridadan | 1:291a9d61e58a | 100 | |
bridadan | 1:291a9d61e58a | 101 | #endif |