mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 31 06:02:27 2019 +0000
Revision:
1:9db0e321a9f4
Parent:
0:5b88d5760320
updated based on mbed-os5.15.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:5b88d5760320 1 /*
kenjiArai 0:5b88d5760320 2 * Copyright (c) 2015 ARM Limited
kenjiArai 0:5b88d5760320 3 *
kenjiArai 0:5b88d5760320 4 * Licensed under the Apache License, Version 2.0 (the "License");
kenjiArai 0:5b88d5760320 5 * you may not use this file except in compliance with the License.
kenjiArai 0:5b88d5760320 6 * You may obtain a copy of the License at
kenjiArai 0:5b88d5760320 7 *
kenjiArai 0:5b88d5760320 8 * http://www.apache.org/licenses/LICENSE-2.0
kenjiArai 0:5b88d5760320 9 *
kenjiArai 0:5b88d5760320 10 * Unless required by applicable law or agreed to in writing, software
kenjiArai 0:5b88d5760320 11 * distributed under the License is distributed on an "AS IS" BASIS,
kenjiArai 0:5b88d5760320 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kenjiArai 0:5b88d5760320 13 * See the License for the specific language governing permissions and
kenjiArai 0:5b88d5760320 14 * limitations under the License.
kenjiArai 0:5b88d5760320 15 */
kenjiArai 0:5b88d5760320 16
kenjiArai 0:5b88d5760320 17 /** @file NetworkInterface.h Network Interface base class */
kenjiArai 0:5b88d5760320 18 /** @addtogroup netinterface
kenjiArai 0:5b88d5760320 19 * Network Interface classes
kenjiArai 0:5b88d5760320 20 * @{ */
kenjiArai 0:5b88d5760320 21
kenjiArai 0:5b88d5760320 22
kenjiArai 0:5b88d5760320 23 #ifndef NETWORK_INTERFACE_H
kenjiArai 0:5b88d5760320 24 #define NETWORK_INTERFACE_H
kenjiArai 0:5b88d5760320 25
kenjiArai 0:5b88d5760320 26 #include "netsocket/nsapi_types.h"
kenjiArai 0:5b88d5760320 27 #include "netsocket/SocketAddress.h"
kenjiArai 0:5b88d5760320 28 #include "Callback.h"
kenjiArai 0:5b88d5760320 29 #include "DNS.h"
kenjiArai 0:5b88d5760320 30
kenjiArai 0:5b88d5760320 31
kenjiArai 0:5b88d5760320 32 // Predeclared classes
kenjiArai 0:5b88d5760320 33 class NetworkStack;
kenjiArai 0:5b88d5760320 34 class EthInterface;
kenjiArai 0:5b88d5760320 35 class WiFiInterface;
kenjiArai 0:5b88d5760320 36 class MeshInterface;
kenjiArai 0:5b88d5760320 37 class CellularInterface;
kenjiArai 0:5b88d5760320 38 class EMACInterface;
kenjiArai 1:9db0e321a9f4 39 class PPPInterface;
kenjiArai 0:5b88d5760320 40
kenjiArai 0:5b88d5760320 41 /** Common interface that is shared between network devices.
kenjiArai 0:5b88d5760320 42 *
kenjiArai 0:5b88d5760320 43 */
kenjiArai 0:5b88d5760320 44 class NetworkInterface: public DNS {
kenjiArai 0:5b88d5760320 45 public:
kenjiArai 0:5b88d5760320 46
kenjiArai 0:5b88d5760320 47 virtual ~NetworkInterface();
kenjiArai 0:5b88d5760320 48
kenjiArai 0:5b88d5760320 49 /** Return the default network interface.
kenjiArai 0:5b88d5760320 50 *
kenjiArai 0:5b88d5760320 51 * Returns the default network interface, as determined by JSON option
kenjiArai 0:5b88d5760320 52 * target.network-default-interface-type or other overrides.
kenjiArai 0:5b88d5760320 53 *
kenjiArai 0:5b88d5760320 54 * The type of the interface returned can be tested by calling ethInterface(),
kenjiArai 0:5b88d5760320 55 * wifiInterface(), meshInterface(), cellularInterface(), emacInterface() and checking
kenjiArai 0:5b88d5760320 56 * for NULL pointers.
kenjiArai 0:5b88d5760320 57 *
kenjiArai 0:5b88d5760320 58 * The default behavior is to return the default interface for the
kenjiArai 0:5b88d5760320 59 * interface type specified by target.network-default-interface-type. Targets
kenjiArai 0:5b88d5760320 60 * should set this in their targets.json to guide default selection,
kenjiArai 0:5b88d5760320 61 * and applications may override.
kenjiArai 0:5b88d5760320 62 *
kenjiArai 0:5b88d5760320 63 * The interface returned should be already configured for use such that its
kenjiArai 0:5b88d5760320 64 * connect() method works with no parameters. For connection types needing
kenjiArai 0:5b88d5760320 65 * configuration, settings should normally be obtained from JSON - the
kenjiArai 0:5b88d5760320 66 * settings for the core types are under the "nsapi" JSON config tree.
kenjiArai 0:5b88d5760320 67 *
kenjiArai 0:5b88d5760320 68 * The list of possible settings for default interface type is open-ended,
kenjiArai 0:5b88d5760320 69 * as is the number of possible providers. Core providers are:
kenjiArai 0:5b88d5760320 70 *
kenjiArai 0:5b88d5760320 71 * * ETHERNET: EthernetInterface, using default EMAC and OnboardNetworkStack
kenjiArai 0:5b88d5760320 72 * * MESH: ThreadInterface or LoWPANNDInterface, using default NanostackRfPhy
kenjiArai 0:5b88d5760320 73 * * CELLULAR: OnboardModemInterface
kenjiArai 0:5b88d5760320 74 * * WIFI: None - always provided by a specific class
kenjiArai 0:5b88d5760320 75 *
kenjiArai 0:5b88d5760320 76 * Specific drivers may be activated by other settings of the
kenjiArai 0:5b88d5760320 77 * default-network-interface-type configuration. This will depend on the
kenjiArai 0:5b88d5760320 78 * target and the driver. For example a board may have its default setting
kenjiArai 0:5b88d5760320 79 * as "AUTO" which causes it to autodetect an Ethernet cable. This should
kenjiArai 0:5b88d5760320 80 * be described in the target's documentation.
kenjiArai 0:5b88d5760320 81 *
kenjiArai 0:5b88d5760320 82 * An application can override all target settings by implementing
kenjiArai 0:5b88d5760320 83 * NetworkInterface::get_default_instance() themselves - the default
kenjiArai 0:5b88d5760320 84 * definition is weak, and calls get_target_default_instance().
kenjiArai 0:5b88d5760320 85 */
kenjiArai 0:5b88d5760320 86 static NetworkInterface *get_default_instance();
kenjiArai 0:5b88d5760320 87
kenjiArai 0:5b88d5760320 88 /** Set network interface as default one.
kenjiArai 0:5b88d5760320 89 */
kenjiArai 0:5b88d5760320 90 virtual void set_as_default();
kenjiArai 0:5b88d5760320 91
kenjiArai 0:5b88d5760320 92 /** Get the local MAC address.
kenjiArai 0:5b88d5760320 93 *
kenjiArai 0:5b88d5760320 94 * Provided MAC address is intended for info or debug purposes and
kenjiArai 0:5b88d5760320 95 * may be not provided if the underlying network interface does not
kenjiArai 0:5b88d5760320 96 * provide a MAC address.
kenjiArai 0:5b88d5760320 97 *
kenjiArai 0:5b88d5760320 98 * @return Null-terminated representation of the local MAC address
kenjiArai 0:5b88d5760320 99 * or null if no MAC address is available.
kenjiArai 0:5b88d5760320 100 */
kenjiArai 0:5b88d5760320 101 virtual const char *get_mac_address();
kenjiArai 0:5b88d5760320 102
kenjiArai 0:5b88d5760320 103 /** Get the local IP address
kenjiArai 0:5b88d5760320 104 *
kenjiArai 1:9db0e321a9f4 105 * @param address SocketAddress representation of the local IP address
kenjiArai 1:9db0e321a9f4 106 * @retval NSAPI_ERROR_OK on success
kenjiArai 1:9db0e321a9f4 107 * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported
kenjiArai 1:9db0e321a9f4 108 * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid
kenjiArai 1:9db0e321a9f4 109 * @retval NSAPI_ERROR_NO_ADDRESS if the address cannot be obtained from stack
kenjiArai 0:5b88d5760320 110 */
kenjiArai 1:9db0e321a9f4 111 virtual nsapi_error_t get_ip_address(SocketAddress *address);
kenjiArai 1:9db0e321a9f4 112
kenjiArai 1:9db0e321a9f4 113 MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
kenjiArai 0:5b88d5760320 114 virtual const char *get_ip_address();
kenjiArai 0:5b88d5760320 115
kenjiArai 1:9db0e321a9f4 116 /** Get the IPv6 link local address
kenjiArai 1:9db0e321a9f4 117 *
kenjiArai 1:9db0e321a9f4 118 * @param address SocketAddress representation of the link local IPv6 address
kenjiArai 1:9db0e321a9f4 119 * @retval NSAPI_ERROR_OK on success
kenjiArai 1:9db0e321a9f4 120 * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported
kenjiArai 1:9db0e321a9f4 121 * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid
kenjiArai 1:9db0e321a9f4 122 */
kenjiArai 1:9db0e321a9f4 123 virtual nsapi_error_t get_ipv6_link_local_address(SocketAddress *address);
kenjiArai 1:9db0e321a9f4 124
kenjiArai 0:5b88d5760320 125 /** Get the local network mask.
kenjiArai 0:5b88d5760320 126 *
kenjiArai 1:9db0e321a9f4 127 * @param address SocketAddress representation of netmask
kenjiArai 1:9db0e321a9f4 128 * @retval NSAPI_ERROR_OK on success
kenjiArai 1:9db0e321a9f4 129 * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported
kenjiArai 1:9db0e321a9f4 130 * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid
kenjiArai 1:9db0e321a9f4 131 * @retval NSAPI_ERROR_NO_ADDRESS if the address cannot be obtained from stack
kenjiArai 0:5b88d5760320 132 */
kenjiArai 1:9db0e321a9f4 133 virtual nsapi_error_t get_netmask(SocketAddress *address);
kenjiArai 1:9db0e321a9f4 134
kenjiArai 1:9db0e321a9f4 135 MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
kenjiArai 0:5b88d5760320 136 virtual const char *get_netmask();
kenjiArai 0:5b88d5760320 137
kenjiArai 0:5b88d5760320 138 /** Get the local gateway.
kenjiArai 0:5b88d5760320 139 *
kenjiArai 1:9db0e321a9f4 140 * @param address SocketAddress representation of gateway address
kenjiArai 1:9db0e321a9f4 141 * @retval NSAPI_ERROR_OK on success
kenjiArai 1:9db0e321a9f4 142 * @retval NSAPI_ERROR_UNSUPPORTED if this feature is not supported
kenjiArai 1:9db0e321a9f4 143 * @retval NSAPI_ERROR_PARAMETER if the provided pointer is invalid
kenjiArai 1:9db0e321a9f4 144 * @retval NSAPI_ERROR_NO_ADDRESS if the address cannot be obtained from stack
kenjiArai 0:5b88d5760320 145 */
kenjiArai 1:9db0e321a9f4 146 virtual nsapi_error_t get_gateway(SocketAddress *address);
kenjiArai 1:9db0e321a9f4 147
kenjiArai 1:9db0e321a9f4 148 MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
kenjiArai 0:5b88d5760320 149 virtual const char *get_gateway();
kenjiArai 0:5b88d5760320 150
kenjiArai 0:5b88d5760320 151 /** Get the network interface name
kenjiArai 0:5b88d5760320 152 *
kenjiArai 0:5b88d5760320 153 * @return Null-terminated representation of the network interface name
kenjiArai 0:5b88d5760320 154 * or null if interface not exists
kenjiArai 0:5b88d5760320 155 */
kenjiArai 0:5b88d5760320 156 virtual char *get_interface_name(char *interface_name);
kenjiArai 0:5b88d5760320 157
kenjiArai 0:5b88d5760320 158 /** Configure this network interface to use a static IP address.
kenjiArai 0:5b88d5760320 159 * Implicitly disables DHCP, which can be enabled in set_dhcp.
kenjiArai 0:5b88d5760320 160 * Requires that the network is disconnected.
kenjiArai 0:5b88d5760320 161 *
kenjiArai 1:9db0e321a9f4 162 * @param ip_address SocketAddress object containing the local IP address
kenjiArai 1:9db0e321a9f4 163 * @param netmask SocketAddress object containing the local network mask
kenjiArai 1:9db0e321a9f4 164 * @param gateway SocketAddress object containing the local gateway
kenjiArai 1:9db0e321a9f4 165 * @retval NSAPI_ERROR_OK on success
kenjiArai 1:9db0e321a9f4 166 * @retval NSAPI_ERROR_UNSUPPORTED if this function is unsupported
kenjiArai 0:5b88d5760320 167 */
kenjiArai 1:9db0e321a9f4 168 virtual nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway);
kenjiArai 1:9db0e321a9f4 169
kenjiArai 1:9db0e321a9f4 170 MBED_DEPRECATED_SINCE("mbed-os-5.15", "String-based APIs are deprecated")
kenjiArai 0:5b88d5760320 171 virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway);
kenjiArai 0:5b88d5760320 172
kenjiArai 0:5b88d5760320 173 /** Enable or disable DHCP on connecting the network.
kenjiArai 0:5b88d5760320 174 *
kenjiArai 0:5b88d5760320 175 * Enabled by default unless a static IP address has been assigned. Requires
kenjiArai 0:5b88d5760320 176 * that the network is disconnected.
kenjiArai 0:5b88d5760320 177 *
kenjiArai 0:5b88d5760320 178 * @param dhcp True to enable DHCP.
kenjiArai 1:9db0e321a9f4 179 * @retval NSAPI_ERROR_OK on success.
kenjiArai 1:9db0e321a9f4 180 * @retval NSAPI_ERROR_UNSUPPORTED if operation is not supported.
kenjiArai 0:5b88d5760320 181 */
kenjiArai 0:5b88d5760320 182 virtual nsapi_error_t set_dhcp(bool dhcp);
kenjiArai 0:5b88d5760320 183
kenjiArai 0:5b88d5760320 184 /** Connect to a network.
kenjiArai 0:5b88d5760320 185 *
kenjiArai 0:5b88d5760320 186 * This blocks until connection is established, but asynchronous operation can be enabled
kenjiArai 0:5b88d5760320 187 * by calling NetworkInterface::set_blocking(false).
kenjiArai 0:5b88d5760320 188 *
kenjiArai 0:5b88d5760320 189 * In asynchronous mode this starts the connection sequence and returns immediately.
kenjiArai 0:5b88d5760320 190 * Status of the connection can then checked from NetworkInterface::get_connection_status()
kenjiArai 0:5b88d5760320 191 * or from status callbacks.
kenjiArai 0:5b88d5760320 192 *
kenjiArai 0:5b88d5760320 193 * NetworkInterface internally handles reconnections until disconnect() is called.
kenjiArai 0:5b88d5760320 194 *
kenjiArai 0:5b88d5760320 195 * @return NSAPI_ERROR_OK if connection established in blocking mode.
kenjiArai 0:5b88d5760320 196 * @return NSAPI_ERROR_OK if asynchronous operation started.
kenjiArai 0:5b88d5760320 197 * @return NSAPI_ERROR_BUSY if asynchronous operation cannot be started.
kenjiArai 0:5b88d5760320 198 Implementation guarantees event generation, which can be used as an
kenjiArai 0:5b88d5760320 199 trigger to reissue the rejected request.
kenjiArai 0:5b88d5760320 200 * @return NSAPI_ERROR_IS_CONNECTED if already connected.
kenjiArai 0:5b88d5760320 201 * @return negative error code on failure.
kenjiArai 0:5b88d5760320 202 */
kenjiArai 0:5b88d5760320 203 virtual nsapi_error_t connect() = 0;
kenjiArai 0:5b88d5760320 204
kenjiArai 0:5b88d5760320 205 /** Disconnect from the network
kenjiArai 0:5b88d5760320 206 *
kenjiArai 0:5b88d5760320 207 * This blocks until interface is disconnected, unless interface is set to
kenjiArai 0:5b88d5760320 208 * asynchronous (non-blocking) mode by calling NetworkInterface::set_blocking(false).
kenjiArai 0:5b88d5760320 209 *
kenjiArai 0:5b88d5760320 210 * @return NSAPI_ERROR_OK on successfully disconnected in blocking mode.
kenjiArai 0:5b88d5760320 211 * @return NSAPI_ERROR_OK if asynchronous operation started.
kenjiArai 0:5b88d5760320 212 * @return NSAPI_ERROR_BUSY if asynchronous operation cannot be started.
kenjiArai 0:5b88d5760320 213 Implementation guarantees event generation, which can be used as an
kenjiArai 0:5b88d5760320 214 trigger to reissue the rejected request.
kenjiArai 0:5b88d5760320 215 * @return NSAPI_ERROR_NO_CONNECTION if already disconnected.
kenjiArai 0:5b88d5760320 216 * @return negative error code on failure.
kenjiArai 0:5b88d5760320 217 */
kenjiArai 0:5b88d5760320 218 virtual nsapi_error_t disconnect() = 0;
kenjiArai 0:5b88d5760320 219
kenjiArai 0:5b88d5760320 220 /** Translate a hostname to an IP address with specific version using network interface name.
kenjiArai 0:5b88d5760320 221 *
kenjiArai 0:5b88d5760320 222 * The hostname may be either a domain name or an IP address. If the
kenjiArai 0:5b88d5760320 223 * hostname is an IP address, no network transactions will be performed.
kenjiArai 0:5b88d5760320 224 *
kenjiArai 0:5b88d5760320 225 * If no stack-specific DNS resolution is provided, the hostname
kenjiArai 0:5b88d5760320 226 * will be resolve using a UDP socket on the stack.
kenjiArai 0:5b88d5760320 227 *
kenjiArai 0:5b88d5760320 228 * @param host Hostname to resolve.
kenjiArai 0:5b88d5760320 229 * @param address Pointer to a SocketAddress to store the result.
kenjiArai 0:5b88d5760320 230 * @param version IP version of address to resolve, NSAPI_UNSPEC indicates
kenjiArai 0:5b88d5760320 231 * version is chosen by the stack (defaults to NSAPI_UNSPEC).
kenjiArai 0:5b88d5760320 232 * @param interface_name Network interface name
kenjiArai 1:9db0e321a9f4 233 * @retval NSAPI_ERROR_OK on success
kenjiArai 1:9db0e321a9f4 234 * @retval int Negative error code on failure.
kenjiArai 1:9db0e321a9f4 235 * See @ref NetworkStack::gethostbyname
kenjiArai 0:5b88d5760320 236 */
kenjiArai 0:5b88d5760320 237 virtual nsapi_error_t gethostbyname(const char *host,
kenjiArai 0:5b88d5760320 238 SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC, const char *interface_name = NULL);
kenjiArai 0:5b88d5760320 239
kenjiArai 0:5b88d5760320 240 /** Hostname translation callback (for use with gethostbyname_async()).
kenjiArai 0:5b88d5760320 241 *
kenjiArai 0:5b88d5760320 242 * Callback will be called after DNS resolution completes or a failure occurs.
kenjiArai 0:5b88d5760320 243 *
kenjiArai 0:5b88d5760320 244 * @note Callback should not take more than 10ms to execute, otherwise it might
kenjiArai 0:5b88d5760320 245 * prevent underlying thread processing. A portable user of the callback
kenjiArai 0:5b88d5760320 246 * should not make calls to network operations due to stack size limitations.
kenjiArai 0:5b88d5760320 247 * The callback should not perform expensive operations such as socket recv/send
kenjiArai 0:5b88d5760320 248 * calls or blocking operations.
kenjiArai 0:5b88d5760320 249 *
kenjiArai 0:5b88d5760320 250 * @param result NSAPI_ERROR_OK on success, negative error code on failure.
kenjiArai 0:5b88d5760320 251 * @param address On success, destination for the host SocketAddress.
kenjiArai 0:5b88d5760320 252 */
kenjiArai 0:5b88d5760320 253 typedef mbed::Callback<void (nsapi_error_t result, SocketAddress *address)> hostbyname_cb_t;
kenjiArai 0:5b88d5760320 254
kenjiArai 0:5b88d5760320 255 /** Translate a hostname to an IP address (asynchronous) using network interface name.
kenjiArai 0:5b88d5760320 256 *
kenjiArai 0:5b88d5760320 257 * The hostname may be either a domain name or a dotted IP address. If the
kenjiArai 0:5b88d5760320 258 * hostname is an IP address, no network transactions will be performed.
kenjiArai 0:5b88d5760320 259 *
kenjiArai 0:5b88d5760320 260 * If no stack-specific DNS resolution is provided, the hostname
kenjiArai 0:5b88d5760320 261 * will be resolve using a UDP socket on the stack.
kenjiArai 0:5b88d5760320 262 *
kenjiArai 0:5b88d5760320 263 * Call is non-blocking. Result of the DNS operation is returned by the callback.
kenjiArai 0:5b88d5760320 264 * If this function returns failure, callback will not be called. In case result
kenjiArai 0:5b88d5760320 265 * is success (IP address was found from DNS cache), callback will be called
kenjiArai 0:5b88d5760320 266 * before function returns.
kenjiArai 0:5b88d5760320 267 *
kenjiArai 0:5b88d5760320 268 * @param host Hostname to resolve.
kenjiArai 0:5b88d5760320 269 * @param callback Callback that is called for result.
kenjiArai 0:5b88d5760320 270 * @param version IP version of address to resolve, NSAPI_UNSPEC indicates
kenjiArai 0:5b88d5760320 271 * version is chosen by the stack (defaults to NSAPI_UNSPEC).
kenjiArai 0:5b88d5760320 272 * @param interface_name Network interface name
kenjiArai 0:5b88d5760320 273 * @return 0 on immediate success,
kenjiArai 0:5b88d5760320 274 * negative error code on immediate failure or
kenjiArai 0:5b88d5760320 275 * a positive unique id that represents the hostname translation operation
kenjiArai 0:5b88d5760320 276 * and can be passed to cancel.
kenjiArai 0:5b88d5760320 277 */
kenjiArai 0:5b88d5760320 278 virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version = NSAPI_UNSPEC,
kenjiArai 0:5b88d5760320 279 const char *interface_name = NULL);
kenjiArai 0:5b88d5760320 280
kenjiArai 0:5b88d5760320 281 /** Cancel asynchronous hostname translation.
kenjiArai 0:5b88d5760320 282 *
kenjiArai 0:5b88d5760320 283 * When translation is cancelled, callback will not be called.
kenjiArai 0:5b88d5760320 284 *
kenjiArai 0:5b88d5760320 285 * @param id Unique id of the hostname translation operation (returned
kenjiArai 0:5b88d5760320 286 * by gethostbyname_async)
kenjiArai 0:5b88d5760320 287 * @return NSAPI_ERROR_OK on success, negative error code on failure.
kenjiArai 0:5b88d5760320 288 */
kenjiArai 0:5b88d5760320 289 virtual nsapi_error_t gethostbyname_async_cancel(int id);
kenjiArai 0:5b88d5760320 290
kenjiArai 0:5b88d5760320 291 /** Add a domain name server to list of servers to query
kenjiArai 0:5b88d5760320 292 *
kenjiArai 0:5b88d5760320 293 * @param address Address for the dns host.
kenjiArai 0:5b88d5760320 294 * @return NSAPI_ERROR_OK on success, negative error code on failure.
kenjiArai 0:5b88d5760320 295 */
kenjiArai 0:5b88d5760320 296 virtual nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name);
kenjiArai 0:5b88d5760320 297
kenjiArai 0:5b88d5760320 298 /** Register callback for status reporting.
kenjiArai 0:5b88d5760320 299 *
kenjiArai 0:5b88d5760320 300 * The specified status callback function will be called on status changes
kenjiArai 0:5b88d5760320 301 * on the network. The parameters on the callback are the event type and
kenjiArai 0:5b88d5760320 302 * event-type dependent reason parameter. Only one callback can be registered at a time.
kenjiArai 0:5b88d5760320 303 *
kenjiArai 0:5b88d5760320 304 * To unregister a callback call with status_cb parameter as a zero.
kenjiArai 0:5b88d5760320 305 *
kenjiArai 0:5b88d5760320 306 * *NOTE:* Any callbacks registered with this function will be overwritten if
kenjiArai 0:5b88d5760320 307 * add_event_listener() API is used.
kenjiArai 0:5b88d5760320 308 *
kenjiArai 0:5b88d5760320 309 * @param status_cb The callback for status changes.
kenjiArai 0:5b88d5760320 310 */
kenjiArai 0:5b88d5760320 311 virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
kenjiArai 0:5b88d5760320 312
kenjiArai 0:5b88d5760320 313 /** Add event listener for interface.
kenjiArai 0:5b88d5760320 314 *
kenjiArai 0:5b88d5760320 315 * This API allows multiple callback to be registered for a single interface.
kenjiArai 0:5b88d5760320 316 * When first called, internal list of event handlers are created and registered to
kenjiArai 0:5b88d5760320 317 * interface through attach() API.
kenjiArai 0:5b88d5760320 318 *
kenjiArai 0:5b88d5760320 319 * Application may only use attach() or add_event_listener() interface. Mixing usage
kenjiArai 0:5b88d5760320 320 * of both leads to undefined behavior.
kenjiArai 0:5b88d5760320 321 *
kenjiArai 0:5b88d5760320 322 * @param status_cb The callback for status changes.
kenjiArai 0:5b88d5760320 323 */
kenjiArai 0:5b88d5760320 324 void add_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
kenjiArai 0:5b88d5760320 325
kenjiArai 0:5b88d5760320 326 /** Remove event listener from interface.
kenjiArai 0:5b88d5760320 327 *
kenjiArai 0:5b88d5760320 328 * Remove previously added callback from the handler list.
kenjiArai 0:5b88d5760320 329 *
kenjiArai 0:5b88d5760320 330 * @param status_cb The callback to unregister.
kenjiArai 0:5b88d5760320 331 */
kenjiArai 0:5b88d5760320 332 void remove_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
kenjiArai 0:5b88d5760320 333
kenjiArai 0:5b88d5760320 334 /** Get the connection status.
kenjiArai 0:5b88d5760320 335 *
kenjiArai 0:5b88d5760320 336 * @return The connection status (@see nsapi_types.h).
kenjiArai 0:5b88d5760320 337 */
kenjiArai 0:5b88d5760320 338 virtual nsapi_connection_status_t get_connection_status() const;
kenjiArai 0:5b88d5760320 339
kenjiArai 0:5b88d5760320 340 /** Set asynchronous operation of connect() and disconnect() calls.
kenjiArai 0:5b88d5760320 341 *
kenjiArai 0:5b88d5760320 342 * By default, interfaces are in synchronous mode which means that
kenjiArai 0:5b88d5760320 343 * connect() or disconnect() blocks until it reach the target state or requested operation fails.
kenjiArai 0:5b88d5760320 344 *
kenjiArai 1:9db0e321a9f4 345 * @param blocking Use false to set NetworkInterface in asynchronous mode.
kenjiArai 0:5b88d5760320 346 * @return NSAPI_ERROR_OK on success
kenjiArai 0:5b88d5760320 347 * @return NSAPI_ERROR_UNSUPPORTED if driver does not support asynchronous mode.
kenjiArai 0:5b88d5760320 348 * @return negative error code on failure.
kenjiArai 0:5b88d5760320 349 */
kenjiArai 0:5b88d5760320 350 virtual nsapi_error_t set_blocking(bool blocking);
kenjiArai 0:5b88d5760320 351
kenjiArai 0:5b88d5760320 352 /** Return pointer to an EthInterface.
kenjiArai 0:5b88d5760320 353 * @return Pointer to requested interface type or NULL if this class doesn't implement the interface.
kenjiArai 0:5b88d5760320 354 */
kenjiArai 0:5b88d5760320 355 virtual EthInterface *ethInterface()
kenjiArai 0:5b88d5760320 356 {
kenjiArai 0:5b88d5760320 357 return 0;
kenjiArai 0:5b88d5760320 358 }
kenjiArai 0:5b88d5760320 359
kenjiArai 0:5b88d5760320 360 /** Return pointer to a WiFiInterface.
kenjiArai 0:5b88d5760320 361 * @return Pointer to requested interface type or NULL if this class doesn't implement the interface.
kenjiArai 0:5b88d5760320 362 */
kenjiArai 0:5b88d5760320 363 virtual WiFiInterface *wifiInterface()
kenjiArai 0:5b88d5760320 364 {
kenjiArai 0:5b88d5760320 365 return 0;
kenjiArai 0:5b88d5760320 366 }
kenjiArai 0:5b88d5760320 367
kenjiArai 0:5b88d5760320 368 /** Return pointer to a MeshInterface.
kenjiArai 0:5b88d5760320 369 * @return Pointer to requested interface type or NULL if this class doesn't implement the interface.
kenjiArai 0:5b88d5760320 370 */
kenjiArai 0:5b88d5760320 371 virtual MeshInterface *meshInterface()
kenjiArai 0:5b88d5760320 372 {
kenjiArai 0:5b88d5760320 373 return 0;
kenjiArai 0:5b88d5760320 374 }
kenjiArai 0:5b88d5760320 375
kenjiArai 1:9db0e321a9f4 376 /** Return pointer to an EMACInterface.
kenjiArai 0:5b88d5760320 377 * @return Pointer to requested interface type or NULL if this class doesn't implement the interface.
kenjiArai 0:5b88d5760320 378 */
kenjiArai 1:9db0e321a9f4 379 virtual EMACInterface *emacInterface()
kenjiArai 0:5b88d5760320 380 {
kenjiArai 0:5b88d5760320 381 return 0;
kenjiArai 0:5b88d5760320 382 }
kenjiArai 0:5b88d5760320 383
kenjiArai 1:9db0e321a9f4 384 /** Return pointer to a CellularInterface.
kenjiArai 0:5b88d5760320 385 * @return Pointer to requested interface type or NULL if this class doesn't implement the interface.
kenjiArai 0:5b88d5760320 386 */
kenjiArai 1:9db0e321a9f4 387 virtual CellularInterface *cellularInterface()
kenjiArai 0:5b88d5760320 388 {
kenjiArai 0:5b88d5760320 389 return 0;
kenjiArai 0:5b88d5760320 390 }
kenjiArai 0:5b88d5760320 391
kenjiArai 0:5b88d5760320 392 #if !defined(DOXYGEN_ONLY)
kenjiArai 0:5b88d5760320 393
kenjiArai 0:5b88d5760320 394 protected:
kenjiArai 0:5b88d5760320 395 friend class InternetSocket;
kenjiArai 0:5b88d5760320 396 friend class UDPSocket;
kenjiArai 0:5b88d5760320 397 friend class TCPSocket;
kenjiArai 0:5b88d5760320 398 friend class TCPServer;
kenjiArai 0:5b88d5760320 399 friend class SocketAddress;
kenjiArai 0:5b88d5760320 400 template <typename IF>
kenjiArai 0:5b88d5760320 401 friend NetworkStack *nsapi_create_stack(IF *iface);
kenjiArai 0:5b88d5760320 402
kenjiArai 0:5b88d5760320 403 /** Provide access to the NetworkStack object
kenjiArai 0:5b88d5760320 404 *
kenjiArai 0:5b88d5760320 405 * @return The underlying NetworkStack object
kenjiArai 0:5b88d5760320 406 */
kenjiArai 0:5b88d5760320 407 virtual NetworkStack *get_stack() = 0;
kenjiArai 0:5b88d5760320 408
kenjiArai 0:5b88d5760320 409 /** Get the target's default network instance.
kenjiArai 0:5b88d5760320 410 *
kenjiArai 0:5b88d5760320 411 * This method can be overridden by the target. Default implementations
kenjiArai 0:5b88d5760320 412 * are provided weakly by various subsystems as described in
kenjiArai 0:5b88d5760320 413 * NetworkInterface::get_default_instance(), so targets should not
kenjiArai 0:5b88d5760320 414 * need to override in simple cases.
kenjiArai 0:5b88d5760320 415 *
kenjiArai 0:5b88d5760320 416 * If a target has more elaborate interface selection, it can completely
kenjiArai 0:5b88d5760320 417 * override this behavior by implementing
kenjiArai 0:5b88d5760320 418 * NetworkInterface::get_target_default_instance() themselves, either
kenjiArai 0:5b88d5760320 419 * unconditionally, or for a specific network-default-interface-type setting
kenjiArai 0:5b88d5760320 420 *
kenjiArai 0:5b88d5760320 421 * For example, a device with both Ethernet and Wi-fi could be set up its
kenjiArai 0:5b88d5760320 422 * target so that:
kenjiArai 0:5b88d5760320 423 * * DEVICE_EMAC is set, and it provides EMAC::get_default_instance(),
kenjiArai 0:5b88d5760320 424 * which means EthernetInterface provides EthInterface::get_target_instance()
kenjiArai 0:5b88d5760320 425 * based on that EMAC.
kenjiArai 0:5b88d5760320 426 * * It provides WifiInterface::get_target_default_instance().
kenjiArai 0:5b88d5760320 427 * * The core will route NetworkInterface::get_default_instance() to
kenjiArai 0:5b88d5760320 428 * either of those if network-default-interface-type is set to
kenjiArai 0:5b88d5760320 429 * ETHERNET or WIFI.
kenjiArai 0:5b88d5760320 430 * * The board overrides NetworkInterface::get_target_default_instance()
kenjiArai 0:5b88d5760320 431 * if network-default-interface-type is set to AUTO. This returns
kenjiArai 0:5b88d5760320 432 * either EthInterface::get_default_instance() or WiFIInterface::get_default_instance()
kenjiArai 0:5b88d5760320 433 * depending on a cable detection.
kenjiArai 0:5b88d5760320 434 *
kenjiArai 0:5b88d5760320 435 *
kenjiArai 0:5b88d5760320 436 * performs the search described by get_default_instance.
kenjiArai 0:5b88d5760320 437 */
kenjiArai 0:5b88d5760320 438 static NetworkInterface *get_target_default_instance();
kenjiArai 0:5b88d5760320 439 #endif //!defined(DOXYGEN_ONLY)
kenjiArai 0:5b88d5760320 440
kenjiArai 0:5b88d5760320 441 public:
kenjiArai 0:5b88d5760320 442 /** Set default parameters on an interface.
kenjiArai 0:5b88d5760320 443 *
kenjiArai 0:5b88d5760320 444 * A network interface instantiated directly or using calls such as
kenjiArai 0:5b88d5760320 445 * WiFiInterface::get_default_instance() is initially unconfigured.
kenjiArai 0:5b88d5760320 446 * This call can be used to set the default parameters that would
kenjiArai 0:5b88d5760320 447 * have been set if the interface had been requested using
kenjiArai 0:5b88d5760320 448 * NetworkInterface::get_default_instance() (see nsapi JSON
kenjiArai 0:5b88d5760320 449 * configuration).
kenjiArai 0:5b88d5760320 450 */
kenjiArai 0:5b88d5760320 451 virtual void set_default_parameters();
kenjiArai 0:5b88d5760320 452 };
kenjiArai 0:5b88d5760320 453
kenjiArai 0:5b88d5760320 454 #endif
kenjiArai 0:5b88d5760320 455
kenjiArai 0:5b88d5760320 456 /** @}*/