BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:fbdae7e6d805 1 /* NetworkStack
borlanic 0:fbdae7e6d805 2 * Copyright (c) 2015 ARM Limited
borlanic 0:fbdae7e6d805 3 *
borlanic 0:fbdae7e6d805 4 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:fbdae7e6d805 5 * you may not use this file except in compliance with the License.
borlanic 0:fbdae7e6d805 6 * You may obtain a copy of the License at
borlanic 0:fbdae7e6d805 7 *
borlanic 0:fbdae7e6d805 8 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:fbdae7e6d805 9 *
borlanic 0:fbdae7e6d805 10 * Unless required by applicable law or agreed to in writing, software
borlanic 0:fbdae7e6d805 11 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:fbdae7e6d805 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:fbdae7e6d805 13 * See the License for the specific language governing permissions and
borlanic 0:fbdae7e6d805 14 * limitations under the License.
borlanic 0:fbdae7e6d805 15 */
borlanic 0:fbdae7e6d805 16
borlanic 0:fbdae7e6d805 17 #ifndef NETWORK_INTERFACE_H
borlanic 0:fbdae7e6d805 18 #define NETWORK_INTERFACE_H
borlanic 0:fbdae7e6d805 19
borlanic 0:fbdae7e6d805 20 #include "netsocket/nsapi_types.h"
borlanic 0:fbdae7e6d805 21 #include "netsocket/SocketAddress.h"
borlanic 0:fbdae7e6d805 22 #include "Callback.h"
borlanic 0:fbdae7e6d805 23
borlanic 0:fbdae7e6d805 24 // Predeclared class
borlanic 0:fbdae7e6d805 25 class NetworkStack;
borlanic 0:fbdae7e6d805 26
borlanic 0:fbdae7e6d805 27
borlanic 0:fbdae7e6d805 28 /** NetworkInterface class
borlanic 0:fbdae7e6d805 29 *
borlanic 0:fbdae7e6d805 30 * Common interface that is shared between network devices
borlanic 0:fbdae7e6d805 31 * @addtogroup netsocket
borlanic 0:fbdae7e6d805 32 */
borlanic 0:fbdae7e6d805 33 class NetworkInterface {
borlanic 0:fbdae7e6d805 34 public:
borlanic 0:fbdae7e6d805 35
borlanic 0:fbdae7e6d805 36
borlanic 0:fbdae7e6d805 37
borlanic 0:fbdae7e6d805 38 virtual ~NetworkInterface() {};
borlanic 0:fbdae7e6d805 39
borlanic 0:fbdae7e6d805 40 /** Get the local MAC address
borlanic 0:fbdae7e6d805 41 *
borlanic 0:fbdae7e6d805 42 * Provided MAC address is intended for info or debug purposes and
borlanic 0:fbdae7e6d805 43 * may not be provided if the underlying network interface does not
borlanic 0:fbdae7e6d805 44 * provide a MAC address
borlanic 0:fbdae7e6d805 45 *
borlanic 0:fbdae7e6d805 46 * @return Null-terminated representation of the local MAC address
borlanic 0:fbdae7e6d805 47 * or null if no MAC address is available
borlanic 0:fbdae7e6d805 48 */
borlanic 0:fbdae7e6d805 49 virtual const char *get_mac_address();
borlanic 0:fbdae7e6d805 50
borlanic 0:fbdae7e6d805 51 /** Get the local IP address
borlanic 0:fbdae7e6d805 52 *
borlanic 0:fbdae7e6d805 53 * @return Null-terminated representation of the local IP address
borlanic 0:fbdae7e6d805 54 * or null if no IP address has been received
borlanic 0:fbdae7e6d805 55 */
borlanic 0:fbdae7e6d805 56 virtual const char *get_ip_address();
borlanic 0:fbdae7e6d805 57
borlanic 0:fbdae7e6d805 58 /** Get the local network mask
borlanic 0:fbdae7e6d805 59 *
borlanic 0:fbdae7e6d805 60 * @return Null-terminated representation of the local network mask
borlanic 0:fbdae7e6d805 61 * or null if no network mask has been received
borlanic 0:fbdae7e6d805 62 */
borlanic 0:fbdae7e6d805 63 virtual const char *get_netmask();
borlanic 0:fbdae7e6d805 64
borlanic 0:fbdae7e6d805 65 /** Get the local gateway
borlanic 0:fbdae7e6d805 66 *
borlanic 0:fbdae7e6d805 67 * @return Null-terminated representation of the local gateway
borlanic 0:fbdae7e6d805 68 * or null if no network mask has been received
borlanic 0:fbdae7e6d805 69 */
borlanic 0:fbdae7e6d805 70 virtual const char *get_gateway();
borlanic 0:fbdae7e6d805 71
borlanic 0:fbdae7e6d805 72 /** Set a static IP address
borlanic 0:fbdae7e6d805 73 *
borlanic 0:fbdae7e6d805 74 * Configures this network interface to use a static IP address.
borlanic 0:fbdae7e6d805 75 * Implicitly disables DHCP, which can be enabled in set_dhcp.
borlanic 0:fbdae7e6d805 76 * Requires that the network is disconnected.
borlanic 0:fbdae7e6d805 77 *
borlanic 0:fbdae7e6d805 78 * @param ip_address Null-terminated representation of the local IP address
borlanic 0:fbdae7e6d805 79 * @param netmask Null-terminated representation of the local network mask
borlanic 0:fbdae7e6d805 80 * @param gateway Null-terminated representation of the local gateway
borlanic 0:fbdae7e6d805 81 * @return 0 on success, negative error code on failure
borlanic 0:fbdae7e6d805 82 */
borlanic 0:fbdae7e6d805 83 virtual nsapi_error_t set_network(
borlanic 0:fbdae7e6d805 84 const char *ip_address, const char *netmask, const char *gateway);
borlanic 0:fbdae7e6d805 85
borlanic 0:fbdae7e6d805 86 /** Enable or disable DHCP on the network
borlanic 0:fbdae7e6d805 87 *
borlanic 0:fbdae7e6d805 88 * Enables DHCP on connecting the network. Defaults to enabled unless
borlanic 0:fbdae7e6d805 89 * a static IP address has been assigned. Requires that the network is
borlanic 0:fbdae7e6d805 90 * disconnected.
borlanic 0:fbdae7e6d805 91 *
borlanic 0:fbdae7e6d805 92 * @param dhcp True to enable DHCP
borlanic 0:fbdae7e6d805 93 * @return 0 on success, negative error code on failure
borlanic 0:fbdae7e6d805 94 */
borlanic 0:fbdae7e6d805 95 virtual nsapi_error_t set_dhcp(bool dhcp);
borlanic 0:fbdae7e6d805 96
borlanic 0:fbdae7e6d805 97 /** Start the interface
borlanic 0:fbdae7e6d805 98 *
borlanic 0:fbdae7e6d805 99 * @return 0 on success, negative error code on failure
borlanic 0:fbdae7e6d805 100 */
borlanic 0:fbdae7e6d805 101 virtual nsapi_error_t connect() = 0;
borlanic 0:fbdae7e6d805 102
borlanic 0:fbdae7e6d805 103 /** Stop the interface
borlanic 0:fbdae7e6d805 104 *
borlanic 0:fbdae7e6d805 105 * @return 0 on success, negative error code on failure
borlanic 0:fbdae7e6d805 106 */
borlanic 0:fbdae7e6d805 107 virtual nsapi_error_t disconnect() = 0;
borlanic 0:fbdae7e6d805 108
borlanic 0:fbdae7e6d805 109 /** Translates a hostname to an IP address with specific version
borlanic 0:fbdae7e6d805 110 *
borlanic 0:fbdae7e6d805 111 * The hostname may be either a domain name or an IP address. If the
borlanic 0:fbdae7e6d805 112 * hostname is an IP address, no network transactions will be performed.
borlanic 0:fbdae7e6d805 113 *
borlanic 0:fbdae7e6d805 114 * If no stack-specific DNS resolution is provided, the hostname
borlanic 0:fbdae7e6d805 115 * will be resolve using a UDP socket on the stack.
borlanic 0:fbdae7e6d805 116 *
borlanic 0:fbdae7e6d805 117 * @param address Destination for the host SocketAddress
borlanic 0:fbdae7e6d805 118 * @param host Hostname to resolve
borlanic 0:fbdae7e6d805 119 * @param version IP version of address to resolve, NSAPI_UNSPEC indicates
borlanic 0:fbdae7e6d805 120 * version is chosen by the stack (defaults to NSAPI_UNSPEC)
borlanic 0:fbdae7e6d805 121 * @return 0 on success, negative error code on failure
borlanic 0:fbdae7e6d805 122 */
borlanic 0:fbdae7e6d805 123 virtual nsapi_error_t gethostbyname(const char *host,
borlanic 0:fbdae7e6d805 124 SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC);
borlanic 0:fbdae7e6d805 125
borlanic 0:fbdae7e6d805 126 /** Add a domain name server to list of servers to query
borlanic 0:fbdae7e6d805 127 *
borlanic 0:fbdae7e6d805 128 * @param address Destination for the host address
borlanic 0:fbdae7e6d805 129 * @return 0 on success, negative error code on failure
borlanic 0:fbdae7e6d805 130 */
borlanic 0:fbdae7e6d805 131 virtual nsapi_error_t add_dns_server(const SocketAddress &address);
borlanic 0:fbdae7e6d805 132
borlanic 0:fbdae7e6d805 133 /** Register callback for status reporting
borlanic 0:fbdae7e6d805 134 *
borlanic 0:fbdae7e6d805 135 * The specified status callback function will be called on status changes
borlanic 0:fbdae7e6d805 136 * on the network. The parameters on the callback are the event type and
borlanic 0:fbdae7e6d805 137 * event-type dependent reason parameter.
borlanic 0:fbdae7e6d805 138 *
borlanic 0:fbdae7e6d805 139 * @param status_cb The callback for status changes
borlanic 0:fbdae7e6d805 140 */
borlanic 0:fbdae7e6d805 141 virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
borlanic 0:fbdae7e6d805 142
borlanic 0:fbdae7e6d805 143 /** Get the connection status
borlanic 0:fbdae7e6d805 144 *
borlanic 0:fbdae7e6d805 145 * @return The connection status according to ConnectionStatusType
borlanic 0:fbdae7e6d805 146 */
borlanic 0:fbdae7e6d805 147 virtual nsapi_connection_status_t get_connection_status() const;
borlanic 0:fbdae7e6d805 148
borlanic 0:fbdae7e6d805 149 /** Set blocking status of connect() which by default should be blocking
borlanic 0:fbdae7e6d805 150 *
borlanic 0:fbdae7e6d805 151 * @param blocking true if connect is blocking
borlanic 0:fbdae7e6d805 152 * @return 0 on success, negative error code on failure
borlanic 0:fbdae7e6d805 153 */
borlanic 0:fbdae7e6d805 154 virtual nsapi_error_t set_blocking(bool blocking);
borlanic 0:fbdae7e6d805 155
borlanic 0:fbdae7e6d805 156
borlanic 0:fbdae7e6d805 157 protected:
borlanic 0:fbdae7e6d805 158 friend class Socket;
borlanic 0:fbdae7e6d805 159 friend class UDPSocket;
borlanic 0:fbdae7e6d805 160 friend class TCPSocket;
borlanic 0:fbdae7e6d805 161 friend class TCPServer;
borlanic 0:fbdae7e6d805 162 friend class SocketAddress;
borlanic 0:fbdae7e6d805 163 template <typename IF>
borlanic 0:fbdae7e6d805 164 friend NetworkStack *nsapi_create_stack(IF *iface);
borlanic 0:fbdae7e6d805 165
borlanic 0:fbdae7e6d805 166 /** Provide access to the NetworkStack object
borlanic 0:fbdae7e6d805 167 *
borlanic 0:fbdae7e6d805 168 * @return The underlying NetworkStack object
borlanic 0:fbdae7e6d805 169 */
borlanic 0:fbdae7e6d805 170 virtual NetworkStack *get_stack() = 0;
borlanic 0:fbdae7e6d805 171 };
borlanic 0:fbdae7e6d805 172
borlanic 0:fbdae7e6d805 173
borlanic 0:fbdae7e6d805 174 #endif