NetworkSocketAPI

Dependencies:   DnsQuery

Dependents:   HelloWizFi250Interface

Fork of NetworkSocketAPI by NetworkSocketAPI

Committer:
Christopher Haster
Date:
Thu Feb 25 21:52:57 2016 -0600
Revision:
59:badee747a030
Parent:
57:3c873fab4207
Child:
60:0360cb987da3
Removed setIPAddress/NetworkMask/Gateway set of functions from NetworkInterface

Who changed what in which revision?

UserRevisionLine numberNew 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
Christopher Haster 45:c8aca7c1e93f 29 /** Inexhaustive enum of standardized error codes
Christopher Haster 45:c8aca7c1e93f 30 */
Christopher Haster 45:c8aca7c1e93f 31 enum ns_error_t {
Christopher Haster 45:c8aca7c1e93f 32 NS_ERROR_TIMEOUT = -3001,
Christopher Haster 45:c8aca7c1e93f 33 NS_ERROR_NO_CONNECTION = -3002,
Christopher Haster 45:c8aca7c1e93f 34 NS_ERROR_NO_SOCKET = -3003,
Christopher Haster 45:c8aca7c1e93f 35 NS_ERROR_NO_ADDRESS = -3004,
Christopher Haster 45:c8aca7c1e93f 36 NS_ERROR_NO_MEMORY = -3005,
Christopher Haster 45:c8aca7c1e93f 37 NS_ERROR_DNS_FAILURE = -3006,
Christopher Haster 45:c8aca7c1e93f 38 NS_ERROR_DHCP_FAILURE = -3007,
Christopher Haster 46:ac37605ca91d 39 NS_ERROR_AUTH_FAILURE = -3008,
Christopher Haster 46:ac37605ca91d 40 NS_ERROR_DEVICE_ERROR = -3009
Christopher Haster 45:c8aca7c1e93f 41 };
Christopher Haster 45:c8aca7c1e93f 42
bridadan 11:47c32687a44c 43
Christopher Haster 21:35ed15069189 44 /** NetworkInterface class
Christopher Haster 21:35ed15069189 45 * Common interface that is shared between all hardware that
Christopher Haster 21:35ed15069189 46 * can connect to a network over IP.
bridadan 1:291a9d61e58a 47 */
sam_grove 3:167dd63981b6 48 class NetworkInterface
sam_grove 3:167dd63981b6 49 {
bridadan 1:291a9d61e58a 50 public:
Christopher Haster 53:26b5f1c69822 51 virtual ~NetworkInterface() {};
Christopher Haster 53:26b5f1c69822 52
Christopher Haster 52:52a6c4ea7128 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 59:badee747a030 72 virtual const char *getMACAddress();
sam_grove 3:167dd63981b6 73
Christopher Haster 21:35ed15069189 74 /** Get the current status of the interface
geky 31:7f15b95f2a1d 75 * @return true if connected
bridadan 1:291a9d61e58a 76 */
Christopher Haster 42:49893d13c432 77 virtual bool isConnected();
Christopher Haster 41:3ec1c97e9bbf 78
Christopher Haster 59:badee747a030 79
geky 31:7f15b95f2a1d 80 /** Looks up the specified host's IP address
geky 31:7f15b95f2a1d 81 * @param name URL of host
geky 31:7f15b95f2a1d 82 * @param ip Buffer to hold IP address, must be at least SOCK_IP_SIZE
geky 31:7f15b95f2a1d 83 * @return 0 on success
geky 31:7f15b95f2a1d 84 */
Christopher Haster 55:7ff3586d7af4 85 virtual int32_t getHostByName(const char *name, char *ip);
Christopher Haster 21:35ed15069189 86
Christopher Haster 26:9774a2edad71 87 protected:
Christopher Haster 25:ed7b2a52e8ac 88 friend class Socket;
Christopher Haster 21:35ed15069189 89
Christopher Haster 21:35ed15069189 90 /** Internally create a socket
Christopher Haster 57:3c873fab4207 91 * @param proto The type of socket to open, NS_TCP or NS_UDP
Christopher Haster 21:35ed15069189 92 * @return The allocated socket
Christopher Haster 21:35ed15069189 93 */
Christopher Haster 57:3c873fab4207 94 virtual SocketInterface *createSocket(ns_protocol_t proto) = 0;
geky 30:3cc78f5db99d 95
Christopher Haster 21:35ed15069189 96 /** Internally destroy a socket
Christopher Haster 21:35ed15069189 97 * @param socket An allocated SocketInterface
Christopher Haster 21:35ed15069189 98 * @returns 0 on success
bridadan 11:47c32687a44c 99 */
Christopher Haster 21:35ed15069189 100 virtual void destroySocket(SocketInterface *socket) = 0;
bridadan 1:291a9d61e58a 101 };
bridadan 1:291a9d61e58a 102
bridadan 1:291a9d61e58a 103 #endif