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