mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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