NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
NetworkInterface.h@66:c84a4c76cb94, 2016-04-01 (annotated)
- Committer:
- geky
- Date:
- Fri Apr 01 17:18:27 2016 +0000
- Revision:
- 66:c84a4c76cb94
- Parent:
- 63:531f4c27f360
- Child:
- 68:a52251517491
Changed API to better match Posix sockets; ; - Send returns size on success; - Returns NS_ERROR_WOULD_BLOCK when recv would block
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 |
42:49893d13c432 | 23 | /** Maximum storage needed for IP address and MAC addresses |
Christopher Haster |
42:49893d13c432 | 24 | */ |
Christopher Haster |
42:49893d13c432 | 25 | #define NS_IP_SIZE 16 |
Christopher Haster |
42:49893d13c432 | 26 | #define NS_MAC_SIZE 18 |
Christopher Haster |
28:163fbe3263f4 | 27 | |
sam_grove | 63:531f4c27f360 | 28 | /** |
sam_grove | 63:531f4c27f360 | 29 | * @enum ns_error_t |
sam_grove | 63:531f4c27f360 | 30 | * @brief enum of standardized error codes |
Christopher Haster |
45:c8aca7c1e93f | 31 | */ |
Christopher Haster |
45:c8aca7c1e93f | 32 | enum ns_error_t { |
geky | 66:c84a4c76cb94 | 33 | NS_ERROR_WOULD_BLOCK = -3000, /*!< no data is not available but call is non-blocking */ |
sam_grove | 63:531f4c27f360 | 34 | NS_ERROR_TIMEOUT = -3001, /*!< operation took longer than allowed */ |
sam_grove | 63:531f4c27f360 | 35 | NS_ERROR_NO_CONNECTION = -3002, /*!< not connected to a network */ |
sam_grove | 63:531f4c27f360 | 36 | NS_ERROR_NO_SOCKET = -3003, /*!< socket not available for use */ |
sam_grove | 63:531f4c27f360 | 37 | NS_ERROR_NO_ADDRESS = -3004, /*!< IP address is not known */ |
sam_grove | 63:531f4c27f360 | 38 | NS_ERROR_NO_MEMORY = -3005, /*!< memory resource not available */ |
sam_grove | 63:531f4c27f360 | 39 | NS_ERROR_DNS_FAILURE = -3006, /*!< DNS failed to complete successfully */ |
sam_grove | 63:531f4c27f360 | 40 | NS_ERROR_DHCP_FAILURE = -3007, /*!< DHCP failed to complete successfully */ |
sam_grove | 63:531f4c27f360 | 41 | NS_ERROR_AUTH_FAILURE = -3008, /*!< connection to access point faield */ |
sam_grove | 63:531f4c27f360 | 42 | NS_ERROR_DEVICE_ERROR = -3009 /*!< failure interfacing with the network procesor */ |
Christopher Haster |
45:c8aca7c1e93f | 43 | }; |
Christopher Haster |
45:c8aca7c1e93f | 44 | |
Christopher Haster |
21:35ed15069189 | 45 | /** NetworkInterface class |
Christopher Haster |
21:35ed15069189 | 46 | * Common interface that is shared between all hardware that |
Christopher Haster |
21:35ed15069189 | 47 | * can connect to a network over IP. |
bridadan | 1:291a9d61e58a | 48 | */ |
sam_grove | 3:167dd63981b6 | 49 | class NetworkInterface |
sam_grove | 3:167dd63981b6 | 50 | { |
bridadan | 1:291a9d61e58a | 51 | public: |
Christopher Haster |
53:26b5f1c69822 | 52 | virtual ~NetworkInterface() {}; |
Christopher Haster |
53:26b5f1c69822 | 53 | |
Christopher Haster |
21:35ed15069189 | 54 | /** Get the IP address |
Christopher Haster |
60:0360cb987da3 | 55 | * @return IP address of the interface or 0 if not yet connected |
sam_grove | 3:167dd63981b6 | 56 | */ |
Christopher Haster |
60:0360cb987da3 | 57 | virtual const char *getIPAddress() = 0; |
Christopher Haster |
21:35ed15069189 | 58 | |
Christopher Haster |
21:35ed15069189 | 59 | /** Get the current MAC address |
Christopher Haster |
21:35ed15069189 | 60 | * @return String MAC address of the interface |
Christopher Haster |
21:35ed15069189 | 61 | */ |
Christopher Haster |
60:0360cb987da3 | 62 | virtual const char *getMACAddress() = 0; |
sam_grove | 3:167dd63981b6 | 63 | |
Christopher Haster |
21:35ed15069189 | 64 | /** Get the current status of the interface |
geky | 31:7f15b95f2a1d | 65 | * @return true if connected |
bridadan | 1:291a9d61e58a | 66 | */ |
Christopher Haster |
42:49893d13c432 | 67 | virtual bool isConnected(); |
Christopher Haster |
41:3ec1c97e9bbf | 68 | |
geky | 31:7f15b95f2a1d | 69 | /** Looks up the specified host's IP address |
geky | 31:7f15b95f2a1d | 70 | * @param name URL of host |
geky | 31:7f15b95f2a1d | 71 | * @param ip Buffer to hold IP address, must be at least SOCK_IP_SIZE |
geky | 31:7f15b95f2a1d | 72 | * @return 0 on success |
geky | 31:7f15b95f2a1d | 73 | */ |
Christopher Haster |
55:7ff3586d7af4 | 74 | virtual int32_t getHostByName(const char *name, char *ip); |
Christopher Haster |
21:35ed15069189 | 75 | |
Christopher Haster |
26:9774a2edad71 | 76 | protected: |
Christopher Haster |
25:ed7b2a52e8ac | 77 | friend class Socket; |
Christopher Haster |
21:35ed15069189 | 78 | |
Christopher Haster |
21:35ed15069189 | 79 | /** Internally create a socket |
Christopher Haster |
57:3c873fab4207 | 80 | * @param proto The type of socket to open, NS_TCP or NS_UDP |
Christopher Haster |
21:35ed15069189 | 81 | * @return The allocated socket |
Christopher Haster |
21:35ed15069189 | 82 | */ |
Christopher Haster |
57:3c873fab4207 | 83 | virtual SocketInterface *createSocket(ns_protocol_t proto) = 0; |
geky | 30:3cc78f5db99d | 84 | |
Christopher Haster |
21:35ed15069189 | 85 | /** Internally destroy a socket |
Christopher Haster |
21:35ed15069189 | 86 | * @param socket An allocated SocketInterface |
Christopher Haster |
21:35ed15069189 | 87 | * @returns 0 on success |
bridadan | 11:47c32687a44c | 88 | */ |
Christopher Haster |
21:35ed15069189 | 89 | virtual void destroySocket(SocketInterface *socket) = 0; |
bridadan | 1:291a9d61e58a | 90 | }; |
bridadan | 1:291a9d61e58a | 91 | |
bridadan | 1:291a9d61e58a | 92 | #endif |