Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

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